Skip to content

pylover/caio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

caio (C AsyncIO)

C non-blocking IO without blocking wait functions and callbacks.

Yes, Duff's device allows simulating coroutine in C.

Features

  • A simple module system to easily extend.
  • Builtin epoll(7) module.
  • Builtin select(2) module.
  • Builtin io_uring(7) module using liburing.

Under the hood

Here is a minimal caio coroutine:

struct bar {
  int baz;
};


ASYNC
foo(struct caio_task *self, struct bar* state) {
  CAIO_BEGIN(self);

  /* Do something with state */
  state->baz++;

  CAIO_FINALLY(self);
}


int
main() {
  struct bar state = {0};
  return CAIO_FOREVER(foo, &state, 1);
}

Which translates to:

void
foo(struct caio_task *self, struct bar* state) {
  switch (self->current->line) {
    case 0:

      /* Do something with state */
      state->baz++;

    case -1:
  }
  self->status = CAIO_TERMINATED
}

Contribution

Setup build environment

Install Dependencies

Build essentials
sudo apt install cmake cmake-curses-gui build-essential valgrind
io_uring

You may disable the io_uring module via make menu variable CAIO_URING. if not, you need to install these packages to compile the project and access to io_uring manuals.

apt install liburing2 liburing-dev
Linter
pip3 install prettyc

Or, in modern way

python3 -m venv ${HOME}/pyenv
${HOME}/pyenv/bin/pip install prettyc
cp ${HOME}/pyenv/bin/prettyc ${HOME}/bin

Build

mkdir build && cd build
cmake ..
make menu
make all

To delete CMake cache to reset options to thei'r default values:

make fresh
make menu