1. request handle
1.1. request对象
#define UV_REQ_FIELDS \
/* public */ \
void* data; \
/* read-only */ \
uv_req_type type; \
/* private */ \
void* reserved[6]; \
UV_REQ_PRIVATE_FIELDS \
/* Abstract base class of all requests. */
struct uv_req_s {
UV_REQ_FIELDS
};
/* Request types. */
typedef struct uv_req_s uv_req_t; //详见下边内容
typedef struct uv_getaddrinfo_s uv_getaddrinfo_t; //详见下边内容
typedef struct uv_getnameinfo_s uv_getnameinfo_t; //详见下边内容
typedef struct uv_shutdown_s uv_shutdown_t; //详见 libuv_net
typedef struct uv_write_s uv_write_t; //详见 libuv5_net
typedef struct uv_connect_s uv_connect_t; //详见 libuv5_net
typedef struct uv_udp_send_s uv_udp_send_t; //详见 libuv5_net
typedef struct uv_fs_s uv_fs_t; //详见 libuv6_file
typedef struct uv_work_s uv_work_t; //详见 libuv7_thread
typedef struct uv_random_s uv_random_t; //详见 libuv10_常用结构
1.2. getaddrinfo/getnameinfo地址转换
getaddrinfo 将主机和服务转换到socket地址
详见linux的 getaddrinfo 接口
struct uv_getaddrinfo_s {
UV_REQ_FIELDS
/* read-only */
uv_loop_t* loop;
/* struct addrinfo* addrinfo is marked as private, but it really isn't. */
UV_GETADDRINFO_PRIVATE_FIELDS
};
typedef void (*uv_getaddrinfo_cb)(uv_getaddrinfo_t* req, int status, struct addrinfo* res);
//node:host 或者IP地址, service:十进制端口号 或者常用服务名称如"ftp"、"http"等,回调可以为空
int uv_getaddrinfo(uv_loop_t* loop, uv_getaddrinfo_t* req, uv_getaddrinfo_cb getaddrinfo_cb,
const char* node, const char* service, const struct addrinfo* hints);
void uv_freeaddrinfo(struct addrinfo* ai);//回调中,必须释放 addrinfo*
getnameinfo 功能与 getaddrinfo 相反,它将socket地址转换到主机和服务
struct uv_getnameinfo_s {
UV_REQ_FIELDS
/* read-only */
uv_loop_t* loop;
/* host and service are marked as private, but they really aren't. */
UV_GETNAMEINFO_PRIVATE_FIELDS
};
typedef void (*uv_getnameinfo_cb)(uv_getnameinfo_t* req, int status, const char* hostname, const char* service);
int uv_getnameinfo(uv_loop_t* loop, uv_getnameinfo_t* req, uv_getnameinfo_cb getnameinfo_cb,
const struct sockaddr* addr, int flags);