Zappy GUI
C++ graphic client: renderer, camera, network
Loading...
Searching...
No Matches
TcpSocket Class Reference

Simple TCP socket wrapper. More...

#include <TcpSocket.hpp>

+ Collaboration diagram for TcpSocket:

Public Member Functions

 ~TcpSocket ()
 Wraps close().
 
void connect (const std::string &host, int port)
 Connects to a remote host.
 
void send (const std::string &data)
 Sends data through the socket.
 
std::optional< std::string > recvLine ()
 Receives a line of text from the socket.
 
bool poll (int timeout_ms)
 Polls the socket for incoming data.
 

Private Attributes

int _fd = -1
 
std::string _recvBuffer
 

Detailed Description

Simple TCP socket wrapper.

Definition at line 22 of file TcpSocket.hpp.

Constructor & Destructor Documentation

◆ ~TcpSocket()

TcpSocket::~TcpSocket ( )

Wraps close().

Definition at line 11 of file TcpSocket.cpp.

References _fd.

Member Function Documentation

◆ connect()

void TcpSocket::connect ( const std::string &  host,
int  port 
)

Connects to a remote host.

Parameters
hostThe hostname or IP address to connect to.
portThe port to connect to.
Exceptions
TcpExceptionon failure.

Definition at line 16 of file TcpSocket.cpp.

References _fd, and connect().

Referenced by App::_connectWithRetry(), and connect().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ poll()

bool TcpSocket::poll ( int  timeout_ms)

Polls the socket for incoming data.

Parameters
timeout_msThe timeout in milliseconds.
Returns
true if data is ready to be read, false if timeout occurred.
Exceptions
TcpExceptionon failure.

Definition at line 139 of file TcpSocket.cpp.

References _fd, and _recvBuffer.

Referenced by App::pollAndEnqueue().

+ Here is the caller graph for this function:

◆ recvLine()

std::optional< std::string > TcpSocket::recvLine ( )

Receives a line of text from the socket.

Returns
A complete line of text, or std::nullopt if the connection is closed.
Exceptions
TcpExceptionon failure.

Definition at line 95 of file TcpSocket.cpp.

References _fd, and _recvBuffer.

Referenced by App::pollAndEnqueue().

+ Here is the caller graph for this function:

◆ send()

void TcpSocket::send ( const std::string &  data)

Sends data through the socket.

Parameters
dataThe data to send.
Exceptions
TcpExceptionon failure.

Definition at line 83 of file TcpSocket.cpp.

References _fd, and send().

Referenced by App::_connectWithRetry(), App::_trySendStu(), and send().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ _fd

int TcpSocket::_fd = -1
private

Definition at line 60 of file TcpSocket.hpp.

Referenced by connect(), poll(), recvLine(), send(), and ~TcpSocket().

◆ _recvBuffer

std::string TcpSocket::_recvBuffer
private

Definition at line 61 of file TcpSocket.hpp.

Referenced by poll(), and recvLine().


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