目录
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