TEC
A lightweight C++ library enabling safe, efficient execution in multithreaded and concurrent systems.
Loading...
Searching...
No Matches
tec::SocketClientNd< TParams > Class Template Reference

Templated client socket actor for NetData stream handling. More...

#include <tec_socket_client_nd.hpp>

Inheritance diagram for tec::SocketClientNd< TParams >:
tec::SocketClient< TParams > tec::Actor

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 &params)
 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 &params)
 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.
 
Actoroperator= (const Actor &)=delete
 Deleted copy assignment operator.
 
Actoroperator= (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 charget_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.
 

Detailed Description

template<typename TParams>
class tec::SocketClientNd< TParams >

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:

  • Processes NetData::StreamIn and StreamOut for structured data exchange.
  • Supports compression/uncompression based on parameters.
  • Delegates to base class for non-NetData requests.
  • Integrates with SocketNd for low-level NetData socket operations.
Template Parameters
TParamsThe parameter type, which must derive from SocketClientParams (inherited check).
See also
SocketClient
NetData
SocketNd
NdCompress

Constructor & Destructor Documentation

◆ SocketClientNd()

template<typename TParams >
tec::SocketClientNd< TParams >::SocketClientNd ( const Params params)
inlineexplicit

Constructs a SocketClientNd with the given parameters.

Initializes the base SocketClient with the provided params.

Parameters
paramsThe configuration parameters for the client.

◆ ~SocketClientNd()

template<typename TParams >
virtual tec::SocketClientNd< TParams >::~SocketClientNd ( )
virtualdefault

Default destructor.

No additional cleanup beyond the base class destructor.

Member Function Documentation

◆ compress()

template<typename TParams >
virtual Status tec::SocketClientNd< TParams >::compress ( NetData nd)
inlineprotectedvirtual

Compresses the NetData using configured parameters.

Creates an NdCompress object with params and calls its compress method.

Parameters
ndPointer to the NetData to compress.
Returns
Status indicating success or error.

◆ postprocess()

template<typename TParams >
virtual Status tec::SocketClientNd< TParams >::postprocess ( NetData nd)
inlineprotectedvirtual

Postprocesses the NetData after receiving (default: uncompress).

Calls uncompress as the default postprocessing step.

Parameters
ndPointer to the NetData to postprocess.
Returns
Status indicating success or error.

◆ preprocess()

template<typename TParams >
virtual Status tec::SocketClientNd< TParams >::preprocess ( NetData nd)
inlineprotectedvirtual

Preprocesses the NetData before sending (default: compress).

Calls compress as the default preprocessing step.

Parameters
ndPointer to the NetData to preprocess.
Returns
Status indicating success or error.

◆ process_request()

template<typename TParams >
Status tec::SocketClientNd< TParams >::process_request ( Request  request,
Reply  reply 
)
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.

Parameters
requestThe incoming request (std::any).
replyOptional reply object (std::any).
Returns
Status indicating success or error (e.g., Invalid if pointers are null).

Reimplemented from tec::SocketClient< TParams >.

◆ recv_nd()

template<typename TParams >
virtual Status tec::SocketClientNd< TParams >::recv_nd ( NetData nd)
inlineprotectedvirtual

Receives a NetData object from the socket.

Creates a SocketNd helper, uses SocketNd::recv_nd to receive the data, and rewinds the NetData.

Parameters
ndPointer to the NetData to populate with received data.
Returns
Status indicating success or error.

◆ request_nd()

template<typename TParams >
Status tec::SocketClientNd< TParams >::request_nd ( NetData nd_in,
NetData nd_out 
)
inline

Convenience method to send a NetData request and receive a response.

Directly calls send_recv_nd to handle the input and output NetData objects.

Parameters
nd_inPointer to the input NetData to send.
nd_outPointer to the output NetData to receive.
Returns
Status indicating success or error.

◆ send_nd()

template<typename TParams >
virtual Status tec::SocketClientNd< TParams >::send_nd ( NetData nd)
inlineprotectedvirtual

Sends a NetData object over the socket.

Creates a SocketNd helper and uses SocketNd::send_nd to transmit the data.

Parameters
ndPointer to the NetData to send.
Returns
Status indicating success or error.

◆ send_recv_nd()

template<typename TParams >
virtual Status tec::SocketClientNd< TParams >::send_recv_nd ( NetData nd_in,
NetData nd_out 
)
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.

Parameters
nd_inPointer to the input NetData to send.
nd_outPointer to the output NetData to receive.
Returns
Status indicating overall success or error.

◆ uncompress()

template<typename TParams >
virtual Status tec::SocketClientNd< TParams >::uncompress ( NetData nd)
inlineprotectedvirtual

Uncompresses the NetData using configured parameters.

Creates an NdCompress object with params and calls its uncompress method.

Parameters
ndPointer to the NetData to uncompress.
Returns
Status indicating success or error.

The documentation for this class was generated from the following file: