nibanks / eventq

Explores the different platform execution models for IO.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

eventq

Explores the different platform execution models for IO.

Build

The "main loop" of the application layer looks like this:

PLATFORM_THREAD(main_loop, context) {
    printf("Main loop start\n");
    app_state* state = (app_state*)context;
    bool running = true;
    eventq_cqe events[8];
    while (running) {
        uint32_t wait_time = platform_process_timers();
        uint32_t count = eventq_dequeue(&state->queue, events, 8, wait_time);
        for (uint32_t i = 0; i < count; ++i) {
            if (eventq_cqe_get_type(&events[i]) < APP_EVENT_TYPE_START) {
                platform_process_event(&state->queue, &events[i]);
            } else {
                switch ((APP_EVENT_TYPE)eventq_cqe_get_type(&events[i])) {
                ...
                }
            }
        }
        eventq_return(&state->queue, count);
    }
    printf("Main loop end\n");
    PLATFORM_THREAD_RETURN(0);
}

Feel free to look at eventq.h for the abstraction layers and eventq.c for the application layer usage.

IO Completion Ports

IO Completion Ports, or IOCP, is the standard mechanism for asynchronous IO on Windows. Generally, it is used to return the completion of a previous asynchronous call made by the application.

To try it out, run the following (on Windows):

git clone --recursive https://github.com/nibanks/eventq.git
cd eventq && mkdir build && cd build
cmake -G 'Visual Studio 17 2022' -A x64 ..
cmake --build .
./Debug/eventq.exe

ProcessSocketNotifications

ProcessSocketNotifications (PSN for short) is a fairly new Windows socket API that allows for an epoll or kqueue like IO model. It also leverages IO completion ports, but is event driven instead of simply a completion of a previous call.

To try it out, run the following (on Windows):

git clone --recursive https://github.com/nibanks/eventq.git
cd eventq && mkdir build && cd build
cmake -G 'Visual Studio 17 2022' -A x64 -DUSE_PSN=on ..
cmake --build .
./Debug/eventq.exe

epoll

epoll is generally viewed as the industry standard way for handling asynchronous operations on not just socket, but all file descriptors, on Linux.

To try it out, run the following (on Ubuntu):

git clone --recursive https://github.com/nibanks/eventq.git
cd eventq && mkdir build && cd build
cmake -G 'Unix Makefiles' -A x64 ..
cmake --build .
./eventq

liburing

liburing is a library built on top of io_uring which is a fairly new interface for creating shared ring buffers between kernel and user mode to reduce the number of syscalls required to operate on file descriptors, such as sockets.

To try it out, run the following (on Ubuntu):

sudo apt-get install liburing-dev
git clone --recursive https://github.com/nibanks/eventq.git
cd eventq && mkdir build && cd build
cmake -G 'Unix Makefiles' -A x64 -DUSE_IO_URING=on ..
cmake --build .
./eventq

kqueue

kqueue is generally viewed as the industry standard way for handling asynchronous operations on not just socket, but all file descriptors, on FreeBSD or mac.

To try it out, run the following (on macOS):

git clone --recursive https://github.com/nibanks/eventq.git
cd eventq && mkdir build && cd build
cmake -G 'Unix Makefiles' -A x64 ..
cmake --build .
./eventq

About

Explores the different platform execution models for IO.

License:MIT License


Languages

Language:C 96.8%Language:CMake 3.2%