mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-03 03:01:44 +00:00
[wpinet] uv::Request: Return shared_ptr from Release() (#5656)
Use this in Stream to allow the finish() callback to reuse the request.
This commit is contained in:
@@ -97,8 +97,8 @@ void Stream::Write(std::span<const Buffer> bufs,
|
||||
if (status < 0) {
|
||||
h.ReportError(status);
|
||||
}
|
||||
auto ptr = h.Release(); // one-shot, but finish() may Keep()
|
||||
h.finish(Error(status));
|
||||
h.Release(); // this is always a one-shot
|
||||
})) {
|
||||
req->Keep();
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "wpinet/uv/Error.h"
|
||||
|
||||
@@ -92,8 +93,12 @@ class Request : public std::enable_shared_from_this<Request> {
|
||||
*
|
||||
* Derived classes can override this method for different memory management
|
||||
* approaches (e.g. pooled storage of requests).
|
||||
*
|
||||
* @return Previous shared pointer
|
||||
*/
|
||||
virtual void Release() noexcept { m_self.reset(); }
|
||||
virtual std::shared_ptr<Request> Release() noexcept {
|
||||
return std::move(m_self);
|
||||
}
|
||||
|
||||
/**
|
||||
* Error callback. By default, this is set up to report errors to the handle
|
||||
|
||||
Reference in New Issue
Block a user