Style
[mono.git] / mcs / class / Mono.Posix / Mono.Unix.Native / Syscall.cs
index 27c4047095bfcb6de6f60fa6be7661ff9c165d02..a95c5ee670991e0508aefb0f7fda765e694d9e2f 100644 (file)
@@ -1136,6 +1136,50 @@ namespace Mono.Unix.Native {
                }
        }
 
+       [Flags][Map]
+       public enum EpollFlags {
+               EPOLL_CLOEXEC = 02000000,
+               EPOLL_NONBLOCK = 04000,
+       }
+
+       [Flags][Map]
+       [CLSCompliant (false)]
+       public enum EpollEvents : uint {
+               EPOLLIN = 0x001,
+               EPOLLPRI = 0x002,
+               EPOLLOUT = 0x004,
+               EPOLLRDNORM = 0x040,
+               EPOLLRDBAND = 0x080,
+               EPOLLWRNORM = 0x100,
+               EPOLLWRBAND = 0x200,
+               EPOLLMSG = 0x400,
+               EPOLLERR = 0x008,
+               EPOLLHUP = 0x010,
+               EPOLLRDHUP = 0x2000,
+               EPOLLONESHOT = 1 << 30,
+               EPOLLET = unchecked ((uint) (1 << 31))
+       }
+
+       public enum EpollOp {
+               EPOLL_CTL_ADD = 1,
+               EPOLL_CTL_DEL = 2,
+               EPOLL_CTL_MOD = 3,
+       }
+
+       [StructLayout (LayoutKind.Explicit, Size=12, Pack=1)]
+       [CLSCompliant (false)]
+       public struct EpollEvent {
+               [FieldOffset (0)]
+               public EpollEvents events;
+               [FieldOffset (4)]
+               public int fd;
+               [FieldOffset (4)]
+               public IntPtr ptr;
+               [FieldOffset (4)]
+               public uint u32;
+               [FieldOffset (4)]
+               public ulong u64;
+       }
        #endregion
 
        #region Classes
@@ -2623,6 +2667,48 @@ namespace Mono.Unix.Native {
 
                #endregion
 
+               #region <sys/epoll.h> Declarations
+
+               public static int epoll_create (int size)
+               {
+                       return sys_epoll_create (size);
+               }
+
+               public static int epoll_create (EpollFlags flags)
+               {
+                       return sys_epoll_create1 (flags);
+               }
+
+               public static int epoll_ctl (int epfd, EpollOp op, int fd, EpollEvents events)
+               {
+                       EpollEvent ee = new EpollEvent ();
+                       ee.events = events;
+                       ee.fd = fd;
+
+                       return sys_epoll_ctl (epfd, op, fd, ref ee);
+               }
+
+               public static int epoll_wait (int epfd, EpollEvent [] events, int max_events, int timeout)
+               {
+                       if (events.Length < max_events)
+                               throw new ArgumentOutOfRangeException ("events", "Must refer to at least 'max_events' elements.");
+
+                       return sys_epoll_wait (epfd, events, max_events, timeout);
+               }
+
+               [DllImport (LIBC, SetLastError=true, EntryPoint="epoll_create")]
+               private static extern int sys_epoll_create (int size);
+
+               [DllImport (LIBC, SetLastError=true, EntryPoint="epoll_create1")]
+               private static extern int sys_epoll_create1 (EpollFlags flags);
+
+               [DllImport (LIBC, SetLastError=true, EntryPoint="epoll_ctl")]
+               private static extern int sys_epoll_ctl (int epfd, EpollOp op, int fd, ref EpollEvent ee);
+
+               [DllImport (LIBC, SetLastError=true, EntryPoint="epoll_wait")]
+               private static extern int sys_epoll_wait (int epfd, EpollEvent [] ee, int maxevents, int timeout);
+               #endregion
+               
                #region <sys/mman.h> Declarations
                //
                // <sys/mman.h>