|
TEC
A lightweight C++ library enabling safe, efficient execution in multithreaded and concurrent systems.
|
Templated client socket actor for NetData stream handling. More...
#include <tec_socket_client_nd.hpp>
Public Types | |
| using | Params = TParams |
| Type alias for the template parameter TParams. This allows easy reference to the params type within the class. | |
Public Types inherited from tec::SocketClient< TParams > | |
| using | Params = TParams |
| Type alias for the template parameter TParams. This allows easy reference to the params type within the class. | |
Public Member Functions | |
| SocketClientNd (const Params ¶ms) | |
| Constructs a SocketClientNd with the given parameters. | |
| virtual | ~SocketClientNd ()=default |
| Default destructor. | |
| Status | process_request (Request request, Reply reply) override |
| Processes incoming requests, handling NetData types. | |
| Status | request_nd (NetData *nd_in, NetData *nd_out) |
| Convenience method to send a NetData request and receive a response. | |
Public Member Functions inherited from tec::SocketClient< TParams > | |
| SocketClient (const Params ¶ms) | |
| Constructs a SocketClient with the given parameters. | |
| virtual | ~SocketClient () |
| Destructor that ensures the socket is terminated if still open. | |
| void | start (Signal *sig_started, Status *status) override |
| Starts the client by resolving the address and establishing a connection. | |
| void | shutdown (Signal *sig_stopped) override |
| Shuts down the client connection. | |
| Status | request_str (const std::string *str_in, std::string *str_out) |
| Convenience method to send a string request and receive a response. | |
Public Member Functions inherited from tec::Actor | |
| Actor ()=default | |
| Default constructor. | |
| Actor (const Actor &)=delete | |
| Deleted copy constructor. | |
| Actor (Actor &&)=delete | |
| Deleted move constructor. | |
| Actor & | operator= (const Actor &)=delete |
| Deleted copy assignment operator. | |
| Actor & | operator= (Actor &&)=delete |
| Deleted move assignment operator. | |
| virtual | ~Actor ()=default |
| Virtual destructor. | |
| virtual Status | run () |
| Mimics Daemon's behavior. | |
| virtual Status | terminate () |
| Mimics Daemon's behavior. | |
Protected Member Functions | |
| virtual Status | send_nd (NetData *nd) |
| Sends a NetData object over the socket. | |
| virtual Status | recv_nd (NetData *nd) |
| Receives a NetData object from the socket. | |
| virtual Status | compress (NetData *nd) |
| Compresses the NetData using configured parameters. | |
| virtual Status | uncompress (NetData *nd) |
| Uncompresses the NetData using configured parameters. | |
| virtual Status | preprocess (NetData *nd) |
| Preprocesses the NetData before sending (default: compress). | |
| virtual Status | postprocess (NetData *nd) |
| Postprocesses the NetData after receiving (default: uncompress). | |
| virtual Status | send_recv_nd (NetData *nd_in, NetData *nd_out) |
| Sends a NetData request and receives a reply with pre/postprocessing. | |
Protected Member Functions inherited from tec::SocketClient< TParams > | |
| constexpr char * | get_buffer () |
| Returns a pointer to the internal buffer. | |
| constexpr size_t | get_buffer_size () |
| Returns the size of the internal buffer. | |
| virtual Status | set_socket_options (int sockfd) |
| Virtual hook to set custom socket options after connection. | |
| virtual Status | send_string (const SocketCharStreamIn *request) |
| Sends a string over the socket. | |
| virtual Status | recv_string (SocketCharStreamOut *reply) |
| Receives a string from the socket. | |
| virtual Status | send_recv_string (const SocketCharStreamIn *request, SocketCharStreamOut *reply) |
| Sends a request and receives a reply in one operation. | |
Additional Inherited Members | |
Protected Attributes inherited from tec::SocketClient< TParams > | |
| Params | params_ |
| Instance of the parameters used for configuration. This holds settings like address, port, family, socktype, protocol, and buffer_size. | |
| int | sockfd_ |
| Socket file descriptor for the established connection. Initialized to EOF (-1) and set upon successful connection. | |
Templated client socket actor for NetData stream handling.
The SocketClientNd class extends SocketClient to support NetData-based requests and replies. It handles binary data transmission with optional compression, providing overrides for request processing and virtual methods for send/receive and data processing customization.
Key features:
| TParams | The parameter type, which must derive from SocketClientParams (inherited check). |
|
inlineexplicit |
Constructs a SocketClientNd with the given parameters.
Initializes the base SocketClient with the provided params.
| params | The configuration parameters for the client. |
|
virtualdefault |
Default destructor.
No additional cleanup beyond the base class destructor.
|
inlineprotectedvirtual |
Compresses the NetData using configured parameters.
Creates an NdCompress object with params and calls its compress method.
| nd | Pointer to the NetData to compress. |
|
inlineprotectedvirtual |
|
inlineprotectedvirtual |
|
inlineoverridevirtual |
Processes incoming requests, handling NetData types.
This override checks for NetData::StreamIn and StreamOut types, validates them, and delegates to send_recv_nd. Falls back to base class processing for other request types.
| request | The incoming request (std::any). |
| reply | Optional reply object (std::any). |
Reimplemented from tec::SocketClient< TParams >.
|
inlineprotectedvirtual |
Receives a NetData object from the socket.
Creates a SocketNd helper, uses SocketNd::recv_nd to receive the data, and rewinds the NetData.
| nd | Pointer to the NetData to populate with received data. |
|
inline |
|
inlineprotectedvirtual |
Sends a NetData object over the socket.
Creates a SocketNd helper and uses SocketNd::send_nd to transmit the data.
| nd | Pointer to the NetData to send. |
|
inlineprotectedvirtual |
Sends a NetData request and receives a reply with pre/postprocessing.
Applies preprocessing to input, sends, receives, applies postprocessing to output. Terminates the connection if any step fails.
| nd_in | Pointer to the input NetData to send. |
| nd_out | Pointer to the output NetData to receive. |
|
inlineprotectedvirtual |
Uncompresses the NetData using configured parameters.
Creates an NdCompress object with params and calls its uncompress method.
| nd | Pointer to the NetData to uncompress. |