|
BCNP 3.2.1
Batched Command Network Protocol
|
TCP transport adapter for BCNP over POSIX sockets. More...
#include <tcp_posix.h>
Public Member Functions | |
| TcpPosixAdapter (uint16_t listenPort, const char *targetIp=nullptr, uint16_t targetPort=0) | |
| Construct TCP adapter. | |
| ~TcpPosixAdapter () override | |
| Destructor. Closes all open sockets. | |
| bool | SendBytes (const uint8_t *data, std::size_t length) override |
| Sends bytes through the TCP connection. | |
| std::size_t | ReceiveChunk (uint8_t *buffer, std::size_t maxLength) override |
| Receives bytes from the TCP connection. | |
| bool | IsValid () const |
| bool | IsConnected () const |
| bool | IsHandshakeComplete () const |
| bool | SendHandshake () |
| Sends the V3 protocol handshake to the peer. | |
| uint32_t | GetRemoteSchemaHash () const |
| void | SetExpectedSchemaHash (uint32_t hash) |
| Override expected schema hash (for testing with custom schemas) | |
Public Member Functions inherited from bcnp::DuplexAdapter | |
| ~DuplexAdapter () override=default | |
Public Member Functions inherited from bcnp::ByteWriter | |
| virtual | ~ByteWriter ()=default |
Public Member Functions inherited from bcnp::ByteStream | |
| virtual | ~ByteStream ()=default |
TCP transport adapter for BCNP over POSIX sockets.
Supports both server and client modes with automatic reconnection, non-blocking I/O, and V3 schema handshake validation.
Server mode: Listens on a port, accepts one client at a time. Client mode: Connects to a remote server, auto-reconnects on disconnect.
Definition at line 22 of file tcp_posix.h.
|
explicit |
Construct TCP adapter.
Constructs a TCP adapter in server or client mode.
| listenPort | Port to listen on (server mode) or 0 (client mode) |
| targetIp | Remote IP address (client mode only) |
| targetPort | Remote port (client mode only) |
| listenPort | Port to bind for server mode. Pass 0 for client mode. |
| targetIp | Target IP address for client mode (ignored in server mode). |
| targetPort | Target port for client mode (ignored in server mode). |
Server mode (listenPort > 0): Creates a listening socket on the specified port Accepts one client at a time Auto-disconnects zombie clients after timeout
Client mode (listenPort == 0, targetIp/targetPort set): Initiates connect to the target Automatically reconnects on disconnect
Definition at line 54 of file tcp_posix.cpp.
|
override |
Destructor. Closes all open sockets.
Definition at line 100 of file tcp_posix.cpp.
|
inline |
Definition at line 41 of file tcp_posix.h.
|
inline |
Definition at line 37 of file tcp_posix.h.
|
inline |
Definition at line 39 of file tcp_posix.h.
|
inline |
Definition at line 36 of file tcp_posix.h.
|
overridevirtual |
Receives bytes from the TCP connection.
Performs non-blocking receive. Handles V3 handshake protocol transparently - handshake bytes are consumed internally and not returned to the caller.
| buffer | Destination buffer for received data. |
| maxLength | Maximum bytes to receive. |
Implements bcnp::ByteStream.
Definition at line 351 of file tcp_posix.cpp.
|
overridevirtual |
Sends bytes through the TCP connection.
Data is buffered and sent asynchronously to prevent blocking on slow connections. Implements congestion control by rejecting new packets when buffer exceeds 50% capacity.
| data | Pointer to byte buffer to send. |
| length | Number of bytes to send. |
Implements bcnp::ByteWriter.
Definition at line 316 of file tcp_posix.cpp.
| bool bcnp::TcpPosixAdapter::SendHandshake | ( | ) |
Sends the V3 protocol handshake to the peer.
The handshake contains the protocol magic bytes and schema hash. Peers must have matching schema hashes for full interoperability.
Definition at line 561 of file tcp_posix.cpp.
|
inline |
Override expected schema hash (for testing with custom schemas)
Definition at line 44 of file tcp_posix.h.