Kanzi Connect  1.1.10
Kanzi Connect C++ API
kanzi::connect::SocketConnectionAdapter Class Referenceabstract

A class that implements connection adapter for TCP-IP transport type. More...

#include <connection_adapter_socket_server.hpp>

Inheritance diagram for kanzi::connect::SocketConnectionAdapter:
kanzi::connect::ConnectionAdapter

Public Member Functions

virtual int getPort () const
 
 SocketConnectionAdapter (ClientIdManager &clientIdManager, int socketType)
 Constructor. More...
 
virtual ~SocketConnectionAdapter () KZ_OVERRIDE
 Destructor. More...
 
virtual void configure (const ConnectionAdapter::Parameters &parameters) KZ_OVERRIDE
 
virtual void listen () KZ_OVERRIDE
 Starts to listen for connections. More...
 
virtual void disconnect (size_t clientId) KZ_OVERRIDE
 Terminates connection to given client. More...
 
virtual void wait () KZ_OVERRIDE
 Starts blocking loop that waits for work, should preserve resources & CPU. More...
 
virtual void work () KZ_OVERRIDE
 Performs all work that was received during the wait loop. More...
 
virtual void interrupt () KZ_OVERRIDE
 Allows to interrupt the wait loop and return from the blocking loop. More...
 
virtual const string & getConnectionType () const KZ_OVERRIDE
 Get the connection type identifier of this connection adapter. More...
 
virtual unsigned int getMaximumConnectionCount () const KZ_OVERRIDE
 Get maximum number of simultaneous connections for this adapters connection type. More...
 
virtual const string getRemoteIPAddress (size_t handle) KZ_OVERRIDE
 Gets the IP Address of the remote peer. More...
 
virtual void getClientSideParameters (vector< ClientSideParameter > &outputList) const KZ_OVERRIDE
 Get list of parameters on the client side that are user configurable. More...
 
- Public Member Functions inherited from kanzi::connect::ConnectionAdapter
virtual void aboutToStop ()
 Invoked when the adapter should stop. Called before the object will be destroyed. More...
 
void addObserver (Observer *observer)
 Adds observer to receive notifications. More...
 
virtual bool clientExists (size_t clientId)
 Check whether a client identifier is valid one. More...
 
 ConnectionAdapter (ClientIdManager &clientIdManager)
 Constructor. More...
 
ConnectDomaingetDomain () const
 Retrieve the domain where class operates in. More...
 
unsigned int getFileBlockSize () const
 Get the file block size configured for this adapter. More...
 
unsigned int getFileTransferTimeout () const
 How long timeout should be used (milliseconds) when transferring file through this connection adapter. More...
 
bool getParameterBool (const string &key, bool defaultValue=false) const
 Gets a configuration boolean value. More...
 
int getParameterInt (const string &key, int defaultValue=0) const
 Gets a configuration integer value. More...
 
const string getParameterString (const string &key, const string defaultValue=string("")) const
 Gets a configuration string value. More...
 
int getParameterUInt (const string &key, unsigned int defaultValue=0) const
 Gets a configuration integer value. More...
 
virtual const string getTrustedPeerName () const
 For SSL connections return the CN of the client peer certificate for other connections return "Unknown". More...
 
virtual const string getType () const =0
 Retrieves the type of the adapter. More...
 
virtual bool isReliable ()
 Must be overridden if adapter does not provide reliable transfer. More...
 
