libuv4_req

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);

1.4. 参考资料

  1. request
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值