2020-12-08
It is vital to re-register, using libc::EPOLL_CTL_MOD
when using epoll in
one-shot mode.
Example adding a file descriptor.
epoll_ctl(
epoll_fd,
libc::EPOLL_CTL_ADD
fd,
&mut event as *mut libc::epoll_event
);
Updating a file descriptor is vital when using epoll in one-shot mode.
Example updating a file descriptor.
epoll_ctl(
epoll_fd,
libc::EPOLL_CTL_MOD
fd,
&mut event as *mut libc::epoll_event
);
Example removing a file descriptor.
epoll_ctl(
epoll_fd,
libc::EPOLL_CTL_DEL
fd, // removes this fd
ptr::null_mut(), // event is not required since kernel 2.6.9
);
TODO: finish this.
See man epoll_ctl
Edge triggered: only triggers events when the underlying file descriptor changes. Without ONESHOT multiple events might still be triggered for the same file descriptor.
libc::EPOLLET
When passed to epoll, the selected file descriptor is registered for read events.
When received from epoll through epoll_wait
the file descriptor can be read from.
libc::EPOLLIN
When passed to epoll, the selected file descriptor is registered for write events.
When received from epoll through epoll_wait
the file descriptor can be written
to.
libc::EPOLLOUT
Urgent read
libc::EPOLLPRI
Error on the associated file descriptor. This is set by epoll.
libc::EPOLLERR
Hang up the file descriptor.
libc::EPOLLHUP
Socket closed or writing half shut down.
Useful to be notified whether the socket was closed or not: EPOLLIN | EPOLLRDHUP
libc::EPOLLRDHUP
libc::EPOLLWAKEUP // Prevents system for sleep (what is a system here?)
libc::EPOLLONESHOT // Without one-shot it's possible to receive multiple events
Looks like it will only wake up the epoll file descriptor where this event's
file descriptor was registered, if the event was registered with EPOLLEXCLUSIVE
.
libc::EPOLLEXCLUSIVE //
See man eventfd
and libc::eventfd