#include <TCPSocketMap.h>
Public Member Functions | |
| TCPSocketMap () | |
| ~TCPSocketMap () | |
| TCPSocket * | findSocketFor (cMessage *msg) |
| void | addSocket (TCPSocket *socket) |
| TCPSocket * | removeSocket (TCPSocket *socket) |
| unsigned int | size () |
| void | deleteSockets () |
Protected Types | |
| typedef std::map< int, TCPSocket * > | SocketMap |
Protected Attributes | |
| SocketMap | socketMap |
Small utility class for managing a large number of TCPSocket objects.
Definition at line 32 of file TCPSocketMap.h.
typedef std::map<int,TCPSocket*> TCPSocketMap::SocketMap [protected] |
Definition at line 35 of file TCPSocketMap.h.
| TCPSocketMap::TCPSocketMap | ( | ) | [inline] |
| TCPSocketMap::~TCPSocketMap | ( | ) | [inline] |
| void TCPSocketMap::addSocket | ( | TCPSocket * | socket | ) |
Registers the given socket. Should not be called multiple times for one socket object.
Definition at line 33 of file TCPSocketMap.cc.
Referenced by TCPSrvHostApp::handleMessage(), LDP::openTCPConnectionToPeer(), and LDP::processMessageFromTCP().
{
ASSERT(socketMap.find(socket->getConnectionId())==socketMap.end());
socketMap[socket->getConnectionId()] = socket;
}
| void TCPSocketMap::deleteSockets | ( | ) |
Deletes the socket objects.
Definition at line 47 of file TCPSocketMap.cc.
| TCPSocket * TCPSocketMap::findSocketFor | ( | cMessage * | msg | ) |
Finds the socket (by connId) for the given message. The message must have arrived from TCP, and must contain a TCPCommand control info object. The method returns NULL if the socket was not found, and throws an error if the message doesn't contain a TCPCommand.
Definition at line 22 of file TCPSocketMap.cc.
Referenced by TCPSrvHostApp::handleMessage(), and LDP::processMessageFromTCP().
{
TCPCommand *ind = dynamic_cast<TCPCommand *>(msg->getControlInfo());
if (!ind)
opp_error("TCPSocketMap: findSocketFor(): no TCPCommand control info in message (not from TCP?)");
int connId = ind->getConnId();
SocketMap::iterator i = socketMap.find(connId);
ASSERT(i==socketMap.end() || i->first==i->second->getConnectionId());
return (i==socketMap.end()) ? NULL : i->second;
}
Removes the given socket from the data structure.
Definition at line 39 of file TCPSocketMap.cc.
Referenced by TCPSrvHostApp::removeThread().
{
SocketMap::iterator i = socketMap.find(socket->getConnectionId());
if (i!=socketMap.end())
socketMap.erase(i);
return socket;
}
| unsigned int TCPSocketMap::size | ( | ) | [inline] |
Returns the number of sockets stored.
Definition at line 71 of file TCPSocketMap.h.
Referenced by TCPSrvHostApp::updateDisplay().
{return socketMap.size();}
SocketMap TCPSocketMap::socketMap [protected] |
Definition at line 36 of file TCPSocketMap.h.
Referenced by addSocket(), deleteSockets(), findSocketFor(), and removeSocket().
1.7.1