SocketWatcher Class Reference

#include <sockets.h>

List of all members.


Detailed Description

SocketWatcher class keeps a list of active sockets, performs checking them for events (in DoPoll() member function), as well as events posting to Event Subsystem when there are events in sockets.

Definition at line 479 of file sockets.h.


Static Public Member Functions

static bool initialize ()
 Initialize socket API.
static void poll ()
 Called from application main loop - perform sockets polling.
static SocketWatcherinstance ()
 Access to the Singleton object of this class.
Static public accessors for adding/removing sockets
template<typename T>
static void addSocket (T *socket)
template<typename T>
static void removeSocket (T *socket)

Private Types

typedef std::set< SOCKET
>::iterator 
SIter
typedef std::map< SOCKET,
SocketClient * >::iterator 
SCIter
typedef std::map< SOCKET,
SocketServer * >::iterator 
SSIter
typedef std::map< SOCKET,
UDPSocket * >::iterator 
SUIter

Private Member Functions

 SocketWatcher ()
 ~SocketWatcher ()
 SocketWatcher (const SocketWatcher &)
SocketWatcheroperator= (const SocketWatcher &)
void doPoll ()
 Perform the actual polling.
void cleanupSockets ()
 Cleans up sockets, removing all sockets pending removal from internal data structures.
Implementation of accessors
void doAddSocket (SocketClient *client)
void doAddSocket (SocketServer *socket)
void doAddSocket (UDPSocket *socket)
void doRemoveSocket (SocketClient *client)
void doRemoveSocket (SocketServer *server)
void doRemoveSocket (UDPSocket *socket)
Internal helper functions for posting events.
void handleReadableSocket (SOCKET sock)
void handleWritableSocket (SOCKET sock)
void handleErronousSocket (SOCKET sock)

Private Attributes

std::set< SOCKETm_sockets
 Set of sockets.
std::map< SOCKET, SocketClient * > m_clients
 Map of clients.
std::map< SOCKET, SocketServer * > m_servers
 Map of servers.
std::map< SOCKET, UDPSocket * > m_udpSockets
 Map of UDP sockets.
std::vector< SocketClient * > m_clientsToRemove
std::vector< SocketServer * > m_serversToRemove
std::vector< UDPSocket * > m_udpToRemove

Member Typedef Documentation

typedef std::map<SOCKET, SocketClient*>::iterator SocketWatcher::SCIter [private]
 

Definition at line 532 of file sockets.h.

typedef std::set<SOCKET>::iterator SocketWatcher::SIter [private]
 

Definition at line 531 of file sockets.h.

typedef std::map<SOCKET, SocketServer*>::iterator SocketWatcher::SSIter [private]
 

Definition at line 533 of file sockets.h.

typedef std::map<SOCKET, UDPSocket* >::iterator SocketWatcher::SUIter [private]
 

Definition at line 534 of file sockets.h.


Constructor & Destructor Documentation

SocketWatcher::SocketWatcher  )  [private]
 

Definition at line 677 of file sockets.cpp.

SocketWatcher::~SocketWatcher  )  [private]
 

Definition at line 680 of file sockets.cpp.

SocketWatcher::SocketWatcher const SocketWatcher  )  [private]
 


Member Function Documentation

template<typename T>
static void SocketWatcher::addSocket T *  socket  )  [inline, static]
 

Definition at line 489 of file sockets.h.

References doAddSocket(), and instance().

Referenced by SocketServer::accept(), SocketClient::connect(), UDPSocket::listen(), and SocketServer::listen().

Here is the call graph for this function:

void SocketWatcher::cleanupSockets  )  [private]
 

Cleans up sockets, removing all sockets pending removal from internal data structures.

Definition at line 752 of file sockets.cpp.

References SocketBase::getSocket(), logTrace(), m_clients, m_clientsToRemove, m_servers, m_serversToRemove, m_sockets, m_udpSockets, m_udpToRemove, SocketBase::toDelete(), and TRACE_SOCKET.

Referenced by doPoll().

Here is the call graph for this function:

void SocketWatcher::doAddSocket UDPSocket socket  )  [private]
 

Definition at line 728 of file sockets.cpp.

References CHECK_THROW, logTrace(), m_sockets, m_udpSockets, and TRACE_SOCKET.

Here is the call graph for this function:

void SocketWatcher::doAddSocket SocketServer socket  )  [private]
 

Definition at line 707 of file sockets.cpp.

References CHECK_THROW, logTrace(), m_servers, m_sockets, and TRACE_SOCKET.

Here is the call graph for this function:

void SocketWatcher::doAddSocket SocketClient client  )  [private]
 

Definition at line 718 of file sockets.cpp.

References CHECK_THROW, logTrace(), m_clients, m_sockets, and TRACE_SOCKET.

Referenced by addSocket().

Here is the call graph for this function:

void SocketWatcher::doPoll  )  [private]
 

Perform the actual polling.

Definition at line 814 of file sockets.cpp.

References cleanupSockets(), SocketClient::close(), Utils::getTick(), handleErronousSocket(), handleReadableSocket(), handleWritableSocket(), m_clients, SocketClient::m_connected, SocketClient::m_connecting, SocketClient::m_erronous, SocketClient::m_hasData, m_servers, m_sockets, SocketClient::m_timeout, m_udpSockets, SocketClient::m_writable, and SOCK_TIMEOUT.

