Public Member Functions | Protected Types | Protected Attributes

TCPSocketMap Class Reference

#include <TCPSocketMap.h>

List of all members.

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

Detailed Description

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

Definition at line 32 of file TCPSocketMap.h.


Member Typedef Documentation

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

Definition at line 35 of file TCPSocketMap.h.


Constructor & Destructor Documentation

TCPSocketMap::TCPSocketMap (  )  [inline]

Constructor.

Definition at line 41 of file TCPSocketMap.h.

{}

TCPSocketMap::~TCPSocketMap (  )  [inline]

Destructor. Does NOT delete the TCPSocket objects.

Definition at line 46 of file TCPSocketMap.h.

{}


Member Function Documentation

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.

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

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;
}

TCPSocket * TCPSocketMap::removeSocket ( TCPSocket socket  ) 

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();}


Member Data Documentation

Definition at line 36 of file TCPSocketMap.h.

Referenced by addSocket(), deleteSockets(), findSocketFor(), and removeSocket().


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