Skip to content

core: event: add native windows backend - #436

Open
edsiper wants to merge 2 commits into
masterfrom
dev
Open

core: event: add native windows backend#436
edsiper wants to merge 2 commits into
masterfrom
dev

Conversation

@edsiper

@edsiper edsiper commented Apr 10, 2026

Copy link
Copy Markdown
Member
  • Added a native Windows event loop backend for mk_event
  • Kept the existing mk_event interface behavior for:
    • readable sockets
    • notification channels
    • timer events
    • injected events
  • Updated build selection so:
    • Windows now defaults to the native backend
    • libevent is only built when explicitly requested

Tests Added

Added unit coverage for the public event loop interface, including:

  • channel notification delivery
  • add / wait / delete flow
  • duplicate-safe event injection
  • timeout delivery

Verification

cmake -S . -B build -DMK_TESTS=ON
cmake --build build
./build/bin/mk-test-event_loop
./build/bin/mk-test-event_timeout
./build/bin/mk-test-lib_server

edsiper added 2 commits April 9, 2026 21:46
The event loop interface selected libevent on Windows when no Unix\nbackend applied. Replace that implicit fallback with a native\nWinSock-based backend so the core event loop no longer depends on\nlibevent for Windows builds by default.\n\nThe new backend keeps the existing mk_event interface semantics for\nreadable sockets, notification channels, timer delivery, and injected\nevents. Update the build selection logic so Windows defaults to the\nnative backend and only builds libevent when it is requested\nexplicitly.\n\nAdd unit coverage for the public event loop interface, including\nchannel notifications, add/wait/delete flow, duplicate-safe injection,\nand timeout delivery.\n\nVerified with:\n- cmake -S . -B build -DMK_TESTS=ON\n- cmake --build build\n- ./build/bin/mk-test-event_loop\n- ./build/bin/mk-test-event_timeout\n- ./build/bin/mk-test-lib_server

Signed-off-by: Eduardo Silva <edsiper@gmail.com>
The native Windows event loop backend removed the libevent build\nrequirement, but mk_fifo still included event.h and used\nevutil_socketpair() on Windows. Replace that path with a native socket\npair helper so the server code builds without libevent headers.\n\nAlso update the pthread_once callback prototype in mk_server/monkey.c\nto use an explicit void parameter list, which avoids the MSVC C4113\nwarning during Windows builds.\n\nVerified with:\n- cmake --build build --target monkey-core-static\n- cmake --build build --target mk-test-lib_server\n- cmake --build build --target mk-test-event_loop\n- cmake --build build --target mk-test-event_timeout

Signed-off-by: Eduardo Silva <edsiper@gmail.com>
Comment thread mk_core/mk_event_win32.c

static LONG win32_wsa_initialized = 0;

static int win32_socketpair(SOCKET pair[2])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Windows 10 1803, we can use AF_UNIX on Windows with including afunix.h like:

#ifdef EVENT__HAVE_AFUNIX_H
#include <afunix.h>
#endif

/* ... */
SOCKET s = socket(AF_UNIX, SOCK_STREAM, 0);

struct sockaddr_un addr;
addr.sun_family = AF_UNIX;
strcpy_s(addr.sun_path, sizeof(addr.sun_path), "C:\\Temp\\xxx.sock");

For further information, we can refer the following links:

https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, we can include this type of changes in libevent to monkey event system:
libevent/libevent#913

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants