5#ifndef WPINET_UV_HANDLE_H_
6#define WPINET_UV_HANDLE_H_
34class Handle :
public std::enable_shared_from_this<Handle> {
67 std::shared_ptr<Loop>
GetLoop() const noexcept {
77 return *
static_cast<Loop*
>(m_uv_handle->loop->data);
134 m_loopClosing = loopClosing;
198 std::function<
void(
Buffer&)> dealloc) {
199 m_allocBuf = std::move(alloc);
200 m_freeBuf = std::move(dealloc);
215 template <
typename T =
void>
217 return std::static_pointer_cast<T>(m_data);
224 void SetData(std::shared_ptr<void> data) { m_data = std::move(data); }
256 m_uv_handle->data =
this;
259 void Keep() noexcept { m_self = shared_from_this(); }
266 template <
typename F,
typename... Args>
268 auto err = std::forward<F>(f)(std::forward<Args>(args)...);
276 std::shared_ptr<Handle> m_self;
278 bool m_closed =
false;
279 bool m_loopClosing =
false;
282 std::shared_ptr<void> m_data;
283 Logger* m_logger =
nullptr;
289template <
typename T,
typename U>
293 return std::static_pointer_cast<T>(Handle::shared_from_this());
297 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:65
Error code.
Definition: Error.h:15
Handle.
Definition: Handle.h:34
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:197
bool IsLoopClosing() const noexcept
Get the loop closing status.
Definition: Handle.h:145
void ForceClosed() noexcept
Definition: Handle.h:261
virtual ~Handle() noexcept
void FreeBuf(Buffer &buf) const noexcept
Free a buffer.
Definition: Handle.h:209
std::string_view GetTypeName() const noexcept
Get the name of the type of the handle.
Definition: Handle.h:58
void SetData(std::shared_ptr< void > data)
Sets user-defined data.
Definition: Handle.h:224
void ReportError(int err) const
Report an error.
Definition: Handle.h:252
Loop & GetLoopRef() const noexcept
Get the loop where this handle runs.
Definition: Handle.h:76
Handle & operator=(Handle &&)=delete
Handle(const Handle &)=delete
Handle(uv_handle_t *uv_handle)
Definition: Handle.h:255
uv_handle_t * GetRawHandle() const noexcept
Get the underlying handle data structure.
Definition: Handle.h:180
std::shared_ptr< T > GetData() const
Gets user-defined data.
Definition: Handle.h:216
void Close() noexcept
Request handle to be closed.
bool IsActive() const noexcept
Check if the handle is active.
Definition: Handle.h:99
void Keep() noexcept
Definition: Handle.h:259
static void AllocBuf(uv_handle_t *handle, size_t size, uv_buf_t *buf)
Logger * GetLogger() const
Gets logger.
Definition: Handle.h:236
void Unreference() noexcept
Unreference the given handle.
Definition: Handle.h:161
sig::Signal closed
Closed signal.
Definition: Handle.h:246
Type GetType() const noexcept
Get the type of the handle.
Definition: Handle.h:53
void Release() noexcept
Definition: Handle.h:260
void SetLogger(Logger *logger)
Sets logger.
Definition: Handle.h:230
Handle & operator=(const Handle &)=delete
bool Invoke(F &&f, Args &&... args) const
Definition: Handle.h:267
void Reference() noexcept
Reference the given handle.
Definition: Handle.h:153
bool IsClosing() const noexcept
Check if a handle is closing or closed.
Definition: Handle.h:109
bool HasReference() const noexcept
Check if the given handle is referenced.
Definition: Handle.h:167
std::shared_ptr< Loop > GetLoop() const noexcept
Get the loop where this handle runs.
Definition: Handle.h:67
sig::Signal< Error > error
Error signal.
Definition: Handle.h:241
size_t RawSize() const noexcept
Return the size of the underlying handle type.
Definition: Handle.h:173
void SetLoopClosing(bool loopClosing) noexcept
Set if the loop is closing.
Definition: Handle.h:133
static void DefaultFreeBuf(Buffer &buf)
Handle.
Definition: Handle.h:290
HandleImpl()
Definition: Handle.h:310
U * GetRaw() const noexcept
Get the underlying handle data structure.
Definition: Handle.h:305
std::shared_ptr< const T > shared_from_this() const
Definition: Handle.h:296
std::shared_ptr< T > shared_from_this()
Definition: Handle.h:292
Event loop.
Definition: Loop.h:37
basic_string_view< char > string_view
Definition: core.h:501
static constexpr const unit_t< compound_unit< charge::coulomb, inverse< substance::mol > > > F(N_A *e)
Faraday constant.
Definition: WebSocket.h:27
Definition: ntcore_cpp.h:26
It should be possible to cast uv_buf_t[] to WSABUF[] see http://msdn.microsoft.com/en-us/library/ms74...
Definition: unix.h:112
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)
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 *)