UV module
uv module contains C++ wrappers for libuv.uv
The uv module contains C++ wrappers for libuv.
Classes
| Name | Description |
|---|---|
Handle | Wrapper class for managing uv_handle_t variants. |
ScopedLoop | RAII wrapper for a libuv event loop. Automatically closes and deletes the loop on destruction. |
HandleStorage | Extra storage placed around a raw libuv handle for close-time cleanup hooks. |
Context | Shared libuv handle context. |
BasicEvent | Default request callback event carrying a libuv status code. |
Request | Wrapper class for managing uv_req_t variants. |
ConnectReq | Asynchronous connection request for TCP sockets and named pipes. |
GetAddrInfoEvent | Callback event delivered when a [GetAddrInfoReq](icy-uv-GetAddrInfoReq.html#getaddrinforeq) resolves. |
GetAddrInfoReq | DNS resolver request to get the IP address of a hostname. |
Typedefs
| Return | Name | Description |
|---|---|---|
uv_loop_t | Loop | Alias for a libuv event loop instance. |
Loop
uv_loop_t Loop()Alias for a libuv event loop instance.
Functions
| Return | Name | Description |
|---|---|---|
Loop * | defaultLoop inline | Returns the process-wide default libuv event loop. |
void | runLoop inline | Runs the given event loop using the specified run mode. Blocks until the loop exits (when using UV_RUN_DEFAULT). |
void | stopLoop inline | Stops the given event loop, causing uv_run to return after the current iteration. |
Loop * | createLoop inline | Allocates and initializes a new libuv event loop. The caller is responsible for closing and deleting the returned loop. |
bool | closeLoop inline | Closes the given event loop, releasing internal resources. All handles must be closed before calling this. |
HandleStorage< T > * | handleStorage inline | Returns the extended storage wrapper that owns handle. |
void | setHandleCloseCleanup inline | Registers a cleanup callback that runs when handle finally closes. |
void | clearHandleCloseCleanup inline | Clears any pending close-time cleanup callback registered on handle. |
auto | withHandleContext inline | Wraps callback so it only runs while the owning handle is still alive. Captures the intrusive [Context](icy-uv-Context.html#context-2) token, rehydrates the typed owner on entry, and suppresses invocation if the handle has already been deleted. |
T & | createRequest inline | Allocate a heap-owned [Request](icy-uv-Request.html#request-2) of type T and attach callback to it. |
T & | createRetainedRequest inline | Allocate a heap-owned [Request](icy-uv-Request.html#request-2) of type T whose callback retains additional state until completion. |
defaultLoop
inline
inline Loop * defaultLoop()Returns the process-wide default libuv event loop.
Returns
Pointer to the default uv_loop_t.
runLoop
inline
inline void runLoop(Loop * loop, uv_run_mode mode) = defaultRuns the given event loop using the specified run mode. Blocks until the loop exits (when using UV_RUN_DEFAULT).
Parameters
loopEvent loop to run. Defaults to the default loop.modelibuv run mode:UV_RUN_DEFAULT,UV_RUN_ONCE, orUV_RUN_NOWAIT.
stopLoop
inline
inline void stopLoop(Loop * loop) = defaultStops the given event loop, causing uv_run to return after the current iteration.
Parameters
loopEvent loop to stop. Defaults to the default loop.
createLoop
inline
inline Loop * createLoop()Allocates and initializes a new libuv event loop. The caller is responsible for closing and deleting the returned loop.
Returns
Pointer to a newly initialized uv_loop_t.
closeLoop
inline
inline bool closeLoop(Loop * loop)Closes the given event loop, releasing internal resources. All handles must be closed before calling this.
Parameters
loopEvent loop to close.
Returns
True on success, false if the loop still has active handles.
handleStorage
inline
template<typename T> inline HandleStorage< T > * handleStorage(T * handle)Returns the extended storage wrapper that owns handle.
Parameters
handleRawlibuvhandle pointer previously allocated by[Context](icy-uv-Context.html#context-2)<T>.
setHandleCloseCleanup
inline
template<typename T> inline void setHandleCloseCleanup(T * handle, void * data, void(*)(void *) cleanup)Registers a cleanup callback that runs when handle finally closes.
Parameters
handleRawlibuvhandle pointer.dataUser data passed back tocleanup.cleanupFunction invoked exactly once when the handle storage is released.
clearHandleCloseCleanup
inline
template<typename T> inline void clearHandleCloseCleanup(T * handle)Clears any pending close-time cleanup callback registered on handle.
Parameters
handleRawlibuvhandle pointer.
withHandleContext
inline
template<typename Owner, typename Callback> inline auto withHandleContext(Owner & owner, Callback && callback)Wraps callback so it only runs while the owning handle is still alive. Captures the intrusive [Context](icy-uv-Context.html#context-2) token, rehydrates the typed owner on entry, and suppresses invocation if the handle has already been deleted.
Parameters
ownerOwning handle instance.callbackCallable that receivesOwner&followed by the libuv callback args.
createRequest
inline
template<typename T> inline T & createRequest(std::function< void(const typename T::Event &)> callback)Allocate a heap-owned [Request](icy-uv-Request.html#request-2) of type T and attach callback to it.
The returned reference is valid until the request's defaultCallback fires and deletes the object.
Parameters
TA specialization of[Request](icy-uv-Request.html#request-2).
Parameters
callbackCompletion handler; receives aT::Eventon completion.
Returns
Reference to the newly allocated request.
createRetainedRequest
inline
template<typename T, typename Retained, typename Callback> inline T & createRetainedRequest(Retained && retained, Callback && callback)Allocate a heap-owned [Request](icy-uv-Request.html#request-2) of type T whose callback retains additional state until completion.
This is the standard way to bind request completion to handle lifetime or other retained context without hand-rolling per-call capture logic.
Parameters
TA specialization of[Request](icy-uv-Request.html#request-2).RetainedRetained object type copied or moved into the callback.CallbackCallable invoked ascallback(retained, event).
Parameters
retainedExtra state to keep alive until the request completes.callbackCompletion handler receiving the retained state and event.
Returns
Reference to the newly allocated request.