virtual void releaseResources ()
 Potentially invoked before software is being terminated, the object itself might not get deleted in controlled manner (i.e. More...
 
void removeObserver (Observer *observer)
 Removes observer. More...
 
virtual void send (size_t clientId, const vector< char > &data)=0
 Sends data to given client. More...
 
void setDomain (ConnectDomain *domain)
 Configure the domain for the class. More...
 
virtual ~ConnectionAdapter ()
 Destructor. More...
 

Static Public Attributes

static const string PARAMETER_HOST_PORT
 Configuration parameter, the port number of the listening socket. More...
 
static const string PARAMETER_INTERFACE_IP
 
- Static Public Attributes inherited from kanzi::connect::ConnectionAdapter
static const string FILE_BLOCK_SIZE_ATTRIBUTE_KEY
 Parameter key for the file block size in the configuration parameters. More...
 
static const string FILE_TRANSFER_TIMEOUT_KEY
 Parameter key for the file transfer timeout in the configuration parameters. More...
 

Protected Member Functions

virtual void acceptPendingConnection (int fd)
 Informs the previously queried (getPendingAcceptSockets()) descriptor has activated and accept procedure can be progressed. More...
 
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. More...
 
virtual void collectDisconnectedClients (set< size_t > &identifiers)
 Invoked periodically from the mainloop of the socket handling thread. More...
 
virtual int getAdapterIdlePeriodSeconds ()
 Gets the period how often wait -> work cycle should be called in case there is no real work available. More...
 
virtual void getPendingAcceptSockets (vector< int > &fds, int &max)
 Invoked to query whether bearer specific implementation has asynchronous accept sockets. More...
 
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(). More...
 
virtual bool isDatagramAdapter ()
 If datagram adapter should return true. More...
 
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. More...
 
virtual void sendPendingTxSocketData (int fd)
 Invoked as result of socket descriptor activation to transmit direction. More...
 
- Protected Member Functions inherited from kanzi::connect::ConnectionAdapter
void notifyConnected (size_t clientId)
 Fires connected event for observers. More...
 
void notifyDisconnected (size_t clientId)
 Fires disconnected event for observers. More...
 
void notifyReceive (size_t clientId, const vector< char > &data)
 Fires receive event for observers. More...
 
void setParameter (const string &key, const int value)
 Set parameter value, create if does not yet exist. More...
 
void setParameter (const string &key, const string &value)
 Set parameter value, create if does not yet exist. More...
 

Protected Attributes

set< size_t > m_clientDisconnectsPending
 Contains a set of client identifiers that have disconnect pending. More...
 
set< size_t > m_clients
 Connected clients. More...
 
PolicyControllerInterfaceSharedPtr m_policyController = nullptr
 Cache the policyController. More...
 
int m_port
 A port number for listening socket. More...
 
::fd_set * m_readSet
 File descriptors being listened. More...
 
int m_signal [2]
 A pipe to interrupt the wait loop. More...
 
Socketm_socket
 Listening socket. More...
 
int m_socketType
 Socket type. More...
 
int m_waitResult
 Caches result of wait() call. More...
 
::fd_set * m_writeSet
 
- Protected Attributes inherited from kanzi::connect::ConnectionAdapter
ClientIdManagerm_clientIdManager
 
ConnectDomainm_domain
 
recursive_mutex m_mutex
 
ObserverContainer m_observers
 
Parameters m_parameters
 Contains the configuration parameters for the connection adapter, regardless of adapter type. More...
 

Additional Inherited Members

- Public Types inherited from kanzi::connect::ConnectionAdapter
using Parameters = map< string, string >
 Key-value pairs that can be used to configure an adapter. More...
 
- Static Public Member Functions inherited from kanzi::connect::ConnectionAdapter
static bool getConfigurationBool (const Parameters &parameters, const string &key, bool defaultValue=false)
 Gets a configuration boolean value. More...
 
static int getConfigurationInt (const Parameters &parameters, const string &key, int defaultValue=0)
 Gets a configuration integer value. More...
 
static const string getConfigurationString (const Parameters &parameters, const string &key, const string defaultValue=string(""))
 Gets a configuration string value. More...
 
static int getConfigurationUInt (const Parameters &parameters, const string &key, unsigned int defaultValue=0)
 Gets a configuration integer value. More...
 
- Protected Types inherited from kanzi::connect::ConnectionAdapter
typedef vector< Observer * > ObserverContainer
 

Detailed Description

A class that implements connection adapter for TCP-IP transport type.

Constructor & Destructor Documentation

◆ SocketConnectionAdapter()

kanzi::connect::SocketConnectionAdapter::SocketConnectionAdapter ( ClientIdManager clientIdManager,
int  socketType 
)
explicit

Constructor.

Parameters
clientIdManagerentity used to allocate internal identifiers for communication
socketTypetype of socket

◆ ~SocketConnectionAdapter()

virtual kanzi::connect::SocketConnectionAdapter::~SocketConnectionAdapter ( )
virtual

Destructor.

Member Function Documentation

◆ acceptPendingConnection()

virtual void kanzi::connect::SocketConnectionAdapter::acceptPendingConnection ( int  fd)
inlineprotectedvirtual

Informs the previously queried (getPendingAcceptSockets()) descriptor has activated and accept procedure can be progressed.

Parameters
fdthe socket descriptor that activated.

◆ adapterClientSocketsAreWaitable()

virtual bool kanzi::connect::SocketConnectionAdapter::adapterClientSocketsAreWaitable ( )
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.

Returns
true (default=true) if client sockets should be listened.

◆ collectDisconnectedClients()

virtual void kanzi::connect::SocketConnectionAdapter::collectDisconnectedClients ( set< size_t > &  identifiers)
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).

