xlt-evil 339c93e477 | преди 6 месеца | |
---|---|---|
.. | ||
sys | преди 6 месеца | |
LICENSE | преди 6 месеца | |
README.md | преди 6 месеца | |
wepoll.c | преди 6 месеца | |
wepoll.h | преди 6 месеца |
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);
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
.op
is EPOLL_CTL_DEL
then the event
parameter is ignored, and it
may be NULL
.EPOLL_CTL_DEL
before closing it.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.
<0
block indefinitely0
report any events that are already waiting, but don't block≥1
block for at most N milliseconds-1
an error occurred0
timed out without any events to report≥1
the number of events stored in the events
buffertypedef union epoll_data {
void* ptr;
int fd;
uint32_t u32;
uint64_t u64;
SOCKET sock; /* Windows specific */
HANDLE hnd; /* Windows specific */
} epoll_data_t;
struct epoll_event {
uint32_t events; /* Epoll events and flags */
epoll_data_t data; /* User data variable */
};
events
field is a bit mask containing the events being
monitored/reported, and optional flags.epoll_ctl()
, but they are not reported
back by epoll_wait()
.data
field can be used to associate application-specific information
with a socket; its value will be returned unmodified by
epoll_wait()
.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()
.