12 #include <RADCore/RADCore.h>
77 bool bind(uint16_t port,
const std::string& address =
"0.0.0.0");
79 bool sendTo(
const std::string& address, uint16_t port,
const std::vector<uint8_t>& payload);
89 std::shared_ptr<Impl> pImpl_;
107 bool listen(uint16_t port,
const std::string& address =
"0.0.0.0");
109 bool sendTo(
const std::string& address, uint16_t port,
const std::vector<uint8_t>& payload);
150 ssize_t
readData(
void* buffer,
size_t maxBytes)
override;
152 ssize_t
writeData(
const void* data,
size_t size)
override;
161 std::shared_ptr<Impl> pImpl_;
179 bool listen(uint16_t port,
const std::string& address =
"0.0.0.0",
int backlog = 128);
189 std::shared_ptr<Impl> pImpl_;
251 static std::optional<RADHttpResponse>
get(
const std::string& url, std::string* error =
nullptr);
253 static std::optional<RADHttpResponse>
post(
const std::string& url,
const std::string& body,
254 const std::map<std::string, std::string>& headers = {}, std::string* error =
nullptr);
294 bool decodeFrames(std::vector<uint8_t>& buffer, std::vector<RADTcpFrame>& frames,
295 uint32_t maxPayloadBytes = 16 * 1024 * 1024, std::string* error =
nullptr);
323 bool sendFrame(uint32_t messageId,
const std::vector<uint8_t>& payload);
344 void attach(std::shared_ptr<RADTcpSocket> socket);
347 std::shared_ptr<RADTcpSocket> socket_;
352 std::vector<uint8_t> buffer_;
353 uint32_t maxPayloadBytes_ = 16 * 1024 * 1024;
394 uint32_t maxPayloadBytes_ = 16 * 1024 * 1024;
#define RAD_EVENT(Name, Signature)
Declares a typed RADCore event; example: RAD_EVENT(done, (int)).
Definition: RADCore.h:97
#define RADEvents
Marks a public event declaration block in RADObject-derived classes.
Definition: RADCore.h:75
#define RADHandlers
Marks a public handler declaration block in RADObject-derived classes.
Definition: RADCore.h:77
Explicit event connection handle.
Definition: RADCore.h:935
RADCore task event loop with locked and low-latency scheduling strategies.
Definition: RADCore.h:988
Abstract byte-oriented IO device similar to QIODevice.
Definition: RADCore.h:1286
JSON value supporting null, bool, number, string, array, and object.
Definition: RADCore.h:541
Base class for event receivers, senders, and thread-affinity aware objects.
Definition: RADCore.h:963
Lightweight URL parser for scheme, host, port, path, query, and fragment.
Definition: RADCore.h:487
Small libcurl-backed HTTP client with sync and event-loop async APIs.
Definition: RADNet.h:235
static std::optional< RADHttpResponse > get(const RADCore::RADUrl &url, std::string *error=nullptr)
Performs a blocking GET request for url.
static std::optional< RADHttpResponse > get(const std::string &url, std::string *error=nullptr)
Parses url and performs a blocking GET request.
RADCore::Event< void(std::string) > errorOccurred
Raised by async requests when request setup or transfer fails.
Definition: RADNet.h:241
void requestAsync(const RADHttpRequest &request)
Starts an async request and emits finished/errorOccurred.
void getAsync(const std::string &url)
Parses url and starts an async GET request.
static std::optional< RADHttpResponse > post(const std::string &url, const std::string &body, const std::map< std::string, std::string > &headers={}, std::string *error=nullptr)
Performs a blocking POST request.
RADHttpClient(RADCore::EventLoop &loop)
Creates an async client that posts results to loop.
RADCore::Event< void(RADNet::RADHttpResponse) > finished
Raised by async requests when a response completes.
Definition: RADNet.h:239
static RADDnsResult resolve(const std::string &host)
Resolves host to address strings.
static std::optional< RADHttpResponse > request(const RADHttpRequest &request, std::string *error=nullptr)
Performs a blocking HTTP request.
void getAsync(const RADCore::RADUrl &url)
Starts an async GET request for url and emits finished/errorOccurred.
Framed protocol TCP client.
Definition: RADNet.h:357
bool connectUsingConfig(const RADProtocolEndpointConfig &config)
Connects using runtime config.
RADProtocolClient(RADCore::EventLoop &loop)
Creates a client.
Framed protocol TCP server.
Definition: RADNet.h:366
RADCore::Event< void(std::string) > errorOccurred
Raised when listening or accepting fails.
Definition: RADNet.h:372
uint16_t localPort() const
Returns bound local port.
void close()
Stops listening.
bool listenUsingConfig(const RADProtocolEndpointConfig &config)
Starts listening using config.
RADProtocolServer(RADCore::EventLoop &loop)
Creates a server.
void handleNewConnection(std::shared_ptr< RADNet::RADTcpSocket > socket)
Internal TCP accept handler.
void handleError(std::string message)
Internal error handler.
RADCore::Event< void(std::shared_ptr< RADNet::RADProtocolSocket >) > newConnection
Raised when a framed client is accepted.
Definition: RADNet.h:370
Protocol socket wrapper that frames RADTcpSocket byte streams.
Definition: RADNet.h:301
void handleConnected()
Internal connected handler.
RADCore::Event< void(RADNet::RADTcpFrame) > frameReceived
Raised when a full frame is received.
Definition: RADNet.h:305
bool sendFrame(const RADTcpFrame &frame)
Sends a frame.
void setMaxPayloadBytes(uint32_t maxPayloadBytes)
Sets maximum accepted payload size.
void handleError(std::string message)
Internal TCP error handler.
RADCore::Event< void(std::string) > errorOccurred
Raised on socket or framing errors.
Definition: RADNet.h:307
bool connectToHost(const std::string &host, uint16_t port)
Connects to host:port.
RADCore::Event< void() > connected
Raised when connected.
Definition: RADNet.h:309
bool sendFrame(uint32_t messageId, const std::vector< uint8_t > &payload)
Sends a frame.
void handleDisconnected()
Internal disconnected handler.
bool isOpen() const
Returns true when the wrapped socket is open.
RADProtocolSocket(RADCore::EventLoop &loop, std::shared_ptr< RADTcpSocket > socket)
Wraps an accepted TCP socket.
void handleReadyRead()
Internal TCP readyRead handler.
~RADProtocolSocket() override
Closes the socket.
RADCore::Event< void() > disconnected
Raised when disconnected.
Definition: RADNet.h:311
RADProtocolSocket(RADCore::EventLoop &loop)
Creates an unconnected protocol socket.
void close()
Closes the wrapped socket.
Process-wide epoll reactor used by RADNet sockets.
Definition: RADNet.h:47
static RADSocketReactor & instance()
Returns the singleton reactor instance.
RADSocketReactor & operator=(const RADSocketReactor &)=delete
Reactor ownership is singleton-only.
RADSocketReactor(const RADSocketReactor &)=delete
Reactor ownership is singleton-only.
Non-blocking TCP server that emits accepted sockets.
Definition: RADNet.h:165
bool listen(uint16_t port, const std::string &address="0.0.0.0", int backlog=128)
Starts listening on address:port with backlog.
~RADTcpServer()
Stops listening if needed.
RADCore::Event< void(std::shared_ptr< RADNet::RADTcpSocket >) > newConnection
Raised when a new client connection is accepted.
Definition: RADNet.h:169
bool isListening() const
Returns true when the server socket is listening.
uint16_t localPort() const
Returns the bound local port, or 0 when unavailable.
RADTcpServer(RADCore::EventLoop &loop)
Creates a server using loop for event delivery.
void close()
Stops listening and closes the server descriptor.
RADCore::Event< void(std::string) > errorOccurred
Raised when listen, accept, or reactor setup fails.
Definition: RADNet.h:171
Non-blocking TCP socket that also implements RADCore::RADIODevice.
Definition: RADNet.h:128
ssize_t readData(void *buffer, size_t maxBytes) override
Reads up to maxBytes from the socket into buffer.
RADCore::Event< void() > connected
Raised when a connection is established.
Definition: RADNet.h:132
RADCore::Event< void() > disconnected
Raised when the peer disconnects or the socket closes.
Definition: RADNet.h:134
ssize_t writeData(const void *data, size_t size) override
Writes size bytes from data to the socket.
bool isOpen() const override
Returns true when the descriptor is open.
bool connectToHost(const std::string &address, uint16_t port)
Starts a non-blocking connection to address:port.
~RADTcpSocket()
Closes the socket if needed.
void close() override
Closes the TCP descriptor and updates state.
RADTcpSocket(RADCore::EventLoop &loop)
Creates an unconnected TCP socket using loop for events.
bool open(RADCore::OpenMode mode) override
Opens the IODevice facet; networking is established with connectToHost().
SocketState state() const
Returns the current TCP socket state.
Convenience UDP server built on RADUdpSocket.
Definition: RADNet.h:93
RADUdpServer(RADCore::EventLoop &loop)
Creates a UDP server whose events are posted to loop.
bool sendTo(const std::string &address, uint16_t port, const std::vector< uint8_t > &payload)
Sends payload from the server socket to address:port.
void handleError(std::string message)
Internal handler that forwards socket errors.
RADCore::Event< void(std::string) > errorOccurred
Re-emits socket errors from the internal socket.
Definition: RADNet.h:99
void handleDatagram(RADNet::Datagram datagram)
Internal handler that forwards datagrams from the owned socket.
void close()
Stops listening and closes the socket.
RADCore::Event< void(RADNet::Datagram) > datagramReceived
Re-emits datagrams received by the internal socket.
Definition: RADNet.h:97
~RADUdpServer()
Closes the internal socket.
bool listen(uint16_t port, const std::string &address="0.0.0.0")
Starts listening for UDP datagrams on address:port.
uint16_t localPort() const
Returns the bound local port, or 0 when unavailable.
Event-loop integrated UDP socket.
Definition: RADNet.h:63
bool sendTo(const std::string &address, uint16_t port, const std::vector< uint8_t > &payload)
Sends payload to address:port.
~RADUdpSocket()
Closes the socket and unregisters it from the reactor.
void close()
Closes the UDP file descriptor if open.
RADCore::Event< void(RADNet::Datagram) > datagramReceived
Raised on the owning RADCore event loop when a datagram arrives.
Definition: RADNet.h:67
bool bind(uint16_t port, const std::string &address="0.0.0.0")
Binds to address:port. Use port 0 to request an ephemeral port.
bool isOpen() const
Returns true when the socket currently owns an open descriptor.
RADUdpSocket(RADCore::EventLoop &loop)
Creates a UDP socket whose events are posted to loop.
RADCore::Event< void(std::string) > errorOccurred
Raised when bind, send, receive, or reactor setup fails.
Definition: RADNet.h:69
uint16_t localPort() const
Returns the bound local port, or 0 when unavailable.
OpenMode
Open mode flags shared by RADIODevice, RADFile, and RADBuffer.
Definition: RADCore.h:325
bool decodeFrames(std::vector< uint8_t > &buffer, std::vector< RADTcpFrame > &frames, uint32_t maxPayloadBytes=16 *1024 *1024, std::string *error=nullptr)
Attempts to decode all complete frames from buffer, removing consumed bytes.
std::vector< uint8_t > encodeFrame(const RADTcpFrame &frame)
Encodes a RADTcpFrame into wire bytes.
RADProtocolEndpointConfig endpointConfigFromJson(const RADCore::RADJsonValue &value, const RADProtocolEndpointConfig &defaults={})
Loads endpoint config from a JSON object.
SocketState
Common socket state used by RADNet TCP sockets.
Definition: RADNet.h:33
@ Closed
Socket was closed.
@ Unconnected
Socket has not connected or listened.
@ Connected
Socket is connected and can transfer data.
@ Listening
Server socket is listening.
@ Connecting
Non-blocking connect is in progress.
UDP datagram payload plus sender/target endpoint metadata.
Definition: RADNet.h:23
std::vector< uint8_t > payload
Raw datagram bytes.
Definition: RADNet.h:25
std::string address
IPv4/IPv6 address text.
Definition: RADNet.h:27
uint16_t port
UDP port in host byte order.
Definition: RADNet.h:29
DNS lookup result.
Definition: RADNet.h:227
std::vector< std::string > addresses
Resolved address strings.
Definition: RADNet.h:229
std::string error
Error text when resolution fails.
Definition: RADNet.h:231
HTTP request options for RADHttpClient::request().
Definition: RADNet.h:205
std::string url
Target URL.
Definition: RADNet.h:209
std::map< std::string, std::string > headers
Request headers.
Definition: RADNet.h:211
long timeoutMs
Total request timeout in milliseconds.
Definition: RADNet.h:215
long maxRedirects
Maximum redirects when followRedirects is true.
Definition: RADNet.h:221
std::string method
HTTP method such as GET, POST, PUT, DELETE.
Definition: RADNet.h:207
long connectTimeoutMs
Connection timeout in milliseconds.
Definition: RADNet.h:217
bool followRedirects
Follow redirects.
Definition: RADNet.h:219
bool verifyTls
Verify TLS peers for HTTPS requests.
Definition: RADNet.h:223
std::string body
Request body bytes/text.
Definition: RADNet.h:213
HTTP response data returned by RADHttpClient.
Definition: RADNet.h:193
std::map< std::string, std::string > headers
Response headers keyed by header name.
Definition: RADNet.h:199
std::string reasonPhrase
HTTP reason phrase, when provided by the server.
Definition: RADNet.h:197
std::string body
Response body as text bytes.
Definition: RADNet.h:201
int statusCode
Numeric HTTP status code.
Definition: RADNet.h:195
Runtime endpoint configuration loaded from JSON.
Definition: RADNet.h:278
int backlog
Server backlog.
Definition: RADNet.h:284
int connectTimeoutMs
Connect timeout in milliseconds.
Definition: RADNet.h:286
uint32_t maxPayloadBytes
Maximum accepted payload bytes.
Definition: RADNet.h:288
std::string address
Server bind address or client host.
Definition: RADNet.h:280
uint16_t port
TCP port.
Definition: RADNet.h:282
Binary TCP protocol frame: u32 messageId, u32 payloadSize, payload.
Definition: RADNet.h:270
uint32_t messageId
Message identifier in host byte order.
Definition: RADNet.h:272
std::vector< uint8_t > payload
Raw payload bytes.
Definition: RADNet.h:274