|
TEC
A lightweight C++ library enabling safe, efficient execution in multithreaded and concurrent systems.
|
Specialized socket wrapper optimized for sending/receiving NetData protocol messages. More...
#include <tec_socket_nd.hpp>
Public Member Functions | |
| SocketNd (const Socket &sock) | |
| Constructs SocketNd by copying from an existing Socket object. | |
| SocketNd (int _fd, const char *_addr, int _port, char *_buffer, size_t _buffer_size) | |
| Constructs SocketNd with explicit parameters. | |
Public Member Functions inherited from tec::Socket | |
| Socket (int _fd, const char *_addr, int _port) | |
| Construct a Socket wrapper from an accepted or connected fd. | |
| Socket (int _fd, const char *_addr, int _port, char *_buffer, size_t _buffer_size) | |
| Construct a Socket wrapper from an accepted or connected fd. | |
Static Public Member Functions | |
| static Status | send_nd (const NetData *nd, const SocketNd *sock) |
| Sends a complete NetData message (header + payload) over the socket. | |
| static Status | recv_nd (NetData *nd, const SocketNd *sock) |
| Receives one complete NetData message (header + payload) | |
Static Public Member Functions inherited from tec::Socket | |
| static Status | recv (Bytes &data, const Socket *sock, size_t length) |
| Receive data from a socket into a MemFile (Bytes). | |
| static Status | send (const Bytes &data, const Socket *sock) |
| Send the entire contents of a MemFile (Bytes) through a socket. | |
Additional Inherited Members | |
Public Attributes inherited from tec::Socket | |
| int | fd |
| Underlying socket file descriptor. | |
| char | addr [INET6_ADDRSTRLEN] |
| Peer address as a null-terminated string (IPv4 or IPv6). | |
| int | port |
| Peer port number. | |
| char * | buffer |
| Buffer used in send/recv operations. | |
| size_t | buffer_size |
| Size of the buffer. | |
Specialized socket wrapper optimized for sending/receiving NetData protocol messages.
SocketNd extends the basic Socket class with protocol-aware send/receive operations specifically tailored for the NetData message format (header + payload).
Main differences from base Socket class:
|
inline |
Constructs SocketNd with explicit parameters.
| _fd | File descriptor of the socket |
| _addr | Remote peer address (usually string representation of IP) |
| _port | Remote peer port number |
| _buffer | Pointer to external buffer used for receive operations |
| _buffer_size | Size of the provided external buffer (in bytes) |
Receives one complete NetData message (header + payload)
Protocol flow:
Important: Uses MSG_PEEK to avoid reading partial/invalid messages. This helps implement reliable framed message reading over TCP.
| [out] | nd | Pointer to NetData object that will receive the message Must be properly constructed (buffer must be valid) |
| sock | SocketNd instance representing the connection |
Sends a complete NetData message (header + payload) over the socket.
The function performs two write operations:
| nd | Pointer to the NetData message to send |
| sock | SocketNd instance representing the connection |