Cross platform C++ wrapper for posix sockets.
More...
#include <socket.hpp>
|
| int | accept (bool loopBack=false) |
| | Accept connection to socket.
|
| |
| bool | bind (int port, bool loopBack=false, bool reuseaddr=true) |
| | Bind an address to socket.
|
| |
| bool | bindToInterface (int port, const string &interfacename, bool reuseaddr) |
| | Binds a socket to specific port and interface.
|
| |
| int | close () |
| |
| bool | connect (const string &server, int port) |
| | Connect socket to server.
|
| |
| bool | connect (sockaddr address) |
| | Connect socket to server.
|
| |
| bool | create (int af, int type, int protocol) |
| | Create socket.
|
| |
| int | getFD () const |
| | Returns file descriptor of this socket.
|
| |
| string | getIPAddress () |
| | Retrieves ip address of this socket.
|
| |
| int | getPort () |
| | Retrieves port of this socket.
|
| |
| string | getRemoteIPAddress () const |
| | Retrieves remote ip address of this socket.
|
| |
| sockaddr * | getSockAddr () |
| | Retrieves socket address of this socket.
|
| |
| bool | isConnected () const |
| | Checks whether the socket is connected.
|
| |
| int | listen (int maxConnections) |
| | Listen for connections on this socket.
|
| |
| int | read (vector< char > &data) |
| | Read data from socket.
|
| |
| int | readOne (char &data) |
| | Read one byte of data from socket.
|
| |
| void | setBlocking (bool blocking) |
| | Sets socket blocking mode.
|
| |
| int | shutdown (bool read, bool write) |
| |
| | Socket (int fd=-1) |
| | Constructor.
|
| |
| int | write (const vector< char > &data) |
| | Write data to socket.
|
| |
| | ~Socket () |
| | Destructor.
|
| |
|
| static unsigned long | bytesAvailable (int fd) |
| | Non-blocking check of how much data is available for reading from descriptor.
|
| |
| static enum AddressType | determineAddressType (const string &candidate) |
| | Determines a type of given address.
|
| |
| static vector< string > | getBindableAddresses (const string &interfacename, size_t mask=(Proto_IPV4|Proto_IPV6)) |
| | Returns a list of addresses that belong into specific interface.
|
| |
| static bool | getIPAndPort (sockaddr_storage *sender, string &ip, string &port) |
| | Translate sockaddr into ip address and port number.
|
| |
| static bool | looksLikeIPV6Address (const string &address) |
| | Checks whether given address looks like a IPv6 address.
|
| |
| static int | read (int fd, vector< char > &data) |
| | Read all data from file descriptor to data buffer.
|
| |
| static int | readOne (int fd, char &data) |
| | Read one byte from a file descriptor to a character.
|
| |
|
| bool | isDatagram () const |
| | Checks is the socket datagram type.
|
| |
Cross platform C++ wrapper for posix sockets.
◆ AddressType
| Enumerator |
|---|
| AddressType_IPV4 | Specific address is recognized to be IPv4.
|
| AddressType_IPV6 | Specific address is recognized to be IPv6.
|
| AddressType_InterfaceName | Address is likely a interface name.
|
◆ ProtocolMask
| Enumerator |
|---|
| Proto_IPV4 | |
| Proto_IPV6 | |
◆ Socket()
| kanzi::connect::Socket::Socket |
( |
int | fd = -1 | ) |
|
Constructor.
- Parameters
-
| fd | File descriptor of a socket, or -1 for closed socket. |
◆ ~Socket()
| kanzi::connect::Socket::~Socket |
( |
| ) |
|
◆ accept()
| int kanzi::connect::Socket::accept |
( |
bool | loopBack = false | ) |
|
Accept connection to socket.
- Parameters
-
| loopBack | Accept only connections from this device. |
- Returns
- File descriptor of the accepted socket or -1 for error.
◆ bind()
| bool kanzi::connect::Socket::bind |
( |
int | port, |
|
|
bool | loopBack = false, |
|
|
bool | reuseaddr = true ) |
Bind an address to socket.
- Parameters
-
| port | Port to bind. |
| loopBack | Bind to address of this device. |
| reuseaddr | if true then SO_REUSEADDR is opted to socket. |
- Returns
- True if operation was successful, otherwise false.
◆ bindToInterface()
| bool kanzi::connect::Socket::bindToInterface |
( |
int | port, |
|
|
const string & | interfacename, |
|
|
bool | reuseaddr ) |
Binds a socket to specific port and interface.
- Parameters
-
| port | port number where to bind |
| interfacename | either name or ip address of the interface to bind to. |
| reuseaddr | if true then SO_REUSEADDR is opted to socket. |
- Returns
- true if bound successfully, false if some errors were met.
◆ bytesAvailable()
| static unsigned long kanzi::connect::Socket::bytesAvailable |
( |
int | fd | ) |
|
|
static |
Non-blocking check of how much data is available for reading from descriptor.
- Parameters
-
- Returns
- Amount of data available.
◆ close()
| int kanzi::connect::Socket::close |
( |
| ) |
|
- Returns
- If successful, returns 0. Otherwise returns -1 as error.
◆ connect() [1/2]
| bool kanzi::connect::Socket::connect |
( |
const string & | server, |
|
|
int | port ) |
Connect socket to server.
- Parameters
-
- Returns
- True if socket was successfully connected.
◆ connect() [2/2]
| bool kanzi::connect::Socket::connect |
( |
sockaddr | address | ) |
|
Connect socket to server.
- Parameters
-
| address | Address of the server. |
- Returns
- True if socket was successfully connected.
◆ create()
| bool kanzi::connect::Socket::create |
( |
int | af, |
|
|
int | type, |
|
|
int | protocol ) |
Create socket.
- Parameters
-
| af | Address family. |
| type | Socket type. |
| protocol | Protocol type. |
- Returns
- True if socket was successfully created.
◆ determineAddressType()
| static enum AddressType kanzi::connect::Socket::determineAddressType |
( |
const string & | candidate | ) |
|
|
static |
Determines a type of given address.
- Parameters
-
| candidate | the candidate to check. |
- Returns
- enumeration value. if empty string is passed then its recognized as interface.
◆ getBindableAddresses()
| static vector< string > kanzi::connect::Socket::getBindableAddresses |
( |
const string & | interfacename, |
|
|
size_t | mask = (Proto_IPV4|Proto_IPV6) ) |
|
static |
Returns a list of addresses that belong into specific interface.
- Parameters
-
| interfacename | The name of the interface for which to seach. |
| mask | The address types to return. |
- Returns
- vector of addresses bound to specific interface.
◆ getFD()
| int kanzi::connect::Socket::getFD |
( |
| ) |
const |
Returns file descriptor of this socket.
- Returns
- File descriptor of this socket.
◆ getIPAddress()
| string kanzi::connect::Socket::getIPAddress |
( |
| ) |
|
Retrieves ip address of this socket.
- Returns
- Ip address of this socket as string.
◆ getIPAndPort()
| static bool kanzi::connect::Socket::getIPAndPort |
( |
sockaddr_storage * | sender, |
|
|
string & | ip, |
|
|
string & | port ) |
|
static |
Translate sockaddr into ip address and port number.
- Parameters
-
| sender | the sender address |
| ip | the ip address |
| port | the port number. |
- Returns
- true if retrieval succeeded, false on error.
◆ getPort()
| int kanzi::connect::Socket::getPort |
( |
| ) |
|
Retrieves port of this socket.
- Returns
- port of this socket.
◆ getRemoteIPAddress()
| string kanzi::connect::Socket::getRemoteIPAddress |
( |
| ) |
const |
Retrieves remote ip address of this socket.
- Returns
- Ip address of the remote side of socket as string.
◆ getSockAddr()
| sockaddr * kanzi::connect::Socket::getSockAddr |
( |
| ) |
|
Retrieves socket address of this socket.
- Returns
- Socket address of this socket.
◆ isConnected()
| bool kanzi::connect::Socket::isConnected |
( |
| ) |
const |
Checks whether the socket is connected.
- Returns
- true if socket still holds a functional connection.
◆ isDatagram()
| bool kanzi::connect::Socket::isDatagram |
( |
| ) |
const |
|
protected |
Checks is the socket datagram type.
- Returns
- true if datagram type of socket
◆ listen()
| int kanzi::connect::Socket::listen |
( |
int | maxConnections | ) |
|
Listen for connections on this socket.
- Parameters
-
| maxConnections | Maximum amount of connections. |
- Returns
- If successful, returns 0. Otherwise returns -1 as error.
◆ looksLikeIPV6Address()
| static bool kanzi::connect::Socket::looksLikeIPV6Address |
( |
const string & | address | ) |
|
|
static |
Checks whether given address looks like a IPv6 address.
- Parameters
-
| address | the address to examine |
- Returns
- true if looks like ipv6 address.
◆ read() [1/2]
| static int kanzi::connect::Socket::read |
( |
int | fd, |
|
|
vector< char > & | data ) |
|
static |
Read all data from file descriptor to data buffer.
- Parameters
-
| fd | File descriptor. |
| data | Output data. |
- Returns
- Amount of data read, zero for EOF or -1 for error.
◆ read() [2/2]
| int kanzi::connect::Socket::read |
( |
vector< char > & | data | ) |
|
Read data from socket.
- Parameters
-
- Returns
- Amount of data read, zero for EOF or -1 for error.
◆ readOne() [1/2]
| int kanzi::connect::Socket::readOne |
( |
char & | data | ) |
|
Read one byte of data from socket.
- Parameters
-
- Returns
- Amount of data read, zero for EOF or -1 for error.
◆ readOne() [2/2]
| static int kanzi::connect::Socket::readOne |
( |
int | fd, |
|
|
char & | data ) |
|
static |
Read one byte from a file descriptor to a character.
- Parameters
-
| fd | File descriptor. |
| data | byte where to read. |
- Returns
- Amount of data read, zero for EOF or -1 for error.
◆ setBlocking()
| void kanzi::connect::Socket::setBlocking |
( |
bool | blocking | ) |
|
Sets socket blocking mode.
- Parameters
-
| blocking | If true, sets socket to blocking mode. |
◆ shutdown()
| int kanzi::connect::Socket::shutdown |
( |
bool | read, |
|
|
bool | write ) |
- Parameters
-
| read | if true, receptions will be disabled. |
| write | if true, transmissions will be disabled. |
- Returns
- If successful, returns 0. Otherwise returns -1 as error.
◆ write()
| int kanzi::connect::Socket::write |
( |
const vector< char > & | data | ) |
|
Write data to socket.
- Parameters
-
- Returns
- Amount of data written, zero for EOF or -1 for error.
The documentation for this class was generated from the following file:
- connect/connection/socket.hpp