summary refs log tree commit diff stats
path: root/lib/posix/epoll.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/posix/epoll.nim')
-rw-r--r--lib/posix/epoll.nim99
1 files changed, 99 insertions, 0 deletions
diff --git a/lib/posix/epoll.nim b/lib/posix/epoll.nim
new file mode 100644
index 000000000..007488354
--- /dev/null
+++ b/lib/posix/epoll.nim
@@ -0,0 +1,99 @@
+#
+#
+#            Nim's Runtime Library
+#        (c) Copyright 2013 Dominik Picheta
+#
+#    See the file "copying.txt", included in this
+#    distribution, for details about the copyright.
+#
+
+from std/posix import SocketHandle
+
+const
+  EPOLLIN* = 0x00000001
+  EPOLLPRI* = 0x00000002
+  EPOLLOUT* = 0x00000004
+  EPOLLERR* = 0x00000008
+  EPOLLHUP* = 0x00000010
+  EPOLLRDNORM* = 0x00000040
+  EPOLLRDBAND* = 0x00000080
+  EPOLLWRNORM* = 0x00000100
+  EPOLLWRBAND* = 0x00000200
+  EPOLLMSG* = 0x00000400
+  EPOLLRDHUP* = 0x00002000
+  EPOLLEXCLUSIVE* = 1 shl 28
+  EPOLLWAKEUP* = 1 shl 29
+  EPOLLONESHOT* = 1 shl 30
+  EPOLLET* = 1 shl 31
+
+# Valid opcodes ( "op" parameter ) to issue to epoll_ctl().
+
+const
+  EPOLL_CTL_ADD* = 1          # Add a file descriptor to the interface.
+  EPOLL_CTL_DEL* = 2          # Remove a file descriptor from the interface.
+  EPOLL_CTL_MOD* = 3          # Change file descriptor epoll_event structure.
+
+# https://github.com/torvalds/linux/blob/ff6992735ade75aae3e35d16b17da1008d753d28/include/uapi/linux/eventpoll.h#L77
+when defined(linux) and defined(amd64):
+  {.pragma: epollPacked, packed.}
+else:
+  {.pragma: epollPacked.}
+
+type
+  EpollData* {.importc: "epoll_data_t",
+      header: "<sys/epoll.h>", pure, final, union.} = object
+    `ptr`* {.importc: "ptr".}: pointer
+    fd* {.importc: "fd".}: cint
+    u32* {.importc: "u32".}: uint32
+    u64* {.importc: "u64".}: uint64
+
+  EpollEvent* {.importc: "struct epoll_event", header: "<sys/epoll.h>", pure, final, epollPacked.} = object
+    events*: uint32 # Epoll events
+    data*: EpollData # User data variable
+
+proc epoll_create*(size: cint): cint {.importc: "epoll_create",
+    header: "<sys/epoll.h>".}
+  ## Creates an epoll instance.  Returns an fd for the new instance.
+  ##
+  ## The "size" parameter is a hint specifying the number of file
+  ## descriptors to be associated with the new instance.  The fd
+  ## returned by epoll_create() should be closed with close().
+
+proc epoll_create1*(flags: cint): cint {.importc: "epoll_create1",
+    header: "<sys/epoll.h>".}
+  ## Same as epoll_create but with an FLAGS parameter.  The unused SIZE
+  ## parameter has been dropped.
+
+proc epoll_ctl*(epfd: cint; op: cint; fd: cint | SocketHandle; event: ptr EpollEvent): cint {.
+    importc: "epoll_ctl", header: "<sys/epoll.h>".}
+  ## Manipulate an epoll instance "epfd". Returns `0` in case of success,
+  ## `-1` in case of error (the "errno" variable will contain the specific error code).
+  ##
+  ## The "op" parameter is one of the `EPOLL_CTL_*`
+  ## constants defined above. The "fd" parameter is the target of the
+  ## operation. The "event" parameter describes which events the caller
+  ## is interested in and any associated user data.
+
+proc epoll_wait*(epfd: cint; events: ptr EpollEvent; maxevents: cint;
+                 timeout: cint): cint {.importc: "epoll_wait",
+    header: "<sys/epoll.h>".}
+  ## Wait for events on an epoll instance "epfd". Returns the number of
+  ## triggered events returned in "events" buffer. Or -1 in case of
+  ## error with the "errno" variable set to the specific error code. The
+  ## "events" parameter is a buffer that will contain triggered
+  ## events. The "maxevents" is the maximum number of events to be
+  ## returned ( usually size of "events" ). The "timeout" parameter
+  ## specifies the maximum wait time in milliseconds (-1 == infinite).
+  ##
+  ## This function is a cancellation point and therefore not marked with
+  ## __THROW.
+
+
+#proc epoll_pwait*(epfd: cint; events: ptr EpollEvent; maxevents: cint;
+#                  timeout: cint; ss: ptr sigset_t): cint {.
+#    importc: "epoll_pwait", header: "<sys/epoll.h>".}
+# Same as epoll_wait, but the thread's signal mask is temporarily
+# and atomically replaced with the one provided as parameter.
+#
+# This function is a cancellation point and therefore not marked with
+# __THROW.
a>
03ba0f3e2 ^

8c0e27e8d ^


39049e151 ^
03ba0f3e2 ^





39049e151 ^
e7cdb1d69 ^
39049e151 ^

03ba0f3e2 ^

e7cdb1d69 ^

7d6500f1d ^

39049e151 ^
03ba0f3e2 ^

39049e151 ^
e65c296bc ^
39049e151 ^
03ba0f3e2 ^


39049e151 ^
03ba0f3e2 ^
eea2a6360 ^
03ba0f3e2 ^

5258447e0 ^
03ba0f3e2 ^
e6c5622aa ^
03ba0f3e2 ^


153441db1 ^
a42545ea3 ^
39049e151 ^
153441db1 ^
a42545ea3 ^
153441db1 ^




03ba0f3e2 ^

3a13706d7 ^


e7cdb1d69 ^
03ba0f3e2 ^
92b8fac94 ^
7d6500f1d ^
39049e151 ^
03ba0f3e2 ^
df1ec0939 ^
56b4e3ad9 ^

46b672a6c ^
56b4e3ad9 ^
73c6efdf6 ^
03ba0f3e2 ^
39049e151 ^
03ba0f3e2 ^
39049e151 ^
03ba0f3e2 ^

153441db1 ^
df1ec0939 ^
39049e151 ^
153441db1 ^
39049e151 ^
153441db1 ^




39049e151 ^
b234b082b ^

03ba0f3e2 ^

b234b082b ^
f7f3a25be ^

39049e151 ^
03ba0f3e2 ^


39049e151 ^
b234b082b ^
39049e151 ^
03ba0f3e2 ^
39049e151 ^


03ba0f3e2 ^
438703f59 ^
03ba0f3e2 ^
39049e151 ^
03ba0f3e2 ^
b234b082b ^
5c33f7651 ^
39049e151 ^
5c33f7651 ^
39049e151 ^







c6235920c ^

39049e151 ^
ab6f79340 ^

6ddd4e6a3 ^
4b0ba5e3f ^
39049e151 ^
6ddd4e6a3 ^

fab69661a ^
39049e151 ^
ab6f79340 ^

b234b082b ^
6ddd4e6a3 ^
39049e151 ^





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175