Referenced by poll().

Here is the call graph for this function:

void SocketWatcher::doRemoveSocket UDPSocket socket  )  [private]
 

Definition at line 748 of file sockets.cpp.

References CHECK_THROW, and m_udpToRemove.

void SocketWatcher::doRemoveSocket SocketServer server  )  [private]
 

Definition at line 740 of file sockets.cpp.

References CHECK_THROW, and m_serversToRemove.

void SocketWatcher::doRemoveSocket SocketClient client  )  [private]
 

Definition at line 744 of file sockets.cpp.

References CHECK_THROW, and m_clientsToRemove.

Referenced by removeSocket().

void SocketWatcher::handleErronousSocket SOCKET  sock  )  [private]
 

Definition at line 1050 of file sockets.cpp.

References SocketClient::close(), SocketServer::close(), logDebug(), logTrace(), m_clients, SocketClient::m_connected, SocketClient::m_connecting, SocketClient::m_erronous, SocketServer::m_erronous, SocketServer::m_listening, m_servers, SocketClient::m_timeout, SOCK_LOST, and TRACE_SOCKET.

Referenced by doPoll().

Here is the call graph for this function:

void SocketWatcher::handleReadableSocket SOCKET  sock  )  [private]
 

Definition at line 920 of file sockets.cpp.

References SocketClient::close(), getErrorStr(), getLastError(), logDebug(), logTrace(), m_clients, SocketClient::m_connected, SocketClient::m_connecting, SocketClient::m_erronous, SocketClient::m_hasData, UDPSocket::m_hasData, SocketServer::m_incoming, m_servers, SocketClient::m_timeout, m_udpSockets, MSG_NOSIGNAL, SOCK_ACCEPT, SOCK_EINPROGRESS, SOCK_ERR, SOCK_EWOULDBLOCK, SOCK_LOST, SOCK_READ, SOCKET_ERROR, and TRACE_SOCKET.

Referenced by doPoll().

Here is the call graph for this function:

void SocketWatcher::handleWritableSocket SOCKET  sock  )  [private]
 

Definition at line 994 of file sockets.cpp.

References SocketClient::close(), logDebug(), logTrace(), m_clients, SocketClient::m_connected, SocketClient::m_connecting, SocketClient::m_timeout, SocketClient::m_writable, SOCK_CONNECTED, SOCK_CONNFAILED, SOCK_WRITE, SOCKET_ERROR, and TRACE_SOCKET.

Referenced by doPoll().

Here is the call graph for this function:

bool SocketWatcher::initialize  )  [static]
 

Initialize socket API.

Definition at line 685 of file sockets.cpp.

SocketWatcher & SocketWatcher::instance  )  [static]
 

Access to the Singleton object of this class.

Definition at line 701 of file sockets.cpp.

Referenced by addSocket(), poll(), and removeSocket().

SocketWatcher& SocketWatcher::operator= const SocketWatcher  )  [private]
 

static void SocketWatcher::poll  )  [inline, static]
 

Called from application main loop - perform sockets polling.

Definition at line 499 of file sockets.h.

References doPoll(), and instance().

Referenced by HydraNode::doLoop().

Here is the call graph for this function:

template<typename T>
static void SocketWatcher::removeSocket T *  socket  )  [inline, static]
 

Definition at line 493 of file sockets.h.

References doRemoveSocket(), and instance().

Referenced by SocketServer::close(), SocketClient::close(), and UDPSocket::destroy().

Here is the call graph for this function:


Member Data Documentation

std::map<SOCKET, SocketClient*> SocketWatcher::m_clients [private]
 

Map of clients.

Definition at line 527 of file sockets.h.

Referenced by cleanupSockets(), doAddSocket(), doPoll(), handleErronousSocket(), handleReadableSocket(), and handleWritableSocket().

std::vector<SocketClient*> SocketWatcher::m_clientsToRemove [private]
 

These are cleared, and removed from real containers in cleanupSockets() method.

Definition at line 550 of file sockets.h.

Referenced by cleanupSockets(), and doRemoveSocket().

std::map<SOCKET, SocketServer*> SocketWatcher::m_servers [private]
 

Map of servers.

Definition at line 528 of file sockets.h.

Referenced by cleanupSockets(), doAddSocket(), doPoll(), handleErronousSocket(), and handleReadableSocket().

std::vector<SocketServer*> SocketWatcher::m_serversToRemove [private]
 

Definition at line 551 of file sockets.h.

Referenced by cleanupSockets(), and doRemoveSocket().

std::set<SOCKET> SocketWatcher::m_sockets [private]
 

Set of sockets.

Definition at line 526 of file sockets.h.

Referenced by cleanupSockets(), doAddSocket(), and doPoll().

std::map<SOCKET, UDPSocket* > SocketWatcher::m_udpSockets [private]
 

Map of UDP sockets.

Definition at line 529 of file sockets.h.

Referenced by cleanupSockets(), doAddSocket(), doPoll(), and handleReadableSocket().

std::vector<UDPSocket* > SocketWatcher::m_udpToRemove [private]
 

Definition at line 552 of file sockets.h.

Referenced by cleanupSockets(), and doRemoveSocket().


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