|
Ocean
|
This class is the base class for all connection oriented servers. More...
#include <ConnectionOrientedServer.h>
Data Structures | |
| class | ConnectionObject |
| Definition of a connection object holding the socket and remote address and port. More... | |
Public Types | |
| using | ConnectionId = unsigned int |
| Definition of a connection id. | |
| using | ConnectionRequestCallback = Callback< bool, const Address4 &, const Port &, const ConnectionId > |
| Definition of a connection request callback function. | |
| using | DisconnectCallback = Callback< void, const ConnectionId > |
| Definition of a disconnect callback function. | |
| using | ReceiveCallback = Callback< void, const ConnectionId, const void *, const size_t > |
| Definition of a receive callback function. | |
Public Types inherited from Ocean::Network::Socket | |
| enum | SocketResult { SR_SUCCEEDED = 0 , SR_FAILED , SR_BUSY , SR_NOT_CONNECTED } |
| Definition of individual result values. More... | |
| using | SocketId = SOCKET |
| Definition of a socket id. | |
| using | SocketId = int |
| Definition of a socket id. | |
| using | Buffer = std::vector< uint8_t > |
| Definition of a vector holding 8 bit values. | |
Public Member Functions | |
| virtual SocketResult | send (const ConnectionId connectionId, const void *data, const size_t size) |
| Sends data over a specified connection. | |
| virtual SocketResult | send (const ConnectionId connectionId, const std::string &message) |
| Sends a message over a specified connection. | |
| virtual bool | disconnect (const ConnectionId connectionId)=0 |
| Disconnects a specified connection. | |
| virtual size_t | connections () const |
| Returns the number of active connections of this server. | |
| bool | connectionProperties (const ConnectionId connectionId, Address4 &address, Port &port) |
| Returns the remote address and port of a specified connection. | |
| void | setConnectionRequestCallback (const ConnectionRequestCallback &callback) |
| Sets the connection request callback function. | |
| void | setDisconnectCallback (const DisconnectCallback &callback) |
| Sets the disconnect callback function. | |
| void | setReceiveCallback (const ReceiveCallback &callback) |
| Sets the receive callback function. | |
Public Member Functions inherited from Ocean::Network::Server | |
| ~Server () override | |
| Destructs a server object. | |
| virtual bool | start () |
| Starts the server. | |
| virtual bool | stop () |
| Stops the server. | |
Public Member Functions inherited from Ocean::Network::Socket | |
| virtual | ~Socket () |
| Destructs a socket object. | |
| SocketId | id () const |
| Returns the socket id. | |
| Address4 | address () const |
| Returns the own address of this socket. | |
| Port | port () const |
| Returns the own port of this socket. | |
| virtual bool | setAddress (const Address4 &address) |
| Sets the own address of this socket. | |
| virtual bool | setPort (const Port &port) |
| Sets the own port of this socket. | |
| operator bool () const | |
| Returns whether this socket is valid. | |
Static Public Member Functions | |
| static constexpr ConnectionId | invalidConnectionId () |
| Returns an invalid connection id. | |
Static Public Member Functions inherited from Ocean::Network::Socket | |
| static constexpr SocketId | invalidSocketId () |
| Returns an invalid socket id. | |
| static bool | setBlockingMode (const SocketId socketId, const bool blocking) |
| Sets the blocking mode of a socket. | |
Protected Types | |
| using | ConnectionMap = std::unordered_map< ConnectionId, ConnectionObject > |
| Definition of a map mapping connection ids to sockets. | |
Protected Member Functions | |
| ConnectionOrientedServer () | |
| Creates a new connection oriented server. | |
| ~ConnectionOrientedServer () override | |
| Destructs a connection oriented server. | |
| bool | onScheduler () override |
| The scheduler event function. | |
| virtual size_t | onSend (const ConnectionId connectionId, const void *data, const size_t size) |
| Internal event function to send data. | |
| virtual void | onReceived (const ConnectionId connectionId, const void *data, const size_t size) |
| Internal event function for received data. | |
Protected Member Functions inherited from Ocean::Network::Server | |
| Server () | |
| Creates a new server object. | |
Protected Member Functions inherited from Ocean::Network::Socket | |
| Socket () | |
| Creates a new socket object. | |
| Socket (const Socket &object)=delete | |
| Disabled copy constructor. | |
| bool | setBlockingMode (const bool blocking) |
| Sets the blocking mode of this socket. | |
| size_t | maximalMessageSize (const size_t defaultSize=65536) |
| Returns the maximal message size in bytes. | |
| bool | releaseSocket () |
| Releases the socket. | |
| Socket & | operator= (const Socket &object)=delete |
| Disabled copy operator. | |
Protected Attributes | |
| ConnectionMap | connectionMap_ |
| Map holding all valid connections. | |
| ConnectionId | connectionCounter_ = ConnectionId(invalidConnectionId() + 1) |
| Connection counter. | |
| ConnectionRequestCallback | connectionRequestCallback_ |
| Connection request callback function. | |
| DisconnectCallback | disconnectCallback_ |
| Disconnect callback function. | |
| ReceiveCallback | receiveCallback_ |
| Receive callback function. | |
Protected Attributes inherited from Ocean::Network::Server | |
| Buffer | buffer_ |
| The socket buffer of this server. | |
| bool | schedulerIsActive_ = false |
| True, if the server scheduler is active. | |
Protected Attributes inherited from Ocean::Network::Socket | |
| SocketId | socketId_ = invalidSocketId() |
| Socket id. | |
| Lock | lock_ |
| Socket lock. | |
| NetworkResource | networkResource_ |
| The network resource object. | |
This class is the base class for all connection oriented servers.
| using Ocean::Network::ConnectionOrientedServer::ConnectionId = unsigned int |
Definition of a connection id.
|
protected |
Definition of a map mapping connection ids to sockets.
| using Ocean::Network::ConnectionOrientedServer::ConnectionRequestCallback = Callback<bool, const Address4&, const Port&, const ConnectionId> |
Definition of a connection request callback function.
Parameter 0 provides the address of the requesting client.
Parameter 1 provides the port of the requesting client.
Parameter 2 provides the potential connection id if the connection is accepted.
Return True, to accept the connection.
| using Ocean::Network::ConnectionOrientedServer::DisconnectCallback = Callback<void, const ConnectionId> |
Definition of a disconnect callback function.
Parameter 0 provides the id of the connection which has been disconnected
| using Ocean::Network::ConnectionOrientedServer::ReceiveCallback = Callback<void, const ConnectionId, const void*, const size_t> |
Definition of a receive callback function.
Parameter 0 provides the id of the connection from which the data is provided.
Parameter 1 provides the buffer which has been received, must be copied.
Parameter 2 provides the size of the buffer which has been received, in bytes
|
protected |
Creates a new connection oriented server.
|
overrideprotected |
Destructs a connection oriented server.
| bool Ocean::Network::ConnectionOrientedServer::connectionProperties | ( | const ConnectionId | connectionId, |
| Address4 & | address, | ||
| Port & | port | ||
| ) |
Returns the remote address and port of a specified connection.
| connectionId | The id of the connection from which the address and port will be returned |
| address | Returning remote address |
| port | Returning remote port |
|
virtual |
Returns the number of active connections of this server.
|
pure virtual |
Disconnects a specified connection.
| connectionId | The id of the connection which will be disconnected |
Implemented in Ocean::Network::TCPServer.
|
staticconstexpr |
Returns an invalid connection id.
|
protectedvirtual |
Internal event function for received data.
| connectionId | The id of the connection |
| data | The data that has been received, must be valid |
| size | The size of the data in bytes, with range [1, infinity) |
Reimplemented in Ocean::Network::PackagedTCPServer.
|
overrideprotectedvirtual |
|
protectedvirtual |
Internal event function to send data.
| connectionId | The id of the connection |
| data | The data to send, must be valid |
| size | The size of the data in bytes, with range [1, infinity) |
Reimplemented in Ocean::Network::PackagedTCPServer.
|
virtual |
Sends a message over a specified connection.
| connectionId | The id of the connection which is used to send the data |
| message | The message to send, must not be empty |
|
virtual |
Sends data over a specified connection.
| connectionId | The id of the connection which is used to send the data |
| data | The data to send, can be nullptr if 'size == 0' |
| size | The size of the data to send, in bytes, with range [0, infinity) |
|
inline |
Sets the connection request callback function.
| callback | The callback function to set |
|
inline |
Sets the disconnect callback function.
| callback | The callback function to set |
|
inline |
Sets the receive callback function.
| callback | The callback function to set |
|
protected |
Connection counter.
|
protected |
Map holding all valid connections.
|
protected |
Connection request callback function.
|
protected |
Disconnect callback function.
|
protected |
Receive callback function.