◆ configure()

virtual void kanzi::connect::SocketConnectionAdapter::configure ( const ConnectionAdapter::Parameters parameters)
virtual

◆ disconnect()

virtual void kanzi::connect::SocketConnectionAdapter::disconnect ( size_t  clientId)
virtual

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.

Parameters
clientIdId of the client that will be disconnected.

Implements kanzi::connect::ConnectionAdapter.

◆ getAdapterIdlePeriodSeconds()

virtual int kanzi::connect::SocketConnectionAdapter::getAdapterIdlePeriodSeconds ( )
inlineprotectedvirtual

Gets the period how often wait -> work cycle should be called in case there is no real work available.

Returns
period (default=5s) in seconds.

◆ getClientSideParameters()

virtual void kanzi::connect::SocketConnectionAdapter::getClientSideParameters ( vector< ClientSideParameter > &  outputList) const
virtual

Get list of parameters on the client side that are user configurable.

Parameters
outputListContains the parameters

Reimplemented from kanzi::connect::ConnectionAdapter.

◆ getConnectionType()

virtual const string& kanzi::connect::SocketConnectionAdapter::getConnectionType ( ) const
virtual

Get the connection type identifier of this connection adapter.

Returns
string which identifies the connection type (e.g. "socket")

Implements kanzi::connect::ConnectionAdapter.

◆ getMaximumConnectionCount()

virtual unsigned int kanzi::connect::SocketConnectionAdapter::getMaximumConnectionCount ( ) const
virtual

Get maximum number of simultaneous connections for this adapters connection type.

See also
getConnectionType

Implements kanzi::connect::ConnectionAdapter.

◆ getPendingAcceptSockets()

virtual void kanzi::connect::SocketConnectionAdapter::getPendingAcceptSockets ( vector< int > &  fds,
int &  max 
)
inlineprotectedvirtual

Invoked to query whether bearer specific implementation has asynchronous accept sockets.

This is required if bearer does asynchronous connection acception (like SSL)

Parameters
fdsvector where to fill the socket descriptors to be waited.
maxthe maximum fd number. This should be updated to if fd with bigger value (than passed in max value) is inserted into fds.

◆ getPendingTxSockets()

virtual void kanzi::connect::SocketConnectionAdapter::getPendingTxSockets ( vector< int > &  fds,
int &  max 
)
inlineprotectedvirtual

Invoked to query whether bearer specific implementation has sockets that should be waited for transmit direction in select().

Parameters
fdsvector where to fill the socket descriptors to be waited.
maxthe maximum fd number. This should be updated to if fd with bigger value (than passed in max value) is inserted into fds.

◆ getPort()

virtual int kanzi::connect::SocketConnectionAdapter::getPort ( ) const
virtual

◆ getRemoteIPAddress()

virtual const string kanzi::connect::SocketConnectionAdapter::getRemoteIPAddress ( size_t  )
virtual

Gets the IP Address of the remote peer.

Parameters
handleidentifies the remote peer.
Returns
IP address of the remote peer.

