1 module tango.sys.linux.epoll;
2 
3 version (linux)
4 {
5 	// From <sys/epoll.h>: support for the Linux epoll_*() system calls
6 	extern (C)
7 	{
8 		enum: uint
9 		{
10 			EPOLLIN         = 0x001,
11 			EPOLLPRI        = 0x002,
12 			EPOLLOUT        = 0x004,
13 			EPOLLRDNORM     = 0x040,
14 			EPOLLRDBAND     = 0x080,
15 			EPOLLWRNORM     = 0x100,
16 			EPOLLWRBAND     = 0x200,
17 			EPOLLMSG        = 0x400,
18 			EPOLLERR        = 0x008,
19 			EPOLLHUP        = 0x010,
20 			EPOLLONESHOT    = (1 << 30),
21 			EPOLLET         = (1 << 31)
22 		}
23 
24 		// Valid opcodes ( "op" parameter ) to issue to epoll_ctl().
25 		public const int EPOLL_CTL_ADD = 1;	// Add a file descriptor to the interface.
26 		public const int EPOLL_CTL_DEL = 2;	// Remove a file descriptor from the interface.
27 		public const int EPOLL_CTL_MOD = 3;	// Change file descriptor epoll_event structure.
28 
29 		align(1) union epoll_data
30 		{
31 			void* ptr;
32 			int fd;
33 			uint u32;
34 			ulong u64;
35 		}
36 
37 		alias epoll_data epoll_data_t;
38 
39 		align(1) struct epoll_event
40 		{
41 			uint events;		// Epoll events
42 			epoll_data_t data;	// User data variable
43 		}
44 
45 		// Creates an epoll instance. Returns an fd for the new instance.
46 		// The "size" parameter is a hint specifying the number of file
47 		// descriptors to be associated with the new instance. The fd
48 		// returned by epoll_create() should be closed with close().
49 		int epoll_create(int size);
50 
51 		// Manipulate an epoll instance "epfd". Returns 0 in case of success,
52 		// -1 in case of error (the "errno" variable will contain the
53 		// specific error code) The "op" parameter is one of the EPOLL_CTL_*
54 		// constants defined above. The "fd" parameter is the target of the
55 		// operation. The "event" parameter describes which events the caller
56 		// is interested in and any associated user data.
57 		int epoll_ctl(int epfd, int op, int fd, epoll_event* event);
58 
59 		// Wait for events on an epoll instance "epfd". Returns the number of
60 		// triggered events returned in "events" buffer. Or -1 in case of
61 		// error with the "errno" variable set to the specific error code. The
62 		// "events" parameter is a buffer that will contain triggered
63 		// events. The "maxevents" is the maximum number of events to be
64 		// returned (usually size of "events"). The "timeout" parameter
65 		// specifies the maximum wait time in milliseconds (-1 == infinite).
66 		int epoll_wait(int epfd, epoll_event* events, int maxevents, int timeout);
67 	}
68 }