Skip to content

eerimoq/async

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

buildstatus codecov nala

πŸ”€ Async

Asynchronous framework in C for systems where low memory usage is important.

Features

  • 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

Examples

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.

Runtimes

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.

Default

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);
}

Native

The native runtime implements all runtime features.

Typical usage:

async_init(&async);
async_set_runtime(&async, async_runtime_create());
...
async_run_forever(&async);

Design

Input

First *_input(self_p) is called to signal that data is available. Then read data with *_read(self_p, buf_p, size).

Output

Write data with *_write(self_p, buf_p, size).

Unit testing

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
...

About

πŸ”€ Asynchronous framework in C.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages