Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/matt-42/moustique
C++14 high performance non-blocking network IO (based on epoll + boost.context)
https://github.com/matt-42/moustique
Last synced: 5 days ago
JSON representation
C++14 high performance non-blocking network IO (based on epoll + boost.context)
- Host: GitHub
- URL: https://github.com/matt-42/moustique
- Owner: matt-42
- License: mit
- Created: 2018-04-01T00:38:34.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-07-24T15:29:27.000Z (over 6 years ago)
- Last Synced: 2024-08-02T01:25:38.218Z (3 months ago)
- Language: C++
- Homepage:
- Size: 21.5 KB
- Stars: 134
- Watchers: 11
- Forks: 10
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Moustique
Moustique is a tiny C++14 library (~180 LOC) providing an easy to use
interface to non-blocking network IO on linux.# Implementation details
Moustique relies on linux epoll for non blocking IO and on
boost::context for resuming/suspending handlers.
The source code is rather small, fell free to dive into moustique.hh if you want
to know more about the implementation.No dynamic allocations, no buffering is done by moustique internally. The read/write
callbacks are simply forwarding your buffer to the read/write syscalls.
The only overhead is the context switching of boost::context [1].Dependencies: boost::context (-lboost_context), C++14.
Licence: MIT## TCP echo example
```c++
#include "moustique.hh"int main()
{
moustique_listen(1234, // Port number
SOCK_STREAM, // TCP socket
2, // number of threads
[] (int fd, auto read, auto write) {printf("new connection: %i\n", fd);
char buf[1024];
int received;
while (received = read(buf, sizeof(buf))) // Suspend until new bytes
// are available for reading.if (!write(buf, received)) // Suspend until the socket is ready for a write.
break;printf("end of connection: %i\n", fd);
}
);
}
```## Compilation
```
g++/clang++ echo.cc -lboost_context -lpthread -DNDEBUG -O3
```[1] https://www.boost.org/doc/libs/1_66_0/libs/context/doc/html/context/performance.html