How does a socket event get propagated/converted to epoll?

Asked
Active3 hr before
Viewed126 times

4 Answers

socketevent
90%

The most glaring problem with epoll documentation is its failure to state in "bold caps" that epoll events, are, in fact, fully identical to poll (2) events. Indeed, on the kernel side epoll handles its events in terms of older poll event names:, 1 Epoll does all the critical work in the kernel as this post explains well: stackoverflow.com/questions/5383959/… ... what exactly is the problem you are trying to solve? – Shafik Yaghmour Aug 7 '13 at 12:52 ,All the critical work for epoll is done in the kernel, the user space API is just an interface. The previous thread on Why exactly does ePoll scale better than Poll? covers the details of how the kernel implements epoll is nice details., My questions are that there are many other possible events (as I listed in my original questions). However, there is no document mentioning under what situation each type of event on the socket will be propagated to epoll_wait(). Let's take an example, what happens to the socket that epoll_wait() will receive EPOLLRDNORM? – Hei Aug 8 '13 at 10:09

The most glaring problem with epoll documentation is its failure to state in "bold caps" that epoll events, are, in fact, fully identical to poll (2) events. Indeed, on the kernel side epoll handles its events in terms of older poll event names:

#define POLLIN 0x0001 // EPOLLIN
#define POLLPRI 0x0002 // EPOLLPRI
#define POLLOUT 0x0004 // EPOLLOUT
#define POLLERR 0x0008 // EPOLLERR
#define POLLHUP 0x0010 // EPOLLHUP
#define POLLNVAL 0x0020 // unused in epoll
#define POLLRDNORM 0x0040 // EPOLLRDNORM
#define POLLRDBAND 0x0080 // EPOLLRDBAND
#define POLLWRNORM 0x0100 // EPOLLWRNORM
#define POLLWRBAND 0x0200 // EPOLLWRBAND
#define POLLMSG 0x0400 // EPOLLMSG
#define POLLREMOVE 0x1000 // unused in epoll
#define POLLRDHUP 0x2000 // EPOLLRDHUP
load more v
88%

epoll_wait waits for FDs in the instance’s interest list, returning ready events. This is the actual polling syscall.,epoll_create creates a new epoll instance in the kernel and returns an epoll file descriptor for this instance.,A3  Yes. If an epoll file descriptor has events waiting, then it will indicate as being readable.,If an epoll_ctl was called (and deferred) before an epoll_wait, it will be executed before performing the wait.

Select was the first system call in Unix to poll many file descriptors (FDs) for read/write. It was created back in the 1980s to allow applications to multiplex I/O on multiple descriptors without the need to busy-loop. Select still exists today but it has its fair share of issues arising from its simplistic original design, one that made sense in the early days of Unix but fails to handle modern server workloads.

fd_set rfds;
struct timeval tv = {
   5,
   0
}; // Wait up to five seconds.
FD_ZERO( & rfds);
FD_SET(STDIN_FILENO, & rfds); // Watch stdin (fd 0) for input

select(STDIN_FILENO + 1, & rfds, NULL, NULL, & tv); // Assume success for sample code
if (FD_ISSET(STDIN_FILENO, & rfds)) {
   printf("Data is available now.\n");
}
load more v
72%

The epoll patch is ready, and Linus has indicated that he wants to merge it. For now, epoll only works for pipes and sockets (its initial use is likely to be network services that manage large numbers of connections). Expanding its scope to other types of I/O should just be a matter of doing the work, however.,the socket activity would cause callbacks , The return value is the number of events (i.e. readable or writeable file descriptors) that epoll_wait() has found. , Once everything has been set up, the process can sit back and wait until there is something for it to do:

    epfd = epoll_create(int maxfds);
load more v
65%

Pipe filesystem inadvertenly clearing edge-triggered epoll event [GH 3276],Pipe filesystem inadvertently clearing edge-triggered epoll event [GH 3276],No WSL related changes in these releases.,Fixed an issue where empty mounts were not handled correctly

  [interop]

  enabled = false # enable launch of Windows binaries;
  default is true

  appendWindowsPath = false # append Windows path to $PATH variable;
  default is true
load more v

Other "socket-event" queries related to "How does a socket event get propagated/converted to epoll?"