Ocean
|
This class is the base class for all connection oriented servers. More...
Data Structures | |
class | ConnectionObject |
Definition of a connection object holding the socket and remote address and port. More... | |
Public Types | |
typedef unsigned int | ConnectionId |
Definition of a connection id. More... | |
typedef Callback< bool, const Address4 &, const Port &, const ConnectionId > | ConnectionRequestCallback |
Definition of a connection request callback function. More... | |
typedef Callback< void, const ConnectionId > | DisconnectCallback |
Definition of a disconnect callback function. More... | |
typedef Callback< void, const ConnectionId, const void *, const size_t > | ReceiveCallback |
Definition of a receive callback function. More... | |
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... | |
typedef SOCKET | SocketId |
Definition of a socket id. More... | |
typedef int | SocketId |
Definition of a socket id. More... | |
typedef std::vector< uint8_t > | Buffer |
Definition of a vector holding 8 bit values. More... | |
Public Member Functions | |
virtual SocketResult | send (const ConnectionId connectionId, const void *data, const size_t size) |
Sends data over a specified connection. More... | |
virtual SocketResult | send (const ConnectionId connectionId, const std::string &message) |
Sends a message over a specified connection. More... | |
virtual bool | disconnect (const ConnectionId connectionId)=0 |
Disconnects a specified connection. More... | |
virtual size_t | connections () const |
Returns the number of active connections of this server. More... | |
bool | connectionProperties (const ConnectionId connectionId, Address4 &address, Port &port) |
Returns the remote address and port of a specified connection. More... | |
void | setConnectionRequestCallback (const ConnectionRequestCallback &callback) |
Sets the connection request callback function. More... | |
void | setDisconnectCallback (const DisconnectCallback &callback) |
Sets the disconnect callback function. More... | |
void | setReceiveCallback (const ReceiveCallback &callback) |
Sets the receive callback function. More... | |
Public Member Functions inherited from Ocean::Network::Server | |
~Server () override | |
Destructs a server object. More... | |
virtual bool | start () |
Starts the server. More... | |
virtual bool | stop () |
Stops the server. More... | |
Public Member Functions inherited from Ocean::Network::Socket | |
virtual | ~Socket () |
Destructs a socket object. More... | |
SocketId | id () const |
Returns the socket id. More... | |
Address4 | address () const |
Returns the own address of this socket. More... | |
Port | port () const |
Returns the own port of this socket. More... | |
virtual bool | setAddress (const Address4 &address) |
Sets the own address of this socket. More... | |
virtual bool | setPort (const Port &port) |
Sets the own port of this socket. More... | |
operator bool () const | |
Returns whether this socket is valid. More... | |
Static Public Member Functions | |
static constexpr ConnectionId | invalidConnectionId () |
Returns an invalid connection id. More... | |
Static Public Member Functions inherited from Ocean::Network::Socket | |
static constexpr SocketId | invalidSocketId () |
Returns an invalid socket id. More... | |
static bool | setBlockingMode (const SocketId socketId, const bool blocking) |
Sets the blocking mode of a socket. More... | |
Protected Types | |
typedef std::unordered_map< ConnectionId, ConnectionObject > | ConnectionMap |
Definition of a map mapping connection ids to sockets. More... | |
Protected Member Functions | |
ConnectionOrientedServer () | |
Creates a new connection oriented server. More... | |
~ConnectionOrientedServer () override | |
Destructs a connection oriented server. More... | |
bool | onScheduler () override |
The scheduler event function. More... | |
virtual size_t | onSend (const ConnectionId connectionId, const void *data, const size_t size) |
Internal event function to send data. More... | |
virtual void | onReceived (const ConnectionId connectionId, const void *data, const size_t size) |
Internal event function for received data. More... | |
Protected Member Functions inherited from Ocean::Network::Server | |
Server () | |
Creates a new server object. More... | |
Protected Member Functions inherited from Ocean::Network::Socket | |
Socket () | |
Creates a new socket object. More... | |
Socket (const Socket &object)=delete | |
Disabled copy constructor. More... | |
bool | setBlockingMode (const bool blocking) |
Sets the blocking mode of this socket. More... | |
size_t | maximalMessageSize (const size_t defaultSize=65536) |
Returns the maximal message size in bytes. More... | |
bool | releaseSocket () |
Releases the socket. More... | |
Socket & | operator= (const Socket &object)=delete |
Disabled copy operator. More... | |
Protected Attributes | |
ConnectionMap | connectionMap_ |
Map holding all valid connections. More... | |
ConnectionId | connectionCounter_ = ConnectionId(invalidConnectionId() + 1) |
Connection counter. More... | |
ConnectionRequestCallback | connectionRequestCallback_ |
Connection request callback function. More... | |
DisconnectCallback | disconnectCallback_ |
Disconnect callback function. More... | |
ReceiveCallback | receiveCallback_ |
Receive callback function. More... | |
Protected Attributes inherited from Ocean::Network::Server | |
Buffer | buffer_ |
The socket buffer of this server. More... | |
bool | schedulerIsActive_ = false |
True, if the server scheduler is active. More... | |
Protected Attributes inherited from Ocean::Network::Socket | |
SocketId | socketId_ = invalidSocketId() |
Socket id. More... | |
Lock | lock_ |
Socket lock. More... | |
NetworkResource | networkResource_ |
The network resource object. More... | |
This class is the base class for all connection oriented servers.
typedef unsigned int Ocean::Network::ConnectionOrientedServer::ConnectionId |
Definition of a connection id.
|
protected |
Definition of a map mapping connection ids to sockets.
typedef Callback<bool, const Address4&, const Port&, const ConnectionId> Ocean::Network::ConnectionOrientedServer::ConnectionRequestCallback |
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.
typedef Callback<void, const ConnectionId> Ocean::Network::ConnectionOrientedServer::DisconnectCallback |
Definition of a disconnect callback function.
Parameter 0 provides the id of the connection which has been disconnected
typedef Callback<void, const ConnectionId, const void*, const size_t> Ocean::Network::ConnectionOrientedServer::ReceiveCallback |
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.