CES - Coroutines, Epoll and Sockets

Overview

CES - Coroutines Epoll and Sockets

This is a demonstration project for a complex coroutine use case.

Non-production code

Please note, that because of the nature of this project, using this code in production environment is inadvisable. Notably:

  • to clearly demonstrate the asynchronous nature of coroutines, this project is strictly single-threaded
  • there is no effort done to address the starvation issues presented by these interfaces
    • epoll itself makes no starvation guarantees
    • our epoll loop fetches one event at a time, with zero consideration towards wait times when multiple sockets are ready
    • due to the single-threaded nature, a non-cooperative coroutine can block all other progress
  • the main focus of this project is the coroutine machinery and minimal effort was invested into proper handling of sockets
  • compiler support and this code itself is still very fresh
    • this project was developed using TRUNK version of GCC (12)

How does it work

Watch this space for a much longer explanation coming soon. Here are the main points:

Coawaitable coroutines with symetric transfer

The core of the coroutine side of things is the chainable_task class in lib/coroutines.h. This class supports coroutine chaining using co_await.

chainable_task async_operation();

synchronous_task my_coro() {
    auto status = co_await async_operation();
}

The execution will look something like this [my_coro]->[async_operation]->[my_coro]. Note that the important point here is that we are not stacking these coroutines, i.e. my_coro is not calling async_operation and that isn't calling my_coro we are chaining them, thus preventing stack blowup. Since async_operation will likely handoff to epoll to wait for I/O to be ready the actual execution will look like [my_coro]->[async_operation]->[epoll_loop]->[async_operation]->[epoll_loop]->[async_operation]->[my_coro].

You might also like...
The standard Packet Batch application that uses standard Linux sockets (AF_PACKETv3) for packet generation.
The standard Packet Batch application that uses standard Linux sockets (AF_PACKETv3) for packet generation.

Packet Batch (Standard) Description This is the standard Packet Batch application that utilizes AF_PACKETv3 Linux sockets. Due to AF_PACKETv3 Linux so

Simple local P2P chat on UDP sockets
Simple local P2P chat on UDP sockets

Local P2P Chat This is a fully decentralized chat. To communicate, simply run it on computers in a single local network (using one port). All messages

GnuTLS implements the TLS/SSL (Transport Layer Security aka Secure Sockets Layer) protocol

GnuTLS implements the TLS/SSL (Transport Layer Security aka Secure Sockets Layer) protocol

A universal C++20 wrapper for cross-platform sockets.

NetSockets A fast and clean, universal C++20 wrapper for cross-platform sockets. This wrapper uses ENet by lsalzman (https://github.com/lsalzman/enet)

Triton Python and C++ client libraries and example, and client examples for go, java and scala.

Triton Client Libraries and Examples To simplify communication with Triton, the Triton project provides several client libraries and examples of how t

Encapsulates the two protocols of OpenVpn and Ikev2, you only need to enter the server IP and port number to realize the connection and status display, and the specific situation of the connection can be displayed at the same time。

NewVpnCore 封装了OpenVpn和Ikev2两种协议,只需要输入服务器IP和端口号即可实现连接和状态显示,同时可以显示连接的具体情况。 UniteVpn Core(第一版) 1. 模块说明 unitevpn:封装了vpn的操作和统一不同协议信息的模块 ikev2:IKEV2协议的源码 op

PcapPlusPlus is a multiplatform C++ library for capturing, parsing and crafting of network packets. It is designed to be efficient, powerful and easy to use. It provides C++ wrappers for the most popular packet processing engines such as libpcap, WinPcap, DPDK and PF_RING. Like libevent and libuv, libhv provides event-loop with non-blocking IO and timer, but simpler api and richer protocols.
Like libevent and libuv, libhv provides event-loop with non-blocking IO and timer, but simpler api and richer protocols.

中文版 Intro Like libevent, libev, and libuv, libhv provides event-loop with non-blocking IO and timer, but simpler api and richer protocols. Features cr

🌱Light and powerful C++ web framework for highly scalable and resource-efficient web application. It's zero-dependency and easy-portable.
🌱Light and powerful C++ web framework for highly scalable and resource-efficient web application. It's zero-dependency and easy-portable.

Oat++ News Hey, meet the new oatpp version 1.2.5! See the changelog for details. Check out the new oatpp ORM - read more here. Oat++ is a modern Web F

Owner
RNDr. Simon Toth
Educational Content Creator, ex-Software Engineer, ex-Researcher
RNDr. Simon Toth
TCP tunnel powered by epoll

Feature Dual Stack Async DNS Non-blocking IO Zero Copy Build git clone https://github.com/zephyrchien/ZTUN cd ZTUN mkdir build && cd build cmake .. ma

zephyr 15 Jun 3, 2022
TCP tunnel powered by epoll

Feature Dual Stack Async DNS Non-blocking IO Zero

zephyr 15 Jun 3, 2022
Boilerplate of a TCP Server written in C++ using the epoll API

tcp-server-boilerplate Boilerplate of a TCP Server written in C++ using the epoll API. Requirements cmake (if you want to use the provided build.sh sc

Leonardo Folgoni 20 Jan 23, 2022
Built a client-server application using TCP and UDP sockets, in which the clients can subscribe/unsubscribe to various topics.

Built a client-server application using TCP and UDP sockets, in which the clients can subscribe/unsubscribe to various topics.

null 1 Jun 22, 2022
Provide translation, currency conversion, and voting services. First using telnet you create a connection to a TCP socket, then the server connects to 3 UDP sockets hosted on other servers to do tasks.

to run micro servers g++ translator.cpp -o translator ./translator <port 1> g++ voting.cpp -o voting ./voting <port 2> g++ currency_converter.cpp -o c

Jacob Artuso 1 Oct 29, 2021
Wrapper library for the BSD sockets API with a nicer C99 interface

A wrapper library for the BSD sockets API. Why? This library trades the series of getaddrinfo, socket, connect, bind, listen, etc. functions and their

Scott Vokes 132 Jun 19, 2022
A simple tcp tunnel on c using sockets Right now it only supports linux systems

A simple tcp tunnel on c using sockets Right now it only supports linux systems build BY MAKE mkdir build make cd build ./tunnel.o <localport> <rem

notaweeb 8 Sep 20, 2021
Native C++ coroutines for libevent

libevent-async libevent-async is a C++ wrapper around the libevent API. It wraps commonly-used objects in classes and provides coroutine support for m

Martin Michelsen 2 Jan 8, 2022
Creating a server-client application with C sockets.

C-ServerClient Creating a server-client application with C socket. How to use? Clone the project and cd in to the main directory. Open a terminal and

AmirH.Najafizadeh 8 Aug 15, 2022
A special version of Packet Batch that utilizes AF_XDP Linux sockets (this should be faster than the standard version, but not as fast as the DPDK).

Packet Batch (AF_XDP) Description This is a special version of Packet Batch that utilizes AF_XDP sockets instead of AF_PACKETv3 (which is what the sta

Packet Batch 12 Sep 14, 2022