libcurl实现解析(2) - libcurl对poll的使用

目录

1.前言

2.curl_poll数据结构

3.curl_poll函数分析

4.curl_wait_ms函数分析


1.前言

libcurl中同时封装了select以及poll这两种I/O机制。代码中使用宏HAVE_POLL_FINE对这两者进行分离。如果定义了这个宏,则使用poll,否则使用select。

这两者的使用代码都位于函数curl_poll()中,而此函数定义在文件lib/select.c中。为了方便分析,阅读,会将select与poll相关的代码分离开来,各自独立分析。

本篇文章主要分析curl_poll()中对poll的封装使用。

2.curl_poll数据结构

先看下使用到的一些数据结构的定义:

typedef int curl_socket_t ;
#define CURL_SOCKET_BAD -1
struct pollfd
{
        curl_socket_t fd;
        short   events;
        short   revents;
};
/*查阅了linux的man手册,对这三个成员的说明如下:
The field fd contains a file descriptor for an open file. If this field is negative, 
then the corresponding events field is ignored and the revents field returns zero. (This 
provides an easy way of ignoring a file descriptor for a single poll() call: 
simply negate the fd field.)

The field events is an input parameter, a bit mask specifying the events the application 
is interested in for the file descriptorfd. 
If this field is specified as zero, then all events are ignored for fd and revents returns zero.

The field revents is an output parameter, filled by the kernel with the events that 
actually occurred. The bits returned inrevents can include any of those specified in 
events, or one of the values POLLERR, POLLHUP, or POLLNVAL. (These 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

水草

您的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值