wepoll: fast epoll for windows
This library implements the epoll API for Windows applications. It is fast and scalable, and it closely resembles the API and behavior of Linux' epoll.
Unlike Linux, OS X, and many other operating systems, Windows doesn't
have a good API for receiving socket state notifications. It only
supports the select and WSAPoll APIs, but they
don't scale and suffer from
other issues.
Using I/O completion ports isn't always practical when software is designed to be cross-platform. Wepoll offers an alternative that is much closer to a drop-in replacement for software that was designed to run on Linux.
EPOLLIN, EPOLLOUT, EPOLLPRI, EPOLLRDHUP)
are supported.EPOLLONESTHOT) modes are supportedEPOLLET) mode isn't supported.The library is distributed as a single source file (wepoll.c) and a single header file (wepoll.h).
Compile the .c file as part of your project, and include the header wherever needed.
HANDLE, not a file descriptor.errno and GetLastError() on failure.HANDLE epoll_create(int size);
HANDLE epoll_create1(int flags);size is ignored but most be greater than zero.flags must be zero as there are no supported flags.NULL on failure.int epoll_close(HANDLE ephnd);close(),
CloseHandle() or closesocket().int epoll_ctl(HANDLE ephnd,
int op,
SOCKET sock,
struct epoll_event* event);Control which socket events are monitored by an epoll port.
ephnd must be a HANDLE created by
epoll_create() or
epoll_create1().
op must be one of EPOLL_CTL_ADD, EPOLL_CTL_MOD, EPOLL_CTL_DEL.
sock must be a valid socket created by socket(),
WSASocket(), or accept().
event should be a pointer to a struct epoll_event.
If op is EPOLL_CTL_DEL then the event parameter is ignored, and it
may be NULL.
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
to epoll_wait().
int epoll_wait(HANDLE ephnd,
struct epoll_event* events,
int maxevents,
int timeout);events should point to a caller-allocated array of
epoll_event structs, which will receive the
reported events.maxevents is the maximum number of events that will be written to the
events array, and must be greater than zero.timeout specifies whether to block when no events are immediately available.1 | | EPOLLHUP | socket hang-up1 | |EPOLLRDNORM| same asEPOLLIN | |EPOLLRDBAND| same asEPOLLPRI | |EPOLLWRNORM| same asEPOLLOUT | |EPOLLWRBAND| same asEPOLLOUT | |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().
No open issues yet, or sync has not completed.