UV module

UV module

The uv module contains C++ wrappers for libuv.

The uv module contains C++ wrappers for libuv.

Classes

NameDescription
HandleWrapper class for managing uv_handle_t variants.
ScopedLoopRAII wrapper for a libuv event loop. Automatically closes and deletes the loop on destruction.
HandleStorageExtra storage placed around a raw libuv handle for close-time cleanup hooks.
ContextShared libuv handle context.
BasicEventDefault request callback event carrying a libuv status code.
RequestWrapper class for managing uv_req_t variants.
ConnectReqAsynchronous connection request for TCP sockets and named pipes.
GetAddrInfoEventCallback event delivered when a GetAddrInfoReq resolves.
GetAddrInfoReqDNS resolver request to get the IP address of a hostname.

Typedefs

ReturnNameDescription
uv_loop_tLoopAlias for a libuv event loop instance.

Loop

using Loop = uv_loop_t

Defined in src/base/include/icy/loop.h:29

Alias for a libuv event loop instance.

Functions

ReturnNameDescription
Loop *defaultLoop inlineReturns the process-wide default libuv event loop.
voidrunLoop inlineRuns the given event loop using the specified run mode. Blocks until the loop exits (when using UV_RUN_DEFAULT).
voidstopLoop inlineStops the given event loop, causing uv_run to return after the current iteration.
Loop *createLoop inlineAllocates and initializes a new libuv event loop. The caller is responsible for closing and deleting the returned loop.
boolcloseLoop inlineCloses the given event loop, releasing internal resources. All handles must be closed before calling this.
HandleStorage< T > *handleStorage inlineReturns the extended storage wrapper that owns handle.
voidsetHandleCloseCleanup inlineRegisters a cleanup callback that runs when handle finally closes.
voidclearHandleCloseCleanup inlineClears any pending close-time cleanup callback registered on handle.
autowithHandleContext inlineWraps callback so it only runs while the owning handle is still alive. Captures the intrusive Context token, rehydrates the typed owner on entry, and suppresses invocation if the handle has already been deleted.
T &createRequest inlineAllocate a heap-owned Request of type T and attach callback to it.
T &createRetainedRequest inlineAllocate a heap-owned Request of type T whose callback retains additional state until completion.

defaultLoop

inline

inline Loop * defaultLoop()

Defined in src/base/include/icy/loop.h:34

Returns the process-wide default libuv event loop.

Returns

Pointer to the default uv_loop_t.


runLoop

inline

inline void runLoop(Loop * loop = defaultLoop(), uv_run_mode mode = UV_RUN_DEFAULT) = default

Defined in src/base/include/icy/loop.h:43

Runs the given event loop using the specified run mode. Blocks until the loop exits (when using UV_RUN_DEFAULT).

Parameters

ParameterTypeDescription
loopLoop *Event loop to run. Defaults to the default loop.
modeuv_run_modelibuv run mode: UV_RUN_DEFAULT, UV_RUN_ONCE, or UV_RUN_NOWAIT.

stopLoop

inline

inline void stopLoop(Loop * loop = defaultLoop()) = default

Defined in src/base/include/icy/loop.h:50

Stops the given event loop, causing uv_run to return after the current iteration.

Parameters

ParameterTypeDescription
loopLoop *Event loop to stop. Defaults to the default loop.

createLoop

inline

inline Loop * createLoop()

Defined in src/base/include/icy/loop.h:58

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)

Defined in src/base/include/icy/loop.h:69

Closes the given event loop, releasing internal resources. All handles must be closed before calling this.

Returns

True on success, false if the loop still has active handles.

Parameters

ParameterTypeDescription
loopLoop *Event loop to close.

handleStorage

inline

template<typename T> inline HandleStorage< T > * handleStorage(T * handle)

Defined in src/base/include/icy/handle.h:53

Returns the extended storage wrapper that owns handle.

Parameters

ParameterTypeDescription
handleT *Raw libuv handle pointer previously allocated by Context<T>.

setHandleCloseCleanup

inline

template<typename T> inline void setHandleCloseCleanup(T * handle, void * data, void(*)(void *) cleanup)

Defined in src/base/include/icy/handle.h:64

Registers a cleanup callback that runs when handle finally closes.

Parameters

ParameterTypeDescription
handleT *Raw libuv handle pointer.
datavoid *User data passed back to cleanup.
cleanupvoid(*)(void *)Function invoked exactly once when the handle storage is released.

clearHandleCloseCleanup

inline

template<typename T> inline void clearHandleCloseCleanup(T * handle)

Defined in src/base/include/icy/handle.h:75

Clears any pending close-time cleanup callback registered on handle.

Parameters

ParameterTypeDescription
handleT *Raw libuv handle pointer.

withHandleContext

inline

template<typename Owner, typename Callback> inline auto withHandleContext(Owner & owner, Callback && callback)

Defined in src/base/include/icy/handle.h:469

Wraps callback so it only runs while the owning handle is still alive. Captures the intrusive Context token, rehydrates the typed owner on entry, and suppresses invocation if the handle has already been deleted.

Parameters

ParameterTypeDescription
ownerOwner &Owning handle instance.
callbackCallback &&Callable that receives Owner& followed by the libuv callback args.

createRequest

inline

template<typename T> inline T & createRequest(std::function< void(const typename T::Event &)> callback)

Defined in src/base/include/icy/request.h:114

Allocate a heap-owned Request of type T and attach callback to it.

The returned reference is valid until the request's defaultCallback fires and deletes the object.

Returns

Reference to the newly allocated request.

Parameters

ParameterTypeDescription
callbackstd::function< void(const typename T::Event &)>Completion handler; receives a T::Event on completion.

createRetainedRequest

inline

template<typename T, typename Retained, typename Callback> inline T & createRetainedRequest(Retained && retained, Callback && callback)

Defined in src/base/include/icy/request.h:135

Allocate a heap-owned Request 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.

Returns

Reference to the newly allocated request.

Parameters

ParameterTypeDescription
retainedRetained &&Extra state to keep alive until the request completes.
callbackCallback &&Completion handler receiving the retained state and event.

Edit this page