|
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:
RADTcpFrame helpers for JSON-defined protocols.Example:
Blocking HTTP request: