码迷,mamicode.com
首页 > 系统相关 > 详细

Linux poll机制

时间:2017-10-02 23:05:48      阅读:304      评论:0      收藏:0      [点我收藏+]

标签:1.5   时间   ted   monit   直接   http   init   number   net   

1.用户空间调用(参考 poll(2) - Linux man page

 int poll(struct pollfd *fds, nfds_t nfds, int timeout);

it waits for one of a set of file descriptors to become ready to perform I/O.

The set of file descriptors to be monitored is specified in the fds argument, which is an array of structures of the following form:

struct pollfd {
    int   fd;         /* file descriptor */
    short events;     /* requested events */
    short revents;    /* returned events */
};

关于timeout参数的说明:

  timeout>0,设置超时时间为timeout

  timeout=0,直接返回

  timeout<0,无限长超时时间

返回值说明:

On success, a positive number is returned; this is the number of structures which have nonzero revents fields (in other words, those descriptors with events or errors reported).

A value of 0 indicates that the call timed out and no file descriptors were ready. On error, -1 is returned, and errno is set appropriately.

2.内核调用

asmlinkage long sys_poll(struct pollfd __user *ufds, unsigned int nfds,long timeout_msecs)
    -->ret = do_sys_poll(ufds, nfds, &timeout);
        -->struct poll_wqueues table;
        -->poll_initwait(&table);
            -->init_poll_funcptr(&pwq->pt, __pollwait);
        -->fdcount = do_poll(nfds, head, &table, timeout);
            -->do_pollfd(pfd, pt)
                -->if (file->f_op && file->f_op->poll)

2.1

Linux poll机制

标签:1.5   时间   ted   monit   直接   http   init   number   net   

原文地址:http://www.cnblogs.com/yangjiguang/p/7622780.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!