TCPSocketMap Class Reference

#include <TCPSocketMap.h>

List of all members.


Detailed Description

Small utility class for managing a large number of TCPSocket objects.

Public Member Functions

 TCPSocketMap ()
 ~TCPSocketMap ()
TCPSocketfindSocketFor (cMessage *msg)
void addSocket (TCPSocket *socket)
TCPSocketremoveSocket (TCPSocket *socket)
unsigned int size ()
void deleteSockets ()

Protected Types

typedef std::map< int,
TCPSocket * > 
SocketMap

Protected Attributes

SocketMap socketMap

Member Typedef Documentation

typedef std::map<int,TCPSocket*> TCPSocketMap::SocketMap [protected]


Constructor & Destructor Documentation

TCPSocketMap::TCPSocketMap (  )  [inline]

Constructor.

00041 {}

TCPSocketMap::~TCPSocketMap (  )  [inline]

Destructor. Does NOT delete the TCPSocket objects.

00046 {}


Member Function Documentation

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.

Referenced by TCPSrvHostApp::handleMessage(), and LDP::processMessageFromTCP().

00023 {
00024     TCPCommand *ind = dynamic_cast<TCPCommand *>(msg->getControlInfo());
00025     if (!ind)
00026         opp_error("TCPSocketMap: findSocketFor(): no TCPCommand control info in message (not from TCP?)");
00027     int connId = ind->getConnId();
00028     SocketMap::iterator i = socketMap.find(connId);
00029     ASSERT(i==socketMap.end() || i->first==i->second->getConnectionId());
00030     return (i==socketMap.end()) ? NULL : i->second;
00031 }

void TCPSocketMap::addSocket ( TCPSocket socket  ) 

Registers the given socket. Should not be called multiple times for one socket object.

Referenced by TCPSrvHostApp::handleMessage(), LDP::openTCPConnectionToPeer(), and LDP::processMessageFromTCP().

00034 {
00035     ASSERT(socketMap.find(socket->getConnectionId())==socketMap.end());
00036     socketMap[socket->getConnectionId()] = socket;
00037 }

TCPSocket * TCPSocketMap::removeSocket ( TCPSocket socket  ) 

Removes the given socket from the data structure.

Referenced by TCPSrvHostApp::removeThread().

00040 {
00041     SocketMap::iterator i = socketMap.find(socket->getConnectionId());
00042     if (i!=socketMap.end())
00043         socketMap.erase(i);
00044     return socket;
00045 }

unsigned int TCPSocketMap::size (  )  [inline]

Returns the number of sockets stored.

Referenced by TCPSrvHostApp::updateDisplay().

00071 {return socketMap.size();}

void TCPSocketMap::deleteSockets (  ) 

Deletes the socket objects.

00048 {
00049     for (SocketMap::iterator i=socketMap.begin(); i!=socketMap.end(); ++i)
00050        delete i->second;
00051 }


Member Data Documentation


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

Generated on Fri Mar 20 18:51:22 2009 for INET Framework for OMNeT++/OMNEST by  doxygen 1.5.5