SocketStreams v1.11.1
|
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 |
Base network class.
|
protected |
web::Network::Network | ( | std::string_view | ip, |
std::string_view | port, | ||
T | timeout = 30s ) |
Client side constructor.
ip | Remote address to connect to |
port | Remote port to connect to |
timeout | Timeout for receive and send calls |
WebException |
web::Network::Network | ( | SOCKET | clientSocket, |
T | timeout = 30s ) |
Server side contructor.
clientSocket |
|
virtualdefault |
void web::Network::addReceiveBuffer | ( | std::string_view | buffer | ) |
Add additional data that uses before getting bytes from network.
buffer |
SOCKET web::Network::getClientSocket | ( | ) | const |
clientSocket getter
bool web::Network::isDataAvailable | ( | int * | availableBytes = nullptr | ) | const |
Check if Network contains data.
|
virtual |
Errors logging, default implementation uses clog.
message | Log message |
data | Additional data |
int web::Network::receiveBytes | ( | DataT * | data, |
int | size, | ||
bool & | endOfStream, | ||
int | flags = 0 ) |
DataT |
data | |
size | |
endOfStream | |
flags |
WebException |
|
protectedvirtual |
|
virtual |
Receive data through network.
data | Actual data with some useful methods. Called with std::vector<char> or std::string |
endOfStream | Is connection closed |
|
virtual |
Receive data through network.
data | Actual data. Called from read method |
endOfStream | Is connection closed |
int web::Network::sendBytes | ( | const DataT * | data, |
int | size, | ||
bool & | endOfStream, | ||
int | flags = 0 ) |
Send raw bytes through network.
DataT |
data | |
size | |
endOfStream | |
flags |
WebException |
|
protectedvirtual |
|
virtual |
Send data through network.
data | Actual data with some useful methods. Called with std::vector<char> or std::string |
endOfStream | Is connection closed |
|
virtual |
Send raw data through network.
data | Actual data. Called from write method |
endOfStream | Is connection closed |
|
protected |
|
protectedvirtual |
|
protected |
|
protected |