INET Framework for OMNeT++/OMNEST
inet::TCPSocketMap Class Reference

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

#include <TCPSocketMap.h>

Public Member Functions

 TCPSocketMap ()
 Constructor. More...
 
 ~TCPSocketMap ()
 Destructor. More...
 
TCPSocketfindSocketFor (cMessage *msg)
 Finds the socket (by connId) for the given message. More...
 
void addSocket (TCPSocket *socket)
 Registers the given socket. More...
 
TCPSocketremoveSocket (TCPSocket *socket)
 Removes the given socket from the data structure. More...
 
unsigned int size () const
 Returns the number of sockets stored. More...
 
void deleteSockets ()
 Deletes the socket objects. More...
 

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.

Member Typedef Documentation

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

Constructor & Destructor Documentation

inet::TCPSocketMap::TCPSocketMap ( )
inline

Constructor.

43 {}
inet::TCPSocketMap::~TCPSocketMap ( )
inline

Destructor.

Does NOT delete the TCPSocket objects.

48 {}

Member Function Documentation

void inet::TCPSocketMap::addSocket ( TCPSocket socket)

Registers the given socket.

Should not be called multiple times for one socket object.

Referenced by inet::TCPSrvHostApp::handleMessage(), inet::httptools::HttpServer::handleMessage(), inet::bgp::BGPRouting::openTCPConnectionToPeer(), inet::LDP::openTCPConnectionToPeer(), inet::bgp::BGPRouting::processMessageFromTCP(), inet::LDP::processMessageFromTCP(), and inet::httptools::HttpBrowser::submitToSocket().

37 {
38  ASSERT(socketMap.find(socket->getConnectionId()) == socketMap.end());
39  socketMap[socket->getConnectionId()] = socket;
40 }
SocketMap socketMap
Definition: TCPSocketMap.h:37
void inet::TCPSocketMap::deleteSockets ( )

Deletes the socket objects.

Referenced by inet::httptools::HttpServer::finish(), and inet::httptools::HttpBrowser::~HttpBrowser().

51 {
52  for (auto & elem : socketMap)
53  delete elem.second;
54  socketMap.clear();
55 }
SocketMap socketMap
Definition: TCPSocketMap.h:37
TCPSocket * inet::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 nullptr if the socket was not found, and throws an error if the message doesn't contain a TCPCommand.

Referenced by inet::TCPSrvHostApp::handleMessage(), inet::httptools::HttpServer::handleMessage(), inet::httptools::HttpBrowser::handleMessage(), inet::bgp::BGPRouting::processMessageFromTCP(), and inet::LDP::processMessageFromTCP().

25 {
26  TCPCommand *ind = dynamic_cast<TCPCommand *>(msg->getControlInfo());
27  if (!ind)
28  throw cRuntimeError("TCPSocketMap: findSocketFor(): no TCPCommand control info in message (not from TCP?)");
29 
30  int connId = ind->getConnId();
31  auto i = socketMap.find(connId);
32  ASSERT(i == socketMap.end() || i->first == i->second->getConnectionId());
33  return (i == socketMap.end()) ? nullptr : i->second;
34 }
az accept haszálja pcb új connId
Definition: lwip_tcp.txt:38
SocketMap socketMap
Definition: TCPSocketMap.h:37
TCPSocket * inet::TCPSocketMap::removeSocket ( TCPSocket socket)

Removes the given socket from the data structure.

Referenced by inet::bgp::BGPRouting::listenConnectionFromPeer(), inet::bgp::BGPRouting::openTCPConnectionToPeer(), inet::TCPSrvHostApp::removeThread(), inet::httptools::HttpServer::socketClosed(), inet::httptools::HttpBrowser::socketClosed(), inet::httptools::HttpServer::socketFailure(), and inet::httptools::HttpBrowser::socketFailure().

43 {
44  auto i = socketMap.find(socket->getConnectionId());
45  if (i != socketMap.end())
46  socketMap.erase(i);
47  return socket;
48 }
SocketMap socketMap
Definition: TCPSocketMap.h:37
unsigned int inet::TCPSocketMap::size ( ) const
inline

Returns the number of sockets stored.

Referenced by inet::TCPSrvHostApp::refreshDisplay().

73 { return socketMap.size(); }
SocketMap socketMap
Definition: TCPSocketMap.h:37

Member Data Documentation

SocketMap inet::TCPSocketMap::socketMap
protected

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