32class Handle :
public std::enable_shared_from_this<Handle> {
65 std::shared_ptr<Loop>
GetLoop() const noexcept {
75 return *
static_cast<Loop*
>(m_uv_handle->loop->data);
132 m_loopClosing = loopClosing;
196 std::function<
void(
Buffer&)> dealloc) {
197 m_allocBuf = std::move(alloc);
198 m_freeBuf = std::move(dealloc);
213 template <
typename T =
void>
215 return std::static_pointer_cast<T>(m_data);
222 void SetData(std::shared_ptr<void> data) { m_data = std::move(data); }
254 m_uv_handle->data =
this;
257 void Keep() noexcept { m_self = shared_from_this(); }
264 template <
typename F,
typename... Args>
265 bool Invoke(F&& f, Args&&... args)
const {
266 auto err = std::forward<F>(f)(std::forward<Args>(args)...);
274 std::shared_ptr<Handle> m_self;
276 bool m_closed =
false;
277 bool m_loopClosing =
false;
280 std::shared_ptr<void> m_data;
287template <
typename T,
typename U>
291 return std::static_pointer_cast<T>(Handle::shared_from_this());
295 return std::static_pointer_cast<const T>(Handle::shared_from_this());
Data buffer.
Definition Buffer.hpp:22
static Buffer Allocate(size_t size)
Definition Buffer.hpp:64
std::shared_ptr< Loop > GetLoop() const noexcept
Get the loop where this handle runs.
Definition Handle.hpp:65
virtual ~Handle() noexcept
Loop & GetLoopRef() const noexcept
Get the loop where this handle runs.
Definition Handle.hpp:74
void SetBufferAllocator(std::function< Buffer(size_t)> alloc, std::function< void(Buffer &)> dealloc)
Set the functions used for allocating and releasing buffers.
Definition Handle.hpp:195
wpi::util::sig::Signal closed
Closed signal.
Definition Handle.hpp:244
void ForceClosed() noexcept
Definition Handle.hpp:259
bool Invoke(F &&f, Args &&... args) const
Definition Handle.hpp:265
void Unreference() noexcept
Unreference the given handle.
Definition Handle.hpp:159
Handle & operator=(Handle &&)=delete
void FreeBuf(Buffer &buf) const noexcept
Free a buffer.
Definition Handle.hpp:207
Handle & operator=(const Handle &)=delete
void Release() noexcept
Definition Handle.hpp:258
bool HasReference() const noexcept
Check if the given handle is referenced.
Definition Handle.hpp:165
static void AllocBuf(uv_handle_t *handle, size_t size, uv_buf_t *buf)
Handle(uv_handle_t *uv_handle)
Definition Handle.hpp:253
void Reference() noexcept
Reference the given handle.
Definition Handle.hpp:151
wpi::util::Logger * GetLogger() const
Gets logger.
Definition Handle.hpp:234
uv_handle_type Type
Definition Handle.hpp:34
void SetLogger(wpi::util::Logger *logger)
Sets logger.
Definition Handle.hpp:228
std::string_view GetTypeName() const noexcept
Get the name of the type of the handle.
Definition Handle.hpp:56
void SetData(std::shared_ptr< void > data)
Sets user-defined data.
Definition Handle.hpp:222
void Close() noexcept
Request handle to be closed.
Type GetType() const noexcept
Get the type of the handle.
Definition Handle.hpp:51
uv_handle_t * GetRawHandle() const noexcept
Get the underlying handle data structure.
Definition Handle.hpp:178
void Keep() noexcept
Definition Handle.hpp:257
size_t RawSize() const noexcept
Return the size of the underlying handle type.
Definition Handle.hpp:171
std::shared_ptr< T > GetData() const
Gets user-defined data.
Definition Handle.hpp:214
bool IsLoopClosing() const noexcept
Get the loop closing status.
Definition Handle.hpp:143
wpi::util::sig::Signal< Error > error
Error signal.
Definition Handle.hpp:239
void ReportError(int err) const
Report an error.
Definition Handle.hpp:250
bool IsActive() const noexcept
Check if the handle is active.
Definition Handle.hpp:97
void SetLoopClosing(bool loopClosing) noexcept
Set if the loop is closing.
Definition Handle.hpp:131
Handle(const Handle &)=delete
static void DefaultFreeBuf(Buffer &buf)
bool IsClosing() const noexcept
Check if a handle is closing or closed.
Definition Handle.hpp:107
std::shared_ptr< const T > shared_from_this() const
Definition Handle.hpp:294
std::shared_ptr< T > shared_from_this()
Definition Handle.hpp:290
U * GetRaw() const noexcept
Get the underlying handle data structure.
Definition Handle.hpp:303
HandleImpl()
Definition Handle.hpp:308
Event loop.
Definition Loop.hpp:35
Error
Definition def.inc:106
Definition StringMap.hpp:773
Definition Errors.hpp:112
Definition Prepare.hpp:14
SignalBase< detail::NullMutex, T... > Signal
Specialization of SignalBase to be used in single threaded contexts.
Definition Signal.h:809
Definition raw_os_ostream.hpp:19
UV_EXTERN int uv_is_active(const uv_handle_t *handle)
UV_EXTERN const char * uv_handle_type_name(uv_handle_type type)
uv_handle_type
Definition uv.h:195
UV_EXTERN void uv_ref(uv_handle_t *)
UV_EXTERN size_t uv_handle_size(uv_handle_type type)
struct uv_handle_s uv_handle_t
Definition uv.h:216
UV_EXTERN void uv_unref(uv_handle_t *)
UV_EXTERN int uv_is_closing(const uv_handle_t *handle)
UV_EXTERN int uv_has_ref(const uv_handle_t *)