A hands-on attempt to better understand asynchronous I/O with TCP sockets. Attempts to read (recv) from a TCP socket usually block until data is available. Similarly, attempts to write (send) into a TCP socket usually block until the remaining message fits in the send buffer. There have been several options (non-exhaustive) to get notified when a TCP socket is ready for I/O:
This silly repository explores and utilises libuv which abstracts away the heavy-lifting work of setting up an asynchronous I/O, which varies greatly from one OS to another. The mini projects found in this repository are:
async-echo
(asynchronous echo server), repeats what was received from the clientasync-dwnlder
(asynchronous downloader): it's likewget
but only HTTP/1.1 with TLSasync-relay
(asynchronous relay): it's likesocat
but only TCP
Been coding this entirely on VS Code with the C/C++ extension. The project settings in ./vscode
is not generalised at the moment, so it works only on my Macbook (unless you already have installed libuv
and openssl
, and their header files and libraries are available in /usr/local/include
and /usr/local/lib
). For llhttp
, you'll have to build them manually.
Also, coding this in C/C++ because it helps me a lot with building an understanding of how computer works internally.