Windows epoll wrapper based on wepoll
nimble install wepoll
Docs from https://github.com/piscisaureus/wepoll
- The epoll port is a
EpollHandle
, not a file descriptor. - All functions set both
errno
andGetLastError()
on failure. - For more extensive documentation, see the epoll(7) man page, and the per-function man pages that are linked below.
proc epoll_create*(size: cint): EpollHandle
proc epoll_create1*(flags: cint): EpollHandle
- Create a new epoll instance (port).
size
is ignored but most be greater than zero.flags
must be zero as there are no supported flags.- Returns
NULL
on failure. - Linux man page
proc epoll_close*(ephnd: EpollHandle): cint
- Close an epoll port.
- Do not attempt to close the epoll port with
close()
,CloseHandle()
orclosesocket()
.
proc epoll_ctl*(ephnd: EpollHandle, op: cint,
sock: EpollSocket, event: ptr EpollEvent): cint {.wepoll.}
- Control which socket events are monitored by an epoll port.
ephnd
must be a EpollHandle created byepoll_create()
orepoll_create1()
.op
must be one ofEPOLL_CTL_ADD
,EPOLL_CTL_MOD
,EPOLL_CTL_DEL
.sock
must be a valid socket created bysocket()
,WSASocket()
, oraccept()
.event
should be a pointer to aEpollEvent
.
Ifop
isEPOLL_CTL_DEL
then theevent
parameter is ignored, and it may beNULL
.- Returns 0 on success, -1 on failure.
- It is recommended to always explicitly remove a socket from its epoll
set using
EPOLL_CTL_DEL
before closing it.
As on Linux, closed sockets are automatically removed from the epoll set, but wepoll may not be able to detect that a socket was closed until the next call toepoll_wait()
. - Linux man page
proc epoll_wait*(ephnd: EpollHandle, events: ptr EpollEvent,
maxevents: cint, timeout: cint): cint {.wepoll.}
- Receive socket events from an epoll port.
events
should point to a caller-allocated array ofEpollEvent
object, which will receive the reported events.maxevents
is the maximum number of events that will be written to theevents
array, and must be greater than zero.timeout
specifies whether to block when no events are immediately available.<0
block indefinitely0
report any events that are already waiting, but don't block≥1
block for at most N milliseconds
- Return value:
-1
an error occurred0
timed out without any events to report≥1
the number of events stored in theevents
buffer
- Linux man page
type
EpollHandle* = pointer
EpollSocket* = culonglong
type
EpollData* {.bycopy, union.} = object
p*: pointer
fd*: cint
u32*: uint32
u64*: uint64
sock*: EpollSocket ## Windows specific
hnd*: EpollHandle ## Windows specific
type
EpollEvent* {.bycopy.} = object
events*: uint32 ## Epoll events and flags
data*: EpollData ## User data variable
- The
events
field is a bit mask containing the events being monitored/reported, and optional flags.
Flags are accepted byepoll_ctl()
, but they are not reported back byepoll_wait()
. - The
data
field can be used to associate application-specific information with a socket; its value will be returned unmodified byepoll_wait()
. - Linux man page
Event | Description |
---|---|
EPOLLIN |
incoming data available, or incoming connection ready to be accepted |
EPOLLOUT |
ready to send data, or outgoing connection successfully established |
EPOLLRDHUP |
remote peer initiated graceful socket shutdown |
EPOLLPRI |
out-of-band data available for reading |
EPOLLERR |
socket error1 |
EPOLLHUP |
socket hang-up1 |
EPOLLRDNORM |
same as EPOLLIN |
EPOLLRDBAND |
same as EPOLLPRI |
EPOLLWRNORM |
same as EPOLLOUT |
EPOLLWRBAND |
same as EPOLLOUT |
EPOLLMSG |
never reported |
Flag | Description |
---|---|
EPOLLONESHOT |
report event(s) only once |
EPOLLET |
not supported by wepoll |
EPOLLEXCLUSIVE |
not supported by wepoll |
EPOLLWAKEUP |
not supported by wepoll |
1: the EPOLLERR
and EPOLLHUP
events may always be reported by
epoll_wait()
, regardless of the event mask that was passed to
epoll_ctl()
.