|
STTNet 0.7.0
|
A lightweight, high-performance C++17 networking framework for Linux. It is built on epoll and the Reactor model and provides HTTP, TCP, UDP, WebSocket, TLS, WorkerPool, logging, and common networking utilities.
An older build recorded about 65,000 requests per second with 2–3 ms average latency on a 4-core/4GB device. This is a historical measurement, not a performance guarantee. Benchmark a Release build on the target environment.
The commands below use Ubuntu / Debian. Each comment explains what the next command does.
# 1. Download the STTNet source code
git clone https://github.com/StephenTaam/STTNet.git
cd STTNet
# 2. Install the compiler, CMake, JsonCpp, and OpenSSL development packages
sudo apt update
sudo apt install -y build-essential cmake pkg-config libjsoncpp-dev libssl-dev
# 3. Configure a Release build and enable the runnable examples
cmake -S . -B build \
-DCMAKE_BUILD_TYPE=Release \
-DSTTNET_BUILD_EXAMPLE=ON \
-DSTTNET_BUILD_TESTS=OFF
# 4. Build STTNet and all examples
cmake --build build -j
# 5. Start the minimal HTTP example
./build/examples/sttnet_http_hello
# 6. Open another terminal and verify the route; expected output: pong
curl http://127.0.0.1:8080/ping
It creates a server, registers the /ping route, starts listening, and shuts down normally after Ctrl-C or SIGTERM.
#include <sttnet.h>
#include <iostream>
int main()
{
using namespace stt::network;
using stt::system::ServerSetting;
// Block termination signals before Reactor or Worker threads are created.
// The main thread waits for SIGINT / SIGTERM synchronously later.
if(!ServerSetting::blockTerminationSignals())
return 1;
// HttpServer owns the listener, connections, Reactor, and WorkerPool.
HttpServer server;
// Register /ping. Return 1 after a successful send.
// Return -2 when sending fails and the connection should close.
server.setFunction("/ping",
[](HttpServerFDHandler &client, HttpRequestInformation &) {
return client.sendText("pong") ? 1 : -2;
});
// Listen on TCP port 8080.
if(!server.startListen(8080))
return 2;
std::cout << "http://127.0.0.1:8080/ping
";
// Wait here until Ctrl-C or SIGTERM is received.
ServerSetting::waitForTerminationSignal();
// Perform graceful cleanup from normal thread context.
return server.close() ? 0 : 3;
}
Every demo includes complete source code, build steps, test commands, and expected results.
The Programming Guide provides structured explanations and complete examples. The API Reference provides signatures and member details for individual classes and functions.