An open API service indexing awesome lists of open source software.

https://github.com/pylover/meloop

Monadic event loop for C using epoll.
https://github.com/pylover/meloop

c epoll epoll-tcp-server io monads

Last synced: 7 months ago
JSON representation

Monadic event loop for C using epoll.

Awesome Lists containing this project

README

          

# meloop (Monadic Event Loop)

## Features

- Async/non-blocking IO
- IO: read, write, wait(using epoll)
- TCP client: connectA
- TCP server: listenA, acceptA
- SSL/TLS: tlsA, tlsreadA, tlswriteA
- Timer using linux timerfd: timeropenA, timersleepA
- Random using /dev/urandom: randopenA, randreadA, randencA

## Build

### Dependencies

```bash
sudo apt install build-essential pkgconf openssl
```

```bash
make clean
make all
make clean all
```

## Examples

Take a look at `examples` directory.

```bash
cd examples

make echoshell
./echoshell

make echoserver
./echoserver

make echoclient
./echoclient

make tlsclient
./tlsclient

make random
./random

make state
./state
```

## Running Tests

```bash
cd tests
make clean runall
```

## Profiling

### gprof

Run desired example, signal it with `CTRL+C`, then:

```bash
cd examples

make echoserver
./echoserver

gprof echoserver
```

### valgrind

```bash
sudo apt install valgrind

cd examples
make clean all
make valgrind
```

Or

```bash
valgrind --tool=memcheck --leak-check=full ./echoserver
valgrind --tool=massif ./echoserver
```

Example output

```bash
==56319== Memcheck, a memory error detector
==56319== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==56319== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==56319== Command: ./echoserver
==56319==
127.0.0.1:42658 Connected.
127.0.0.1:42658 Disconnected.
^C
SIGINT detected: 2
Terminating TCP Server
==56319==
==56319== HEAP SUMMARY:
==56319== in use at exit: 0 bytes in 0 blocks
==56319== total heap usage: 14 allocs, 14 frees, 2,384 bytes allocated
==56319==
==56319== All heap blocks were freed -- no leaks are possible
==56319==
==56319== For lists of detected and suppressed errors, rerun with: -s
==56319== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
```

## Coding Convention

- C Macros: UPPER_CASE
- Monads/Arrows: fooA
- All others: lowercase with `meloop_` prefix.