Reimplemented from kanzi::connect::ConnectionAdapter.

◆ interrupt()

virtual void kanzi::connect::SocketConnectionAdapter::interrupt ( )
virtual

Allows to interrupt the wait loop and return from the blocking loop.

Implements kanzi::connect::ConnectionAdapter.

◆ isDatagramAdapter()

virtual bool kanzi::connect::SocketConnectionAdapter::isDatagramAdapter ( )
inlineprotectedvirtual

If datagram adapter should return true.

Returns
true if datagram protocol used and single socket is used to multiplex communications.

◆ listen()

virtual void kanzi::connect::SocketConnectionAdapter::listen ( )
virtual

Starts to listen for connections.

Implements kanzi::connect::ConnectionAdapter.

◆ onClientConnected()

virtual void kanzi::connect::SocketConnectionAdapter::onClientConnected ( size_t  clientId)
protectedvirtual

◆ onClientDataRead()

virtual void kanzi::connect::SocketConnectionAdapter::onClientDataRead ( size_t  clientId,
const vector< char > &  data 
)
protectedvirtual

◆ onClientDisconnected()

virtual void kanzi::connect::SocketConnectionAdapter::onClientDisconnected ( size_t  clientId)
protectedvirtual

◆ read()

virtual bool kanzi::connect::SocketConnectionAdapter::read ( int  fd,
vector< char > &  data,
size_t &  clientId 
)
protectedpure virtual

Do the reading from socket.

Parameters
fdFile descriptor of the client to read.
dataData read.
clientIdin 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.
Returns
Client was disconnected.

◆ sendPendingTxSocketData()

virtual void kanzi::connect::SocketConnectionAdapter::sendPendingTxSocketData ( int  fd)
inlineprotectedvirtual

Invoked as result of socket descriptor activation to transmit direction.

The activated descriptor has earlier been queried with getPendingTxSockets

Parameters
fdthe socket descriptor that activated.

◆ wait()

virtual void kanzi::connect::SocketConnectionAdapter::wait ( )
virtual

Starts blocking loop that waits for work, should preserve resources & CPU.

Implements kanzi::connect::ConnectionAdapter.

◆ work()

virtual void kanzi::connect::SocketConnectionAdapter::work ( )
virtual

Performs all work that was received during the wait loop.

Implements kanzi::connect::ConnectionAdapter.

Member Data Documentation

◆ m_clientDisconnectsPending

set<size_t> kanzi::connect::SocketConnectionAdapter::m_clientDisconnectsPending
protected

Contains a set of client identifiers that have disconnect pending.

◆ m_clients

set<size_t> kanzi::connect::SocketConnectionAdapter::m_clients
protected

Connected clients.

◆ m_policyController

PolicyControllerInterfaceSharedPtr kanzi::connect::SocketConnectionAdapter::m_policyController = nullptr
protected

Cache the policyController.

◆ m_port

int kanzi::connect::SocketConnectionAdapter::m_port
protected

A port number for listening socket.

◆ m_readSet

::fd_set* kanzi::connect::SocketConnectionAdapter::m_readSet
protected

File descriptors being listened.

◆ m_signal

int kanzi::connect::SocketConnectionAdapter::m_signal[2]
protected

A pipe to interrupt the wait loop.

◆ m_socket

Socket* kanzi::connect::SocketConnectionAdapter::m_socket
protected

Listening socket.

◆ m_socketType

int kanzi::connect::SocketConnectionAdapter::m_socketType
protected

Socket type.

◆ m_waitResult

int kanzi::connect::SocketConnectionAdapter::m_waitResult
protected

Caches result of wait() call.

◆ m_writeSet

::fd_set* kanzi::connect::SocketConnectionAdapter::m_writeSet
protected

◆ PARAMETER_HOST_PORT

const string kanzi::connect::SocketConnectionAdapter::PARAMETER_HOST_PORT
static

Configuration parameter, the port number of the listening socket.

◆ PARAMETER_INTERFACE_IP

const string kanzi::connect::SocketConnectionAdapter::PARAMETER_INTERFACE_IP
static

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