Linux poll mechanism

Source: Internet
Author: User

1. User space Invocation (ref. poll (2)-Linux man page)

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

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

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

struct POLLFD {    int   FD;         /*  */short     events;     /*  */short     revents;    /* */};

A description of the timeout parameter:

Timeout>0, set timeout time to timeout

Timeout=0, return directly

Timeout<0, unlimited long timeout time

Return Value Description:

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

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

2. Kernel calls

long sys_poll (structint 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                )--andif (file->f_op && file->f_op->poll)

2.1

Linux poll mechanism

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.