Epol Study Notes to learn more about epoll

Source: Internet
Author: User

Epol Study Notes to learn more about epoll

Epol Study Notes

LEpollRelated system calls

Epoll_create ()

Epoll_ctl ()

Epoll_wait ()

LInt epoll_create (int size );

Create an epoll handle.

LInt epoll_ctl (int epfd, int op, int fd, struct epoll_event * event );

Epoll event registration function.

1. The first parameter is the returned value of epoll_create.

2. The second parameter represents an action, represented by three macros:

EPOLL_CTL_ADD: Register a new fd to epfd;

EPOLL_CTL_MOD: Modify the listening events of the registered fd;

EPOLL_CTL_DEL: Delete an fd from epfd.

3. The third parameter is the fd to be monitored.

4. The fourth parameter is to tell the kernel what to listen.

The structure of struct epoll_event is as follows:

Typedef union epoll_data

{// Save the data related to a file descriptor of the trigger event

Void * ptr;

Int fd;

_ Uint32_t u32;

_ Uint64_t u64;

} Epoll_data_t;

 

Struct epoll_event

{

_ Uint32_t events;/* Epoll events */

Epoll_data_t data;/* User data variable */

};

Events can be a collection of the following macros:

LInt epoll_wait (int epfd, struct epoll_event * events, int maxevents, int timeout );

Collect events that have occurred in epoll monitoring events.

LEdge TriggeredWorking Mode

@ Based on non-blocking file handle

@ It must be suspended only when read () or write () returns EAGAIN.

However, this does not mean that every read () operation needs to be performed cyclically until an EAGAIN is generated. When read () when the returned data length is less than the requested data length, you can determine that there is no data in the buffer at this time, so that the read event has been processed.

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.