wepoll-d — a single-file D port of wepoll (epoll-style socket polling for Windows)

Timur Moldazhan tim.moldazhan at gmail.com
Tue Nov 24 08:58:42 UTC 2026


Hi D community,

I'd like to share **wepoll-d**, a native D port of
[wepoll](https://github.com/piscisaureus/wepoll) — Bert Belder's 
epoll
emulation for Windows generated with the help of AI.

**Repo:** https://github.com/Timok82/wepoll-d

### What it is

     - One self-contained module, `wepoll.d`. No C sources, 
headers or import
       libraries needed — it only depends on druntime's `core.*` 
modules.
     - The public API mirrors `core.sys.linux.epoll`, plus the 
wepoll.h specifics:
       `epoll_create`, `epoll_create1`, `epoll_ctl`, `epoll_wait`, 
`epoll_close`,
       and `epoll_data_t` with the Windows-only `sock` / `hnd` 
members.
     - All public functions are `extern(C) nothrow @nogc`. The 
`extern(C)` is only
       there to give them a C-compatible ABI — the implementation 
is 100% D,
       not a binding around a C library.
     - Thread-safe: multiple threads can poll the same port, and a 
socket can be
       registered in multiple epoll sets. Level-triggered and 
`EPOLLONESHOT` are
       supported; `EPOLLET` is not.

### Usage

```d
import wepoll;
import core.sys.windows.winsock2;

HANDLE ep = epoll_create1(0);

epoll_event ev;
ev.events = EPOLLIN | EPOLLRDHUP;
ev.data.sock = listener;
epoll_ctl(ep, EPOLL_CTL_ADD, listener, &ev);

     epoll_event[64] events;
     int n = epoll_wait(ep, events.ptr, cast(int) events.length, 
-1);
     foreach (i; 0 .. n) {
         // events[i].data.sock, events[i].events
     }

epoll_close(ep);
```

Requirements: Windows Vista+, recent dmd/ldc/gdc. The module 
declares
pragma(lib, "Kernel32") and pragma(lib, "Ws2_32"), so linking is 
handled
automatically with dmd/ldc.
One gotcha: use the exported EPOLL_CTL_* constants instead of 
hard-coded
numbers — this module follows wepoll.h (ADD = 1, MOD = 2, DEL = 
3),
which is a different order from Linux.
License: BSD 2-clause, inherited from the original wepoll.
Feedback, bug reports and PRs are very welcome — especially if 
you give it a
try in a real Windows project.


More information about the Digitalmars-d-announce mailing list