Skip to content

Libuv:BaseHandle

Types

typedef enum {
  UV_UNKNOWN_HANDLE = 0,
  UV_ASYNC,
  UV_CHECK,
  UV_FS_EVENT,
  UV_FS_POLL,
  UV_HANDLE,
  UV_IDLE,
  UV_NAMED_PIPE,
  UV_POLL,
  UV_PREPARE,
  UV_PROCESS,
  UV_STREAM,
  UV_TCP,
  UV_TIMER,
  UV_TTY,
  UV_UDP,
  UV_SIGNAL,
  UV_FILE,
  UV_HANDLE_TYPE_MAX
} uv_handle_type;

Handle Public members

uv_loop_t* uv_handle_t.loop
[Readonly] Pointer to the uv_loop_t where the handle is running on.
uv_loop_t* uv_handle_t.type
[Readonly] Pointer to the uv_handle_type.
void* uv_handle_t.data
Space for user-defined arbitrary data. libuv does not use this field.

Closing libuv handles

libuv is not done with a handle until it's close callback is called. That is the exact moment when you can free the handle. I see you call uv_loop_close, but you don't check for the return value. If there are still pending handles, it will return UV_EBUSY, so you should check for that. If you want to close a loop and close all handles, you need to do the following:

  1. Use uv_stop to stop the loop
  2. Use uv_walk and call uv_close on all handles which are not closing
  3. Run the loop again with uv_run so all close callbacks are called and you can free the memory in the callbacks
  4. Call uv_loop_close, it should return 0 now

See also

Favorite site