RADLib
RADical C++ application framework

RADNet provides event-loop integrated networking on Linux: an epoll reactor, UDP and TCP sockets, server classes, a small HTTP client, and a framed binary protocol layer. Socket events are delivered on a RADCore::EventLoop.

RADSocketReactor is a process-wide singleton epoll reactor, obtained via RADSocketReactor::instance(), that drives readiness for all RADNet sockets.

For UDP, RADUdpSocket binds with bind(), sends with sendTo(), and raises datagramReceived(RADNet::Datagram) and errorOccurred(std::string). A Datagram carries the payload, sender address, and port. RADUdpServer is a convenience wrapper that re-emits those events after listen().

For TCP, RADTcpSocket implements RADCore::RADIODevice, connects with connectToHost(), exposes readData()/writeData(), reports its SocketState (Unconnected, Connecting, Connected, Listening, Closed), and raises connected()/disconnected(). RADTcpServer listens and emits newConnection(std::shared_ptr<RADTcpSocket>) for each accepted client.

RADHttpClient is a small libcurl-backed client with both blocking and async APIs. Static request(), get(), and post() return an optional RADHttpResponse (with statusCode, reasonPhrase, headers, and body), driven by a RADHttpRequest. Instances constructed with an EventLoop offer requestAsync()/getAsync(), emitting finished(RADHttpResponse) and errorOccurred(std::string). resolve() returns a RADDnsResult.

For custom binary protocols, RADTcpFrame (messageId + payload) is encoded by encodeFrame() and parsed by decodeFrames(). RADProtocolSocket frames a RADTcpSocket byte stream and raises frameReceived(RADTcpFrame), with RADProtocolClient and RADProtocolServer driven by a JSON-loaded RADProtocolEndpointConfig (via endpointConfigFromJson()).

Core features:

  • Event-loop driven UDP and TCP sockets with an epoll reactor.
  • TCP/UDP server and client primitives.
  • Binary RADTcpFrame helpers for JSON-defined protocols.
  • Sync and async HTTP client helpers plus DNS resolution.
  • Epoll-based readiness handling on Linux.

Example:

RADNet::RADTcpServer server(loop);
server.newConnection.connect([](std::shared_ptr<RADNet::RADTcpSocket> client) {
client->writeData("HELLO\n", 6);
});
server.listen(9000);
loop.run();
RADCore task event loop with locked and low-latency scheduling strategies.
Definition: RADCore.h:988
Non-blocking TCP server that emits accepted sockets.
Definition: RADNet.h:165

Blocking HTTP request:

std::string error;
auto resp = RADNet::RADHttpClient::get("https://radcomp.tech/status", &error);
if (resp && resp->statusCode == 200) {
// Use resp->body.
}
static std::optional< RADHttpResponse > get(const RADCore::RADUrl &url, std::string *error=nullptr)
Performs a blocking GET request for url.