Author : Paulus Gandung Prakosa (syn1988@sdf.lonestar.org)

Controlling Epoll

The epoll_ctl() system call can be used to add file descriptors to and remove file descriptors from a given epoll context :

		#include <sys/epoll.h>
		
		int epoll_ctl (int epfd,
				int op,
				int fd,
				struct epoll_event *event);
	

The header <sys/epoll.h> defines the epoll_event structure as :

		struct epoll_event {
			__u32 events;		/* events */
			union {
				void *ptr;
				int fd;
				__u32 u32;
				__u64 u64;
			} data;
		};
	

A successful call to epoll_ctl() controls the epoll instance associated with the file descriptor epfd. The parameter op specifies the operation to be taken against the file associated with fd. The event parameter further describes the behavior of the operation.

Here are valid values for the op parameter :

The events field in the epoll_event structure lists which events to monitor on the given file descriptor. Multiple events can be bitwise-ORed together. Here are valid values :

The data field inside the event_poll structure is for user's private use. The contents are returned to the user upon receipt of the requested event. The common practice is to set event.data.fd to fd, which makes it easy to look up which file descriptor caued the event.

Upon success, epoll_ctl() returns 0. On failure, the call returns -1, and sets global variable errno to one of the following values :