Home

Awesome

wepoll - 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.

Rationale

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.

Features

Limitations

How to use

The library is distributed as a single source file (wepoll.c) and a single header file (wepoll.h).<br> Compile the .c file as part of your project, and include the header wherever needed.

Compatibility

API

General remarks

epoll_create/epoll_create1

HANDLE epoll_create(int size);
HANDLE epoll_create1(int flags);

epoll_close

int epoll_close(HANDLE ephnd);

epoll_ctl

int epoll_ctl(HANDLE ephnd,
              int op,
              SOCKET sock,
              struct epoll_event* event);

epoll_wait

int epoll_wait(HANDLE ephnd,
               struct epoll_event* events,
               int maxevents,
               int timeout);

struct epoll_event

typedef 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 */
};
EventDescription
EPOLLINincoming data available, or incoming connection ready to be accepted
EPOLLOUTready to send data, or outgoing connection successfully established
EPOLLRDHUPremote peer initiated graceful socket shutdown
EPOLLPRIout-of-band data available for reading
EPOLLERRsocket error<sup>1</sup>
EPOLLHUPsocket hang-up<sup>1</sup>
EPOLLRDNORMsame as EPOLLIN
EPOLLRDBANDsame as EPOLLPRI
EPOLLWRNORMsame as EPOLLOUT
EPOLLWRBANDsame as EPOLLOUT
EPOLLMSGnever reported
FlagDescription
EPOLLONESHOTreport event(s) only once
EPOLLETnot supported by wepoll
EPOLLEXCLUSIVEnot supported by wepoll
EPOLLWAKEUPnot supported by wepoll

<sup>1</sup>: the EPOLLERR and EPOLLHUP events may always be reported by epoll_wait(), regardless of the event mask that was passed to epoll_ctl().