|
netLink C++ 11
|
Socket and stream buffer. More...
#include <Socket.h>
Public Types | |
| enum | IPVersion { IPv4 , IPv6 , ANY } |
| Defines the version of IP. More... | |
| enum | Type { NONE , TCP_CLIENT , TCP_SERVER , TCP_SERVERS_CLIENT , UDP_PEER } |
| Defines the nature of a socket. More... | |
| enum | Status { NOT_CONNECTED , CONNECTING , LISTENING , READY , BUSY } |
| Defines the send status of a socket. More... | |
Public Member Functions | |
| void | initAsTcpClient (const std::string &hostRemote, unsigned portRemote, bool waitUntilConnected=false) |
| void | initAsTcpServer (const std::string &hostLocal, unsigned portLocal, unsigned listenQueue=16) |
| void | initAsUdpPeer (const std::string &hostLocal, unsigned portLocal) |
| IPVersion | getIPVersion () const |
| Returns the IPVersion of the socket. | |
| Type | getType () const |
| Returns the SocketType of the socket. | |
| Status | getStatus () const |
| Returns the SocketStatus of the socket. | |
| std::streamsize | showmanyc () |
| std::streamsize | receive (char_type *buffer, std::streamsize size) |
| std::streamsize | send (const char_type *buffer, std::streamsize size) |
| std::streamsize | redirect (const std::vector< std::shared_ptr< Socket > > &destinations) |
| std::streamsize | getInputBufferSize () |
| Get the size of the input intermediate buffer in bytes. | |
| std::streamsize | getOutputBufferSize () |
| Get the size of the output intermediate buffer in bytes. | |
| void | setInputBufferSize (std::streamsize size) |
| Set the size of the input intermediate buffer in bytes (unread contents are lost) | |
| void | setOutputBufferSize (std::streamsize size) |
| Set the size of the output intermediate buffer in bytes (unwritten contents are lost) | |
| void | setBlockingMode (bool blocking) |
| void | setBroadcast (bool active) |
| void | setMulticastGroup (const std::string &address, bool join) |
| std::shared_ptr< Socket > | accept () |
| void | disconnect () |
| Disconnects the socket, deletes the intermediate buffers and sets the handle to -1. | |
| void | disconnectOnError () |
| Check if there is a problem with this socket and disconnect in case there is one. | |
Public Attributes | |
| std::set< std::shared_ptr< Socket > > | clients |
| Client sockets of a server. | |
| std::string | hostLocal |
| Host string of local. | |
| std::string | hostRemote |
| Host string of remote. | |
| unsigned int | portLocal |
| Port of local. | |
| unsigned int | portRemote |
| Port of remote. | |
Protected Member Functions | |
| void | initSocket (bool blocking) |
| virtual std::shared_ptr< Socket > | SocketFactory () |
| Generates new sockets for client connections of a server. | |
Protected Attributes | |
| IPVersion | ipVersion |
| IP version which is in use. | |
| Type | type |
| Type of the socket. | |
| unsigned int | status |
| Or listen queue size if socket is TCP_SERVER. | |
| int | handle |
| Handle used for the system interface. | |
Friends | |
| class | SocketManager |
Socket and stream buffer.
Defines the send status of a socket.
| Enumerator | |
|---|---|
| NOT_CONNECTED | Socket is not even initialized or disconnected. |
| CONNECTING | Socket is initialized but not connected yet and can not send or receive data. |
| LISTENING | Socket is a server and can neither send nor receive data. |
| READY | Socket is connected, can send and receive data. |
| BUSY | Socket is connected and can not send but receive data (at the moment) |
| std::shared_ptr< Socket > netLink::Socket::accept | ( | ) |
Accepts a TCP connection and returns it
| void netLink::Socket::initAsTcpClient | ( | const std::string & | hostRemote, |
| unsigned | portRemote, | ||
| bool | waitUntilConnected = false |
||
| ) |
Setup socket as TCP client
| hostRemote | The remote host to connect to |
| portRemote | The remote port to connect to |
| waitUntilConnected | Set blocking mode until connected |
| void netLink::Socket::initAsTcpServer | ( | const std::string & | hostLocal, |
| unsigned | portLocal, | ||
| unsigned | listenQueue = 16 |
||
| ) |
Setup socket as TCP server
| hostLocal | The host to be listening to: |
"" or "*" to listen to any incoming data (IPVersion will be choosen by system) "0.0.0.0" to listen to any incoming data (IPVersion will be IPv4) "::0" to listen to any incoming data (IPVersion will be IPv6)
| portLocal | The local port |
| listenQueue | Queue size for outstanding sockets to accept |
| void netLink::Socket::initAsUdpPeer | ( | const std::string & | hostLocal, |
| unsigned | portLocal | ||
| ) |
Setup socket as UDP server
| hostLocal | The host to be listening to: |
"" or "*" to listen to any incoming data (IPVersion will be choosen by system) "0.0.0.0" to listen to any incoming data (IPVersion will be IPv4) "::0" to listen to any incoming data (IPVersion will be IPv6) A multicast address of the multicast group to listen to
| portLocal | The local port |
|
protected |
Initzialize system handle
| blocking | Waits for connection if true |
| std::streamsize netLink::Socket::receive | ( | char_type * | buffer, |
| std::streamsize | size | ||
| ) |
Receives size bytes into buffer
| std::streamsize netLink::Socket::redirect | ( | const std::vector< std::shared_ptr< Socket > > & | destinations | ) |
Redirects received data to all Sockets in destinations
| destinations | A list of destinations to sent the data to |
| std::streamsize netLink::Socket::send | ( | const char_type * | buffer, |
| std::streamsize | size | ||
| ) |
Sends size bytes from buffer
| void netLink::Socket::setBlockingMode | ( | bool | blocking | ) |
Updates the blocking mode of the socket. A socket will be non blocking by default. Try to avoid using blocking mode. Use a SocketManager with listen(sec > 0.0) instead.
| void netLink::Socket::setBroadcast | ( | bool | active | ) |
Enables or disables the broadcasting (only relevant for sending)
| active | If true enables broadcasting else disables broadcasting |
| void netLink::Socket::setMulticastGroup | ( | const std::string & | address, |
| bool | join | ||
| ) |
Joines or leaves a muticast group (only relevant for receiving)
| address | Address of the group |
| join | If true it joines the group else it leaves it |
| std::streamsize netLink::Socket::showmanyc | ( | ) |
Returns only the number of outstanding bytes to be received from the system cache
|
inlineprotectedvirtual |
Generates new sockets for client connections of a server.
Reimplemented in netLink::MsgPackSocket.