Ocean
Ocean::Network::ConnectionOrientedServer Class Referenceabstract

This class is the base class for all connection oriented servers. More...

Inheritance diagram for Ocean::Network::ConnectionOrientedServer:

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 ConnectionIdConnectionRequestCallback
 Definition of a connection request callback function. More...
 
typedef Callback< void, const ConnectionIdDisconnectCallback
 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, ConnectionObjectConnectionMap
 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...
 
Socketoperator= (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...
 

Detailed Description

This class is the base class for all connection oriented servers.

Member Typedef Documentation

◆ ConnectionId

Definition of a connection id.

◆ ConnectionMap

Definition of a map mapping connection ids to sockets.

◆ 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.

◆ DisconnectCallback

Definition of a disconnect callback function.


Parameter 0 provides the id of the connection which has been disconnected

◆ ReceiveCallback

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

Constructor & Destructor Documentation

◆ ConnectionOrientedServer()

Ocean::Network::ConnectionOrientedServer::ConnectionOrientedServer ( )
protected

Creates a new connection oriented server.

◆ ~ConnectionOrientedServer()

Ocean::Network::ConnectionOrientedServer::~ConnectionOrientedServer ( )
overrideprotected

Destructs a connection oriented server.

Member Function Documentation

◆ connectionProperties()

bool Ocean::Network::ConnectionOrientedServer::connectionProperties ( const ConnectionId  connectionId,
Address4 address,
Port port 
)

Returns the remote address and port of a specified connection.

Parameters
connectionIdThe id of the connection from which the address and port will be returned
addressReturning remote address
portReturning remote port
Returns
True, if the connection exists

◆ connections()

virtual size_t Ocean::Network::ConnectionOrientedServer::connections ( ) const
virtual

Returns the number of active connections of this server.

Returns
Number of active connections

◆ disconnect()

virtual bool Ocean::Network::ConnectionOrientedServer::disconnect ( const ConnectionId  connectionId)
pure virtual

Disconnects a specified connection.

Parameters
connectionIdThe id of the connection which will be disconnected
Returns
True, if the connection was established

Implemented in Ocean::Network::TCPServer.

◆ invalidConnectionId()

constexpr ConnectionOrientedServer::ConnectionId Ocean::Network::ConnectionOrientedServer::invalidConnectionId ( )
staticconstexpr

Returns an invalid connection id.

Returns
Invalid connection id

◆ onReceived()

virtual void Ocean::Network::ConnectionOrientedServer::onReceived ( const ConnectionId  connectionId,
const void *  data,
const size_t  size 
)
protectedvirtual

Internal event function for received data.

Parameters
connectionIdThe id of the connection
dataThe data that has been received, must be valid
sizeThe size of the data in bytes, with range [1, infinity)

Reimplemented in Ocean::Network::PackagedTCPServer.

◆ onScheduler()

bool Ocean::Network::ConnectionOrientedServer::onScheduler ( )
overrideprotectedvirtual

The scheduler event function.

Socket::onScheduler().

Reimplemented from Ocean::Network::Socket.

◆ onSend()

virtual size_t Ocean::Network::ConnectionOrientedServer::onSend ( const ConnectionId  connectionId,
const void *  data,
const size_t  size 
)
protectedvirtual

Internal event function to send data.

Parameters
connectionIdThe id of the connection
dataThe data to send, must be valid
sizeThe size of the data in bytes, with range [1, infinity)
Returns
The number of bytes which have been sent, with range [0, size]

Reimplemented in Ocean::Network::PackagedTCPServer.

◆ send() [1/2]

virtual SocketResult Ocean::Network::ConnectionOrientedServer::send ( const ConnectionId  connectionId,
const std::string &  message 
)
virtual

Sends a message over a specified connection.

Parameters
connectionIdThe id of the connection which is used to send the data
messageThe message to send, must not be empty
Returns
SR_SUCCEEDED, if succeeded

◆ send() [2/2]

virtual SocketResult Ocean::Network::ConnectionOrientedServer::send ( const ConnectionId  connectionId,
const void *  data,
const size_t  size 
)
virtual

Sends data over a specified connection.

Parameters
connectionIdThe id of the connection which is used to send the data
dataThe data to send, can be nullptr if 'size == 0'
sizeThe size of the data to send, in bytes, with range [0, infinity)
Returns
SR_SUCCEEDED, if succeeded

◆ setConnectionRequestCallback()

void Ocean::Network::ConnectionOrientedServer::setConnectionRequestCallback ( const ConnectionRequestCallback callback)
inline

Sets the connection request callback function.

Parameters
callbackThe callback function to set

◆ setDisconnectCallback()

void Ocean::Network::ConnectionOrientedServer::setDisconnectCallback ( const DisconnectCallback callback)
inline

Sets the disconnect callback function.

Parameters
callbackThe callback function to set

◆ setReceiveCallback()

void Ocean::Network::ConnectionOrientedServer::setReceiveCallback ( const ReceiveCallback callback)
inline

Sets the receive callback function.

Parameters
callbackThe callback function to set

Field Documentation

◆ connectionCounter_

ConnectionId Ocean::Network::ConnectionOrientedServer::connectionCounter_ = ConnectionId(invalidConnectionId() + 1)
protected

Connection counter.

◆ connectionMap_

ConnectionMap Ocean::Network::ConnectionOrientedServer::connectionMap_
protected

Map holding all valid connections.

◆ connectionRequestCallback_

ConnectionRequestCallback Ocean::Network::ConnectionOrientedServer::connectionRequestCallback_
protected

Connection request callback function.

◆ disconnectCallback_

DisconnectCallback Ocean::Network::ConnectionOrientedServer::disconnectCallback_
protected

Disconnect callback function.

◆ receiveCallback_

ReceiveCallback Ocean::Network::ConnectionOrientedServer::receiveCallback_
protected

Receive callback function.


The documentation for this class was generated from the following file: