5#ifndef WPINET_UV_HANDLE_H_
6#define WPINET_UV_HANDLE_H_
30class Handle :
public std::enable_shared_from_this<Handle> {
63 std::shared_ptr<Loop>
GetLoop() const noexcept {
73 return *
static_cast<Loop*
>(m_uv_handle->loop->data);
130 m_loopClosing = loopClosing;
194 std::function<
void(
Buffer&)> dealloc) {
195 m_allocBuf = std::move(alloc);
196 m_freeBuf = std::move(dealloc);
211 template <
typename T =
void>
213 return std::static_pointer_cast<T>(m_data);
240 m_uv_handle->data =
this;
243 void Keep() noexcept { m_self = shared_from_this(); }
250 template <
typename F,
typename... Args>
252 auto err = std::forward<F>(f)(std::forward<Args>(args)...);
260 std::shared_ptr<Handle> m_self;
262 bool m_closed =
false;
263 bool m_loopClosing =
false;
266 std::shared_ptr<void> m_data;
272template <
typename T,
typename U>
276 return std::static_pointer_cast<T>(Handle::shared_from_this());
280 return std::static_pointer_cast<const T>(Handle::shared_from_this());
SignalBase is an implementation of the observer pattern, through the use of an emitting object and sl...
Definition: Signal.h:495
Data buffer.
Definition: Buffer.h:23
static Buffer Allocate(size_t size)
Definition: Buffer.h:52
Error code.
Definition: Error.h:15
Handle.
Definition: Handle.h:30
void SetBufferAllocator(std::function< Buffer(size_t)> alloc, std::function< void(Buffer &)> dealloc)
Set the functions used for allocating and releasing buffers.
Definition: Handle.h:193
bool IsLoopClosing() const noexcept
Get the loop closing status.
Definition: Handle.h:141
void ForceClosed() noexcept
Definition: Handle.h:245
virtual ~Handle() noexcept
void FreeBuf(Buffer &buf) const noexcept
Free a buffer.
Definition: Handle.h:205
std::string_view GetTypeName() const noexcept
Get the name of the type of the handle.
Definition: Handle.h:54
void SetData(std::shared_ptr< void > data)
Sets user-defined data.
Definition: Handle.h:220
void ReportError(int err) const
Report an error.
Definition: Handle.h:236
Loop & GetLoopRef() const noexcept
Get the loop where this handle runs.
Definition: Handle.h:72
Handle & operator=(Handle &&)=delete
Handle(const Handle &)=delete
Handle(uv_handle_t *uv_handle)
Definition: Handle.h:239
uv_handle_t * GetRawHandle() const noexcept
Get the underlying handle data structure.
Definition: Handle.h:176
std::shared_ptr< T > GetData() const
Gets user-defined data.
Definition: Handle.h:212
void Close() noexcept
Request handle to be closed.
bool IsActive() const noexcept
Check if the handle is active.
Definition: Handle.h:95
void Keep() noexcept
Definition: Handle.h:243
static void AllocBuf(uv_handle_t *handle, size_t size, uv_buf_t *buf)
void Unreference() noexcept
Unreference the given handle.
Definition: Handle.h:157
sig::Signal closed
Closed signal.
Definition: Handle.h:230
Type GetType() const noexcept
Get the type of the handle.
Definition: Handle.h:49
void Release() noexcept
Definition: Handle.h:244
Handle & operator=(const Handle &)=delete
bool Invoke(F &&f, Args &&... args) const
Definition: Handle.h:251
void Reference() noexcept
Reference the given handle.
Definition: Handle.h:149
bool IsClosing() const noexcept
Check if a handle is closing or closed.
Definition: Handle.h:105
bool HasReference() const noexcept
Check if the given handle is referenced.
Definition: Handle.h:163
std::shared_ptr< Loop > GetLoop() const noexcept
Get the loop where this handle runs.
Definition: Handle.h:63
sig::Signal< Error > error
Error signal.
Definition: Handle.h:225
size_t RawSize() const noexcept
Return the size of the underlying handle type.
Definition: Handle.h:169
void SetLoopClosing(bool loopClosing) noexcept
Set if the loop is closing.
Definition: Handle.h:129
static void DefaultFreeBuf(Buffer &buf)
Handle.
Definition: Handle.h:273
HandleImpl()
Definition: Handle.h:293
U * GetRaw() const noexcept
Get the underlying handle data structure.
Definition: Handle.h:288
std::shared_ptr< const T > shared_from_this() const
Definition: Handle.h:279
std::shared_ptr< T > shared_from_this()
Definition: Handle.h:275
Event loop.
Definition: Loop.h:37
basic_string_view< char > string_view
Definition: core.h:520
EIGEN_CONSTEXPR Index size(const T &x)
Definition: Meta.h:479
Definition: BFloat16.h:88
static constexpr const unit_t< compound_unit< charge::coulomb, inverse< substance::mol > > > F(N_A *e)
Faraday constant.
Definition: format.h:1552
It should be possible to cast uv_buf_t[] to WSABUF[] see http://msdn.microsoft.com/en-us/library/ms74...
Definition: unix.h:113
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:186
UV_EXTERN void uv_ref(uv_handle_t *)
UV_EXTERN size_t uv_handle_size(uv_handle_type type)
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 *)