Systems and network programming in C++
You wrap POSIX interfaces safely in RAII classes and write concurrent network services and tools with sockets and Asio.
Level 301 · 18 lessons · 15 practice labs
Lessons
System interfaces
- A RAII wrapper for file descriptors
- Starting a process from C++ and reading its output
- Signals and clean shutdown
- Reading a memory-mapped file through span
- Short task: a class that runs commands without a shell
Sockets
- A socket class: movable but not copyable
- A TCP client and server
- Buffers and message framing
- Sending and receiving notifications over UDP
- An event loop with poll
- Short task: a key-value server
Asynchronous I/O with Asio
- Asio basics: io_context and timers
- An asynchronous TCP server
- Readable async code with Asio and coroutines
- TLS with Asio and certificate verification
- A simple HTTP client and timeouts
- Short task: a tool that probes the lab targets concurrently
Capstone
- Capstone: an asynchronous TCP relay with limits and logging
Practice labs
- Writing a move-only wrapper for a file descriptor: Write a class that closes the descriptor in its destructor, cannot be copied and does not close twice after a move.
- Scanning a memory-mapped file through span: Map a file of fixed-size records with mmap, walk it through std::span and unmap with RAII, rejecting a partial final record.
- Shutting down on a signal while releasing resources: Fix a service that makes unsafe calls in its signal handler with an atomic flag checked in the main loop and show by test that destructors run.
- Running a program with fork and exec and capturing output: Run a program from an argument vector with fork and exec, collect its standard output into a string through a pipe and return the exit code.
- Ending a hung command when time runs out: Add a timeout to a command runner that terminates the child when it expires, leaves no zombie and verifiably closes the descriptors.
- Moving a system() call to an argument vector: Move a backup class that splices a file name into a command string and runs it with system to the shell-free runner and pass regression tests with special-character names.
- An echo client with a socket class: Complete a movable socket class with connect, send and receive functions and pass the tests against a local echo server.
- Framing length-prefixed messages: Write a framer that extracts complete messages from bytes arriving in pieces and refuses the connection on a message over the maximum size.
- A multi-client key-value server with poll: Write a server that handles GET and SET in a single-threaded poll loop where a slow client does not stall others and partial writes are completed.
- A heartbeat with an Asio timer: Write an asynchronous heartbeat with steady_timer that increments a counter every second and stops itself after five beats.
- Managing a session object's lifetime correctly: Fix an async server that crashes because the session is destroyed before its callback runs using shared_from_this and pass the ASan test.
- Probing lab targets concurrently with coroutines: Connect concurrently to allow-listed lab targets with Asio coroutines, put a timeout on each connection and produce a reachability table.
- Reading the HTTP status line: Write a client that sends a simple GET request to the lab web target and returns the status code and Content-Length header.
- Adding time limits to an HTTP client: Add connect, read and total time limits to a client that waits forever on an unresponsive server and report each as a distinct error.
- Turning on certificate verification in a TLS client: Fix an Asio TLS client that disabled verification so it trusts the lab's internal CA and checks the host name, and show it refuses a server with the wrong name.
About this course
You wrap POSIX interfaces safely in RAII classes and write concurrent network services and tools with sockets and Asio.
What you will learn
- System interfaces
- Sockets
- Asynchronous I/O with Asio
- Capstone
Prerequisites
You should be comfortable with the level 101 and 201 topics of the same path.
Lab environment
Lessons run in your own Kali Linux terminal in the browser, connected to a private lab network. Nothing to install.
Frequently asked questions
- Is this course right for my level?
- The course is at level 301; it assumes you know the topics of the lower-level courses.
- Is there anything to install?
- No. Every lesson runs in your own lab environment that opens in the browser.
- How do lessons work?
- Each lesson has 8 to 10 steps and a short quiz. Early steps show the command to type, later steps give less help; if two attempts fail, the solution opens.
- Can I try it for free?
- Yes. The first three lessons of every course are free.