SocketStreams v1.11.1
Loading...
Searching...
No Matches
web::Network Class Reference

Base network class. More...

#include <Network.h>

Public Member Functions

template<Timeout T = std::chrono::seconds>
 Network (std::string_view ip, std::string_view port, T timeout=30s)
 Client side constructor.
 
template<Timeout T = std::chrono::seconds>
 Network (SOCKET clientSocket, T timeout=30s)
 Server side contructor.
 
bool isDataAvailable (int *availableBytes=nullptr) const
 Check if Network contains data.
 
virtual int sendData (const utility::ContainerWrapper &data, bool &endOfStream, int flags=0)
 Send data through network.
 
virtual int sendRawData (const char *data, int size, bool &endOfStream, int flags=0)
 Send raw data through network.
 
virtual int receiveData (utility::ContainerWrapper &data, bool &endOfStream, int flags=0)
 Receive data through network.
 
virtual int receiveRawData (char *data, int size, bool &endOfStream, int flags=0)
 Receive data through network.
 
virtual void log (const std::string &message, std::any &&data="")
 Errors logging, default implementation uses clog.
 
void addReceiveBuffer (std::string_view buffer)
 Add additional data that uses before getting bytes from network.
 
SOCKET getClientSocket () const
 clientSocket getter
 
template<typename DataT >
int sendBytes (const DataT *data, int size, bool &endOfStream, int flags=0)
 Send raw bytes through network.
 
template<typename DataT >
int receiveBytes (DataT *data, int size, bool &endOfStream, int flags=0)
 
virtual ~Network ()=default
 

Protected Member Functions

virtual int sendBytesImplementation (const char *data, int size, int flags=0)
 
virtual int receiveBytesImplementation (char *data, int size, int flags=0)
 
virtual void throwException (int line, std::string_view file) const
 
void setTimeout (int64_t timeout)
 
 Network (std::string_view ip, std::string_view port, int64_t timeout)
 

Protected Attributes

std::shared_ptr< SOCKET > handle
 
std::queue< std::string_view > buffers
 

Detailed Description

Base network class.

Constructor & Destructor Documentation

◆ Network() [1/3]

web::Network::Network ( std::string_view ip,
std::string_view port,
int64_t timeout )
protected

◆ Network() [2/3]

template<Timeout T>
web::Network::Network ( std::string_view ip,
std::string_view port,
T timeout = 30s )

Client side constructor.

Parameters
ipRemote address to connect to
portRemote port to connect to
timeoutTimeout for receive and send calls
Exceptions
WebException

◆ Network() [3/3]

template<Timeout T>
web::Network::Network ( SOCKET clientSocket,
T timeout = 30s )

Server side contructor.

Parameters
clientSocket

◆ ~Network()

virtual web::Network::~Network ( )
virtualdefault

Member Function Documentation

◆ addReceiveBuffer()

void web::Network::addReceiveBuffer ( std::string_view buffer)

Add additional data that uses before getting bytes from network.

Parameters
buffer

◆ getClientSocket()

SOCKET web::Network::getClientSocket ( ) const

clientSocket getter

Returns
clientSocket

◆ isDataAvailable()

bool web::Network::isDataAvailable ( int * availableBytes = nullptr) const

Check if Network contains data.

Returns

◆ log()

void web::Network::log ( const std::string & message,
std::any && data = "" )
virtual

Errors logging, default implementation uses clog.

Parameters
messageLog message
dataAdditional data

◆ receiveBytes()

template<typename DataT >
int web::Network::receiveBytes ( DataT * data,
int size,
bool & endOfStream,
int flags = 0 )
Template Parameters
DataT
Parameters
data
size
endOfStream
flags
Returns
Total number of received bytes
Exceptions
WebException

◆ receiveBytesImplementation()

int web::Network::receiveBytesImplementation ( char * data,
int size,
int flags = 0 )
protectedvirtual

◆ receiveData()

int web::Network::receiveData ( utility::ContainerWrapper & data,
bool & endOfStream,
int flags = 0 )
virtual

Receive data through network.

Parameters
dataActual data with some useful methods. Called with std::vector<char> or std::string
endOfStreamIs connection closed
Returns
Total number of bytes receive

◆ receiveRawData()

int web::Network::receiveRawData ( char * data,
int size,
bool & endOfStream,
int flags = 0 )
virtual

Receive data through network.

Parameters
dataActual data. Called from read method
endOfStreamIs connection closed
Returns
Total number of bytes receive

◆ sendBytes()

template<typename DataT >
int web::Network::sendBytes ( const DataT * data,
int size,
bool & endOfStream,
int flags = 0 )

Send raw bytes through network.

Template Parameters
DataT
Parameters
data
size
endOfStream
flags
Returns
Total number of sended bytes
Exceptions
WebException

◆ sendBytesImplementation()

int web::Network::sendBytesImplementation ( const char * data,
int size,
int flags = 0 )
protectedvirtual

◆ sendData()

int web::Network::sendData ( const utility::ContainerWrapper & data,
bool & endOfStream,
int flags = 0 )
virtual

Send data through network.

Parameters
dataActual data with some useful methods. Called with std::vector<char> or std::string
endOfStreamIs connection closed
Returns
Total number of bytes send

◆ sendRawData()

int web::Network::sendRawData ( const char * data,
int size,
bool & endOfStream,
int flags = 0 )
virtual

Send raw data through network.

Parameters
dataActual data. Called from write method
endOfStreamIs connection closed
Returns
Total number bytes send

◆ setTimeout()

void web::Network::setTimeout ( int64_t timeout)
protected

◆ throwException()

void web::Network::throwException ( int line,
std::string_view file ) const
protectedvirtual

Member Data Documentation

◆ buffers

std::queue<std::string_view> web::Network::buffers
protected

◆ handle

std::shared_ptr<SOCKET> web::Network::handle
protected

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