Asynchronous framework in C for systems where low memory usage is important.
- Delayed (asynchronous) function calls.
- Timers.
- An MQTT client (only QoS 0 is supported).
- A simple shell.
- TCP client and server.
- Secure communication with SSL/TLS.
Project homepage: https://github.com/eerimoq/async
Releases: https://github.com/eerimoq/async/releases
The hello world example, printing 'Hello world!' periodically.
#include <stdio.h>
#include "async.h"
static void on_timeout()
{
printf("Hello world!\n");
}
int main()
{
struct async_t async;
struct async_timer_t timer;
async_init(&async);
async_set_runtime(&async, async_runtime_create());
async_timer_init(&timer, on_timeout, NULL, 0, 1000, &async);
async_timer_start(&timer);
async_run_forever(&async);
return (0);
}
There are more examples in the examples folder.
A runtime implements zero or more of the following features:
- Timer handling.
- Networking (TCP).
- Call functions in the worker pool.
- Call functions from any thread.
The default runtime does not implement any runtime features. It's designed for minimal dependencies and easy integration in any application.
Typical usage:
async_init(&async);
...
while (true) {
epoll_wait(...);
...
if (timeout) {
async_tick(&async);
}
async_process(&async);
}
The native runtime implements all runtime features.
Typical usage:
async_init(&async);
async_set_runtime(&async, async_runtime_create());
...
async_run_forever(&async);
First *_input(self_p)
is called to signal that data is
available. Then read data with *_read(self_p, buf_p, size)
.
Write data with *_write(self_p, buf_p, size)
.
Source the development environment setup script.
$ source setup.sh
Execute all unit tests.
$ make -s -j4 test
...
Execute tests matching given pattern.
$ make -s -j4 ARGS=core_timer test
...