A class that implements connection adapter for TCP-IP transport type. More...
#include <connection_adapter_socket_server.hpp>
Public Member Functions | |
virtual int | getPort () const |
SocketConnectionAdapter (ClientIdManager &clientIdManager, int socketType) | |
Constructor. | |
virtual | ~SocketConnectionAdapter () override |
Destructor. | |
virtual void | configure (const ConnectionAdapter::Parameters ¶meters) override |
virtual void | listen () override |
Starts to listen for connections. | |
virtual void | disconnect (size_t clientId) override |
Terminates connection to given client. | |
virtual void | wait () override |
Starts blocking loop that waits for work, should preserve resources & CPU. | |
virtual void | work () override |
Performs all work that was received during the wait loop. | |
virtual void | interrupt () override |
Allows to interrupt the wait loop and return from the blocking loop. | |
virtual const string & | getConnectionType () const override |
Get the connection type identifier of this connection adapter. | |
virtual unsigned int | getMaximumConnectionCount () const override |
Get maximum number of simultaneous connections for this adapters connection type. | |
virtual const string | getRemoteIPAddress (size_t handle) override |
Gets the IP Address of the remote peer. | |
virtual void | getClientSideParameters (vector< ClientSideParameter > &outputList) const override |
Get list of parameters on the client side that are user configurable. | |
![]() | |
virtual void | aboutToStop () |
Invoked when the adapter should stop. Called before the object will be destroyed. | |
void | addObserver (Observer *observer) |
Adds observer to receive notifications. | |
virtual bool | clientExists (size_t clientId) |
Check whether a client identifier is valid one. | |
ConnectionAdapter (ClientIdManager &clientIdManager) | |
Constructor. | |
ConnectDomainSharedPtr | getDomain () const |
Retrieve the domain where class operates in. | |
unsigned int | getFileBlockSize () const |
Get the file block size configured for this adapter. | |
unsigned int | getFileTransferTimeout () const |
How long timeout should be used (milliseconds) when transferring file through this connection adapter. | |
virtual shared_ptr< MessageTranslator > | getNetworkTranslator (MessagePackage::SerializationFormat format=MessagePackage::SerializationFormatBinary) |
Get message translator used with this connection adapter. | |
bool | getParameterBool (const string &key, bool defaultValue=false) const |
Gets a configuration boolean value. | |
int | getParameterInt (const string &key, int defaultValue=0) const |
Gets a configuration integer value. | |
const string | getParameterString (const string &key, const string defaultValue=string("")) const |
Gets a configuration string value. | |
int | getParameterUInt (const string &key, unsigned int defaultValue=0) const |
Gets a configuration integer value. | |
virtual const string | getTrustedPeerName () const |
For SSL connections return the CN of the client peer certificate for other connections return "Unknown". | |
virtual const string | getType () const =0 |
Retrieves the type of the adapter. | |
virtual bool | isReliable () |
Must be overridden if adapter does not provide reliable transfer. | |
virtual void | releaseResources () |
Potentially invoked before software is being terminated, the object itself might not get deleted in controlled manner (i.e. | |
void | removeObserver (Observer *observer) |
Removes observer. | |
virtual void | send (size_t clientId, const vector< char > &data)=0 |
Sends data to given client. | |
void | setDomain (ConnectDomainSharedPtr domain) |
Configure the domain for the class. | |
virtual bool | supportsListen () |
Must be overridden to disable listening. | |
virtual | ~ConnectionAdapter () |
Destructor. | |
Static Public Attributes | |
static const string | PARAMETER_HOST_PORT |
Configuration parameter, the port number of the listening socket. | |
static const string | PARAMETER_INTERFACE_IP |
![]() | |
static const string | FILE_BLOCK_SIZE_ATTRIBUTE_KEY |
Parameter key for the file block size in the configuration parameters. | |
static const string | FILE_TRANSFER_TIMEOUT_KEY |
Parameter key for the file transfer timeout in the configuration parameters. | |
Protected Member Functions | |
virtual void | acceptPendingConnection (int fd) |
Informs the previously queried (getPendingAcceptSockets()) descriptor has activated and accept procedure can be progressed. | |
virtual bool | adapterClientSocketsAreWaitable () |
Should the client sockets be really listened or not - for some bearers like UDP there is no special client sockets but all data is received through single socket. | |
virtual void | collectDisconnectedClients (set< size_t > &identifiers) |
Invoked periodically from the mainloop of the socket handling thread. | |
virtual int | getAdapterIdlePeriodSeconds () |
Gets the period how often wait -> work cycle should be called in case there is no real work available. | |
virtual void | getPendingAcceptSockets (vector< int > &fds, int &max) |
Invoked to query whether bearer specific implementation has asynchronous accept sockets. | |
virtual void | getPendingTxSockets (vector< int > &fds, int &max) |
Invoked to query whether bearer specific implementation has sockets that should be waited for transmit direction in select(). | |
virtual bool | isDatagramAdapter () |
If datagram adapter should return true. | |
virtual void | onClientConnected (size_t clientId) |
virtual void | onClientDataRead (size_t clientId, const vector< char > &data) |
virtual void | onClientDisconnected (size_t clientId) |
virtual bool | read (int fd, vector< char > &data, size_t &clientId)=0 |
Do the reading from socket. | |
virtual void | sendPendingTxSocketData (int fd) |
Invoked as result of socket descriptor activation to transmit direction. | |
![]() | |
void | notifyConnected (size_t clientId) |
Fires connected event for observers. | |
void | notifyDisconnected (size_t clientId) |
Fires disconnected event for observers. | |
void | notifyReceive (size_t clientId, const vector< char > &data) |
Fires receive event for observers. | |
void | setParameter (const string &key, const int value) |
Set parameter value, create if does not yet exist. | |
void | setParameter (const string &key, const string &value) |
Set parameter value, create if does not yet exist. | |
Protected Attributes | |
set< size_t > | m_clientDisconnectsPending |
Contains a set of client identifiers that have disconnect pending. | |
set< size_t > | m_clients |
Connected clients. | |
PolicyControllerInterfaceSharedPtr | m_policyController = nullptr |
Cache the policyController. | |
int | m_port |
A port number for listening socket. | |
::fd_set * | m_readSet |
File descriptors being listened. | |
int | m_signal [2] |
A pipe to interrupt the wait loop. | |
Socket * | m_socket |
Listening socket. | |
int | m_socketType |
Socket type. | |
int | m_waitResult |
Caches result of wait() call. | |
::fd_set * | m_writeSet |
![]() | |
ClientIdManager & | m_clientIdManager |
ConnectDomainSharedPtr | m_domain |
recursive_mutex | m_mutex |
ObserverContainer | m_observers |
Parameters | m_parameters |
Contains the configuration parameters for the connection adapter, regardless of adapter type. | |
Additional Inherited Members | |
![]() | |
using | Parameters = map<string, string> |
Key-value pairs that can be used to configure an adapter. | |
![]() | |
static bool | getConfigurationBool (const Parameters ¶meters, const string &key, bool defaultValue=false) |
Gets a configuration boolean value. | |
static int | getConfigurationInt (const Parameters ¶meters, const string &key, int defaultValue=0) |
Gets a configuration integer value. | |
static const string | getConfigurationString (const Parameters ¶meters, const string &key, const string defaultValue=string("")) |
Gets a configuration string value. | |
static int | getConfigurationUInt (const Parameters ¶meters, const string &key, unsigned int defaultValue=0) |
Gets a configuration integer value. | |
![]() | |
typedef vector< Observer * > | ObserverContainer |
A class that implements connection adapter for TCP-IP transport type.
|
explicit |
Constructor.
clientIdManager | entity used to allocate internal identifiers for communication |
socketType | type of socket |
|
overridevirtual |
Destructor.
|
inlineprotectedvirtual |
Informs the previously queried (getPendingAcceptSockets()) descriptor has activated and accept procedure can be progressed.
fd | the socket descriptor that activated. |
|
inlineprotectedvirtual |
Should the client sockets be really listened or not - for some bearers like UDP there is no special client sockets but all data is received through single socket.
|
protectedvirtual |
Invoked periodically from the mainloop of the socket handling thread.
Use this function to work with file descriptor (like close socket if marked as disconnected).
|
overridevirtual |
Implements kanzi::connect::ConnectionAdapter.
|
overridevirtual |
Terminates connection to given client.
If a file descriptor related to this client has been returned by the implementation then implementation must not closed the file descriptor. Instead it should mark the client disconnected and issue interrupt() call that will cause the disconnectPendingClients() to be invoked that can be used to close the file descriptors.
clientId | Id of the client that will be disconnected. |
Implements kanzi::connect::ConnectionAdapter.
|
inlineprotectedvirtual |
Gets the period how often wait -> work cycle should be called in case there is no real work available.
|
overridevirtual |
Get list of parameters on the client side that are user configurable.
outputList | Contains the parameters |
Reimplemented from kanzi::connect::ConnectionAdapter.
|
overridevirtual |
Get the connection type identifier of this connection adapter.
Implements kanzi::connect::ConnectionAdapter.
|
overridevirtual |
Get maximum number of simultaneous connections for this adapters connection type.
Implements kanzi::connect::ConnectionAdapter.
|
inlineprotectedvirtual |
Invoked to query whether bearer specific implementation has asynchronous accept sockets.
This is required if bearer does asynchronous connection acception (like SSL)
fds | vector where to fill the socket descriptors to be waited. |
max | the maximum fd number. This should be updated to if fd with bigger value (than passed in max value) is inserted into fds. |
|
inlineprotectedvirtual |
Invoked to query whether bearer specific implementation has sockets that should be waited for transmit direction in select().
fds | vector where to fill the socket descriptors to be waited. |
max | the maximum fd number. This should be updated to if fd with bigger value (than passed in max value) is inserted into fds. |
|
virtual |
|
overridevirtual |
Gets the IP Address of the remote peer.
handle | identifies the remote peer. |
Reimplemented from kanzi::connect::ConnectionAdapter.
|
overridevirtual |
Allows to interrupt the wait loop and return from the blocking loop.
Implements kanzi::connect::ConnectionAdapter.
|
inlineprotectedvirtual |
If datagram adapter should return true.
|
overridevirtual |
Starts to listen for connections.
Implements kanzi::connect::ConnectionAdapter.
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedpure virtual |
Do the reading from socket.
fd | File descriptor of the client to read. |
data | Data read. |
clientId | in case connection adapter is multiplexing where single socket might receive messages from multiple clients (i.e. UDP) this field will be filled with the client identifier of the sender. |
|
inlineprotectedvirtual |
Invoked as result of socket descriptor activation to transmit direction.
The activated descriptor has earlier been queried with getPendingTxSockets
fd | the socket descriptor that activated. |
|
overridevirtual |
Starts blocking loop that waits for work, should preserve resources & CPU.
Implements kanzi::connect::ConnectionAdapter.
|
overridevirtual |
Performs all work that was received during the wait loop.
Implements kanzi::connect::ConnectionAdapter.
|
protected |
Contains a set of client identifiers that have disconnect pending.
|
protected |
Connected clients.
|
protected |
Cache the policyController.
|
protected |
A port number for listening socket.
|
protected |
File descriptors being listened.
|
protected |
A pipe to interrupt the wait loop.
|
protected |
Listening socket.
|
protected |
Socket type.
|
protected |
Caches result of wait() call.
|
protected |
|
static |
Configuration parameter, the port number of the listening socket.
|
static |