|
#include <BaseSocket.h>
Public Types | |
| enum class | OpenMode : uint8_t { CREATE , CONNECT , BIND } |
Public Member Functions | |
| 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 | |
| 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) |
Generic socket.
Allows establishing a network connection to the host by name and port address
|
strong |
|
explicit |
Constructor
| domain | Socket domain type |
| type | Socket type |
| protocol | Protocol type |
|
delete |
Deleted copy constructor
| other | Other socket |
|
defaultnoexcept |
Move constructor
| other | Other socket |
|
protectedvirtual |
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 |
| timeoutMS | Connection timeout. The default is 0 (wait forever) |
Reimplemented in sptk::SSLSocket, and sptk::TCPSocket.
|
inlineprotectedvirtual |
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 |
| timeoutMS | Connection timeout, std::chrono::milliseconds. The default is 0 (wait forever) |
Reimplemented in sptk::SSLSocket, and sptk::TCPSocket.
|
inline |
Returns the current socket state
|
virtual |
Attaches socket handle
| socketHandle | Existing socket handle |
Reimplemented in sptk::SSLSocket.
Referenced by sptk::TCPServerConnection::TCPServerConnection().
| void sptk::BaseSocket::bind | ( | const char * | address, |
| uint32_t | portNumber | ||
| ) |
Binds the socket to port
| address | Local IP address, or NULL if any |
| portNumber | The port number, or 0 if any |
|
inline |
Return current blocking mode state.
| void sptk::BaseSocket::blockingMode | ( | bool | blocking | ) |
Set blocking mode
| blocking | Socket blocking mode flag |
|
virtualnoexcept |
Closes the socket connection
Reimplemented in sptk::SSLSocket, and sptk::TCPSocket.
| int32_t sptk::BaseSocket::control | ( | int | flag, |
| const uint32_t * | check | ||
| ) | const |
Calls Unix fcntl() or Windows ioctlsocket()
|
virtual |
Detaches socket handle, setting it to INVALID_SOCKET. Closes the socket without affecting socket handle.
|
inlineprotected |
Get socket domain type
|
inline |
Get socket internal (OS) handle
| void sptk::BaseSocket::getOption | ( | int | level, |
| int | option, | ||
| int & | value | ||
| ) | const |
Gets socket option value
Throws an error if not succeeded
|
inline |
Returns the host
| void sptk::BaseSocket::host | ( | const Host & | host | ) |
| void sptk::BaseSocket::listen | ( | uint16_t | portNumber = 0 | ) |
Opens the server socket connection on port (binds/listens)
| portNumber | The port number |
Referenced by sptk::TCPServerListener::listen().
|
inline |
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 |
| timeoutMS | Connection timeout. The default is 0 (wait forever) |
|
inline |
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 |
| timeoutMS | Connection timeout, std::chrono::milliseconds. The default is 0 (wait forever) |
| void sptk::BaseSocket::open_addr | ( | OpenMode | openMode = OpenMode::CREATE, |
| const sockaddr_in * | addr = nullptr, |
||
| std::chrono::milliseconds | timeout = std::chrono::milliseconds(0) |
||
| ) |
Opens the socket connection by address.
| openMode | SOM_CREATE for UDP socket, SOM_BIND for the server socket, and SOM_CONNECT for the client socket |
| addr | Defines socket address/port information |
| timeout | Connection timeout. If 0 then wait forever. |
|
defaultnoexcept |
Move assignment
| other | Other socket |
|
delete |
Deleted copy assignment
| other | Other socket |
|
inlineprotected |
Get socket protocol
|
inline |
Reads data from the socket into memory buffer
Buffer bytes() is set to number of bytes read
| buffer | The output buffer |
| size | The number of bytes to read |
|
virtual |
Reads data from the socket into memory buffer
Buffer bytes() is set to number of bytes read
| buffer | The output buffer |
| size | The number of bytes to read |
| from | The source address |
Reimplemented in sptk::TCPSocket, and sptk::UDPSocket.
|
inline |
Reads data from the socket into memory buffer
Buffer bytes() is set to number of bytes read
| buffer | The memory buffer |
| size | The number of bytes to read |
|
virtual |
Reads data from the socket into memory buffer
Buffer bytes() is set to number of bytes read
| buffer | The memory buffer |
| size | The number of bytes to read |
| from | The source address |
Reimplemented in sptk::TCPSocket, and sptk::UDPSocket.
|
inlinevirtual |
Reads data from the socket
| buffer | The memory buffer |
| size | The number of bytes to read |
|
virtual |
Reads data from the socket
| buffer | The memory buffer |
| size | The number of bytes to read |
| from | The source address |
Reimplemented in sptk::TCPSocket, and sptk::UDPSocket.
|
virtual |
Reports true if socket is ready for reading from it
| timeout | Read timeout |
Reimplemented in sptk::TCPSocket.
|
virtual |
Reports true if socket is ready for writing to it
| timeout | Write timeout |
|
virtual |
Reads data from the socket in regular or SSL mode
| buffer | The destination buffer |
| len | The destination buffer size |
Reimplemented in sptk::SSLSocket.
|
virtual |
Reads data from the socket in regular or TLS mode
| buffer | The send buffer |
| len | The send data length |
Reimplemented in sptk::SSLSocket.
| void sptk::BaseSocket::setOption | ( | int | level, |
| int | option, | ||
| int | value | ||
| ) | const |
Sets socket option value Throws an error if not succeeded
|
inlineprotected |
Set socket internal (OS) handle
|
virtual |
Returns number of bytes available in socket
Reimplemented in sptk::SSLSocket, and sptk::TCPSocket.
|
inlineprotected |
Get socket type
|
inline |
Writes data to the socket
| buffer | The memory buffer |
|
virtual |
Writes data to the socket
| buffer | The memory buffer |
| peer | The peer information |
|
inline |
Writes data to the socket
| buffer | The memory buffer |
|
virtual |
Writes data to the socket
| buffer | The memory buffer |
| peer | The peer information |
|
inline |
Writes data to the socket
If size is omited then buffer is treated as zero-terminated string
| buffer | The memory buffer |
| size | The memory buffer size |
|
virtual |
Writes data to the socket
If size is omited then buffer is treated as zero-terminated string
| buffer | The memory buffer |
| size | The memory buffer size |
| peer | The peer information |