NetLink Sockets C++  1.0.0
Networking C++ Library
 All Classes Namespaces Files Functions Enumerations Enumerator Pages
Public Member Functions | List of all members
NL::SocketGroup Class Reference

#include <netlink/socket_group.h>

Public Member Functions

 SocketGroup ()
 
void add (Socket *socket)
 
Socketget (unsigned index) const
 
void remove (unsigned index)
 
void remove (Socket *socket)
 
size_t size () const
 
void setCmdOnAccept (SocketGroupCmd *cmd)
 
void setCmdOnRead (SocketGroupCmd *cmd)
 
void setCmdOnDisconnect (SocketGroupCmd *cmd)
 
bool listen (unsigned milisec=0, void *reference=NULL)
 

Detailed Description

To manage sockets and connections

Examples:
chatClient.cc, chatServer.cc, and webGet.cc.

Constructor & Destructor Documentation

SocketGroup::SocketGroup ( )

SocketGroup constructor

Member Function Documentation

void NL::SocketGroup::add ( Socket socket)
inline

Adds the Socket to the SocketGroup

Parameters
socketSocket to be added
Examples:
chatClient.cc, chatServer.cc, and webGet.cc.
Socket * NL::SocketGroup::get ( unsigned  index) const
inline

Gets the pointer to the Socket of position index in the SocketGroup

Parameters
indexSocket position
Returns
A pointer to the Socket
Exceptions
ExceptionOUT_OF_RANGE
Examples:
chatServer.cc.
bool SocketGroup::listen ( unsigned  milisec = 0,
void *  reference = NULL 
)

Listens for incoming data/connections

Listens during milisecs time for incoming data/connections in any socket of the group calling the appropriate callback (Accept, Read or Disconnect) if assigned.

Note
UDP sockets only uses Read callback as they don not establish connections (can not accept) nor they register disconnections
Parameters
milisecminimum time spent listening. By defaul 0
referenceA pointer which can be passed to the callback functions so they have a context. By default NULL
Returns
false if there were no incoming data, true otherwise
Exceptions
ExceptionERROR_SELECT
Examples:
chatClient.cc, chatServer.cc, and webGet.cc.
void NL::SocketGroup::remove ( unsigned  index)
inline

Removes from the group the Socket of position index

Parameters
indexSocket position
Exceptions
ExceptionOUT_OF_RANGE
Examples:
chatServer.cc, and webGet.cc.
void SocketGroup::remove ( Socket socket)

Removes a socket of the group

Parameters
socketThe socket we want to be removed
Warning
This removes only one reference to the socket: if the socket was added to the group more than once (you shouldn't) there will be references left
void NL::SocketGroup::setCmdOnAccept ( SocketGroupCmd cmd)
inline

Sets the onAcceptReady callback

This callback will be call for any incoming connection waiting to be accepted

Parameters
cmdSocketGroupCmd implementing the desired callback in exec() function
Warning
Only used for TCP protocol SERVER sockets
Examples:
chatServer.cc.
void NL::SocketGroup::setCmdOnDisconnect ( SocketGroupCmd cmd)
inline

Sets the onDisconnect callback

This callback will be call for any disconnection detected

Parameters
cmdSocketGroupCmd implementing the desired callback in exec() function
Warning
Only used for TCP protocol CLIENT sockets
Examples:
chatClient.cc, chatServer.cc, and webGet.cc.
void NL::SocketGroup::setCmdOnRead ( SocketGroupCmd cmd)
inline

Sets the onReadReady callback

This callback will be call for any incoming data waiting to be read

Parameters
cmdSocketGroupCmd implementing the desired callback in exec() function
Examples:
chatClient.cc, chatServer.cc, and webGet.cc.
size_t NL::SocketGroup::size ( ) const
inline

Returns the size of the group

Returns
The number of Sockets contained in the SocketGroup
Examples:
chatServer.cc, and webGet.cc.

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