#include <TCPSocket.h>
Public Member Functions | |
TCPSocket (SOCKET_ADDRESS_FAMILY domain=AF_INET, int32_t type=SOCK_STREAM, int32_t protocol=0) | |
~TCPSocket () override | |
void | setProxy (std::shared_ptr< Proxy > proxy) |
void | close () noexcept override |
virtual bool | accept (SOCKET &clientSocketFD, struct sockaddr_in &clientInfo, std::chrono::milliseconds timeout) |
size_t | socketBytes () override |
bool | readyToRead (std::chrono::milliseconds timeout) override |
size_t | readLine (char *buffer, size_t size, char delimiter='\n') |
size_t | readLine (Buffer &buffer, char delimiter='\n') |
size_t | readLine (String &s, char delimiter='\n') |
size_t | read (uint8_t *buffer, size_t size, sockaddr_in *from=nullptr) override |
size_t | read (Buffer &buffer, size_t size, sockaddr_in *from=nullptr) override |
size_t | read (String &buffer, size_t size, sockaddr_in *from=nullptr) override |
template<typename T > | |
size_t | read (T &value, sockaddr_in *from=nullptr) |
Public Member Functions inherited from sptk::BaseSocket | |
SOCKET | fd () const |
void | open_addr (OpenMode openMode=OpenMode::CREATE, const sockaddr_in *addr=nullptr, std::chrono::milliseconds timeout=std::chrono::milliseconds(0)) |
BaseSocket (SOCKET_ADDRESS_FAMILY domain=AF_INET, int32_t type=SOCK_STREAM, int32_t protocol=0) | |
BaseSocket (const BaseSocket &other)=delete | |
BaseSocket (BaseSocket &&other) noexcept=default | |
virtual | ~BaseSocket () |
Destructor. | |
BaseSocket & | operator= (const BaseSocket &other)=delete |
BaseSocket & | operator= (BaseSocket &&other) noexcept=default |
void | blockingMode (bool blocking) |
virtual size_t | socketBytes () |
virtual void | attach (SOCKET socketHandle, bool accept) |
virtual SOCKET | detach () |
void | host (const Host &host) |
const Host & | host () const |
void | open (const Host &host=Host(), OpenMode openMode=OpenMode::CONNECT, bool blockingMode=true, std::chrono::milliseconds timeoutMS=std::chrono::milliseconds(0)) |
void | open (const struct sockaddr_in &address, OpenMode openMode=OpenMode::CONNECT, bool blockingMode=true, std::chrono::milliseconds timeoutMS=std::chrono::milliseconds(0)) |
void | bind (const char *address, uint32_t portNumber) |
void | listen (uint16_t portNumber=0) |
virtual void | close () noexcept |
bool | active () const |
int32_t | control (int flag, const uint32_t *check) const |
void | setOption (int level, int option, int value) const |
void | getOption (int level, int option, int &value) const |
virtual size_t | recv (uint8_t *buffer, size_t len) |
virtual size_t | send (const uint8_t *buffer, size_t len) |
virtual size_t | read (uint8_t *buffer, size_t size, sockaddr_in *from) |
virtual size_t | read (uint8_t *buffer, size_t size) |
virtual size_t | read (Buffer &buffer, size_t size, sockaddr_in *from) |
size_t | read (Buffer &buffer, size_t size) |
virtual size_t | read (String &buffer, size_t size, sockaddr_in *from) |
size_t | read (String &buffer, size_t size) |
virtual size_t | write (const uint8_t *buffer, size_t size, const sockaddr_in *peer) |
size_t | write (const uint8_t *buffer, size_t size) |
virtual size_t | write (const Buffer &buffer, const sockaddr_in *peer) |
size_t | write (const Buffer &buffer) |
virtual size_t | write (const String &buffer, const sockaddr_in *peer) |
size_t | write (const String &buffer) |
virtual bool | readyToRead (std::chrono::milliseconds timeout) |
virtual bool | readyToWrite (std::chrono::milliseconds timeout) |
bool | blockingMode () const |
Return current blocking mode state. More... | |
Protected Member Functions | |
TCPSocketReader & | reader () |
void | _open (const Host &host, OpenMode openMode, bool blockingMode, std::chrono::milliseconds timeout) override |
void | _open (const struct sockaddr_in &address, OpenMode openMode, bool blockingMode, std::chrono::milliseconds timeout) override |
Proxy * | proxy () |
Protected Member Functions inherited from sptk::BaseSocket | |
void | setSocketFD (SOCKET socket) |
int32_t | domain () const |
int32_t | type () const |
int32_t | protocol () const |
virtual void | _open (const Host &host, OpenMode openMode, bool blockingMode, std::chrono::milliseconds timeoutMS) |
virtual void | _open (const struct sockaddr_in &address, OpenMode openMode, bool blockingMode, std::chrono::milliseconds timeoutMS) |
Additional Inherited Members | |
Public Types inherited from sptk::BaseSocket | |
enum class | OpenMode : uint8_t { CREATE , CONNECT , BIND } |
Generic TCP socket.
Allows to establish a network connection to the host by name and port address
|
explicit |
Constructor
domain | Socket domain type |
type | Socket type |
protocol | Protocol type |
|
override |
Destructor
|
overrideprotectedvirtual |
Opens the client socket connection by host and port
host | The host |
openMode | Socket open mode |
blockingMode | Socket blocking (true) on non-blocking (false) mode |
timeout | Connection timeout. The default is 0 (wait forever) |
Reimplemented from sptk::BaseSocket.
|
overrideprotectedvirtual |
Opens the client socket connection by host and port
address | Address and port |
openMode | Socket open mode |
blockingMode | Socket blocking (true) on non-blocking (false) mode |
timeout | Connection timeout. The default is 0 (wait forever) |
Reimplemented from sptk::BaseSocket.
|
virtual |
In server mode, waits for the incoming connection.
When incoming connection is made, exits returning the connection info
clientSocketFD | Connected client socket FD |
clientInfo | Connected client info |
timeout | Accept operation timeout |
|
overridevirtualnoexcept |
Close socket connection
Reimplemented from sptk::BaseSocket.
Referenced by sptk::TCPServerConnection::terminate(), and sptk::WSProtocol::~WSProtocol().
|
inlineprotected |
Get proxy information
|
overridevirtual |
Reads data from the socket into memory buffer
Buffer bytes() is set to number of bytes read
buffer | The memory buffer |
size | Number of bytes to read from socket |
from | An optional structure for source address |
Reimplemented from sptk::BaseSocket.
|
overridevirtual |
Reads data from the socket into memory buffer
Buffer bytes() is set to number of bytes read
buffer | The memory buffer |
size | Number of bytes to read from socket |
from | An optional structure for source address |
Reimplemented from sptk::BaseSocket.
|
overridevirtual |
Reads data from the socket
buffer | The memory buffer |
size | The number of bytes to read |
from | An optional structure for source address |
Reimplemented from sptk::BaseSocket.
|
inlineprotected |
Access to internal socket reader for derived classes
size_t sptk::TCPSocket::readLine | ( | Buffer & | buffer, |
char | delimiter = '\n' |
||
) |
Reads one line (terminated with CRLF) from the socket into existing memory buffer
The memory buffer is extended automatically to fit the string.
buffer | The destination buffer |
delimiter | Line delimiter |
size_t sptk::TCPSocket::readLine | ( | char * | buffer, |
size_t | size, | ||
char | delimiter = '\n' |
||
) |
Reads one line from the socket into existing memory buffer
The output string should fit the buffer or it will be returned incomplete.
buffer | The destination buffer |
size | The destination buffer size |
delimiter | Line delimiter |
size_t sptk::TCPSocket::readLine | ( | String & | s, |
char | delimiter = '\n' |
||
) |
Reads one line (terminated with CRLF) from the socket into string
s | The destination string |
delimiter | Line delimiter |
|
overridevirtual |
Reports true if socket is ready for reading from it
timeout | Read timeout |
Reimplemented from sptk::BaseSocket.
|
overridevirtual |
Returns number of bytes available in socket
Reimplemented from sptk::BaseSocket.