29#ifndef _POSIX_C_SOURCE
31#define _POSIX_C_SOURCE 200809L
34#include <netinet/in.h>
35#include <sys/socket.h>
80 SocketNd(
int _fd,
const char* _addr,
int _port,
char* _buffer,
size_t _buffer_size)
81 :
Socket(_fd, _addr, _port, _buffer, _buffer_size)
104 auto errmsg =
format(
"{}:{} Peer closed the connection.",
110 auto errmsg =
format(
"{}:{} NetData::Header write error.",
118 if (nd->
size() > 0) {
163 auto errmsg =
format(
"{}:{} Peer closed the connection.",
169 auto errmsg =
format(
"{}:{} Socket read error.",
175 auto errmsg =
format(
"{}:{} NetData::Header read error.",
182 auto errmsg =
format(
"{}:{} NetData::Header is invalid.",
196 if (nd->
size() > 0) {
Lightweight binary serialization container optimized for network communication.
Definition tec_net_data.hpp:51
size_t size() const
Returns current logical size of the message (according to header)
Definition tec_net_data.hpp:127
void rewind()
Resets read position to the beginning of the buffer.
Definition tec_net_data.hpp:119
Header header
Global message header.
Definition tec_net_data.hpp:54
const Bytes & bytes() const
Returns const reference to internal byte buffer.
Definition tec_net_data.hpp:85
#define TEC_ENTER(name)
Logs an entry message for a named context (e.g., function).
Definition tec_trace.hpp:211
#define TEC_TRACE(...)
Logs a formatted trace message.
Definition tec_trace.hpp:222
@ Invalid
Invalid data or state.
@ NetErr
Network-related error.
@ System
System-level error.
Specialized socket wrapper optimized for sending/receiving NetData protocol messages.
Definition tec_socket_nd.hpp:63
static Status send_nd(const NetData *nd, const SocketNd *sock)
Sends a complete NetData message (header + payload) over the socket.
Definition tec_socket_nd.hpp:96
static Status recv_nd(NetData *nd, const SocketNd *sock)
Receives one complete NetData message (header + payload)
Definition tec_socket_nd.hpp:148
SocketNd(const Socket &sock)
Constructs SocketNd by copying from an existing Socket object.
Definition tec_socket_nd.hpp:68
SocketNd(int _fd, const char *_addr, int _port, char *_buffer, size_t _buffer_size)
Constructs SocketNd with explicit parameters.
Definition tec_socket_nd.hpp:80
Lightweight wrapper around a connected socket file descriptor.
Definition tec_socket.hpp:272
static Status recv(Bytes &data, const Socket *sock, size_t length)
Receive data from a socket into a MemFile (Bytes).
Definition tec_socket.hpp:329
static Status send(const Bytes &data, const Socket *sock)
Send the entire contents of a MemFile (Bytes) through a socket.
Definition tec_socket.hpp:395
char * buffer
Buffer used in send/recv operations.
Definition tec_socket.hpp:276
int port
Peer port number.
Definition tec_socket.hpp:275
size_t buffer_size
Size of the buffer.
Definition tec_socket.hpp:277
int fd
Underlying socket file descriptor.
Definition tec_socket.hpp:273
char addr[INET6_ADDRSTRLEN]
Peer address as a null-terminated string (IPv4 or IPv6).
Definition tec_socket.hpp:274
Common definitions and utilities for the tec namespace.
Lightweight binary serialization optimized for network communication.
std::string format(const T &arg)
Formats a single argument into a string.
Definition tec_print.hpp:171
Generic BSD socket parameters and helpers.
Defines error handling types and utilities for the tec namespace.
Provides a thread-safe tracing utility for debugging in the tec namespace.