1. handle
loop的调度一般通过二种模式调度,一种是Handle,一种是Request。Handle一般关联一个长期任务,request关联一个一次性任务。比如一个socket的监听任务,就是uv_udp_t(handle),而一次数据的发送就是一个请求任务,关联请求句柄uv_udp_send_t(request)。
1.1. handle对象
#define UV_HANDLE_FIELDS \
/* public */ \
void* data; \
/* read-only */ \
uv_loop_t* loop; \
uv_handle_type type; \
/* private */ \
uv_close_cb close_cb; \
void* handle_queue[2]; \
union { \
int fd; \
void* reserved[4]; \
} u; \
UV_HANDLE_PRIVATE_FIELDS \
/* The abstract base class of all handles. */
struct uv_handle_s {
UV_HANDLE_FIELDS
};
/* Handle types. */
typedef struct uv_loop_s uv_loop_t;
typedef struct uv_stream_s uv_stream_t; //详见libuv5_net
typedef struct uv_tcp_s uv_tcp_t; //详见libuv5_net
typedef struct uv_udp_s uv_udp_t; //详见libuv5_net
typedef struct uv_pipe_s uv_pipe_t

本文详细介绍了Libuv中Handle的概念及各类Handle的具体实现,包括通用API、异步通信Handle、定时器、辅助消息Handle等,并提供了相关参考资料。
最低0.47元/天 解锁文章
1297

被折叠的 条评论
为什么被折叠?



