Socket for Linux network programming (13) Introduction to Epoll series functions the difference between Select and poll

Source: Internet
Author: User
Tags epoll int size socket

Introduction of Epoll Series functions

#include <sys/epoll.h>

int epoll_create (int size);

int epoll_create1 (int flags);

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

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

* Epoll_create (2) creates a Epoll instance and returns a file descriptor referring to that instance. (The more recent

Epoll_create1 (2) extends the functionality of Epoll_create (2).)

* Interest in particular file descriptors is then registered via EPOLL_CTL (2). The set of file descriptors currently

Registered on a Epoll instance is sometimes called a epoll set.

* EPOLL_WAIT (2) waits for I/O events, blocking the calling thread if no events are currently.

1. Epoll_create1 produces a Epoll instance that returns the handle to the instance. Flag can be set to 0 or epoll_cloexec, the 0 o'clock function behaves the same as Epoll_create, and the EPOLL_CLOEXEC flag is similar to the O_CLOEXEC flag on open, which closes the file descriptor when the process is replaced.

2, Epoll_ctl:

(1) Epfd:epoll instance handle;

(2) OP: The operation of the document descriptor FD, mainly Epoll_ctl_add, Epoll_ctl_del, etc.

(3) FD: The target file descriptor required to operate;

(4) Event: Structural body pointer

typedef Union EPOLL_DATA {

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 parameters mainly include Epollin, Epollout, Epollet, epolllt, etc. general data community we set its member FD, that is, the third parameter of the EPOLL_CTL function.

3, Epoll_wait:

(1) Epfd:epoll instance handle;

(2) Events: Structural body pointers

(3) Maxevents: Maximum number of events

(4) Timeout: timeout, set to-1 means never time out

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.