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

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

#include <SocketMap.h>

Public Member Functions

 SocketMap ()
 
 ~SocketMap ()
 Destructor does NOT delete the socket objects. More...
 
ISocketfindSocketFor (cMessage *msg)
 Finds the socket for the given message. More...
 
void addSocket (ISocket *socket)
 Adds the given socket. More...
 
ISocketremoveSocket (ISocket *socket)
 Removes the given socket. More...
 
unsigned int size () const
 Returns the number of sockets stored. More...
 
std::map< int, ISocket * > & getMap ()
 Returns the socket map. More...
 
ISocketgetSocketById (unsigned int socketId)
 Returns the socket specified by socketId. More...
 
void deleteSockets ()
 Deletes the socket objects. More...
 
void addWatch ()
 

Protected Attributes

std::map< int, ISocket * > socketMap
 

Detailed Description

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

Constructor & Destructor Documentation

◆ SocketMap()

inet::SocketMap::SocketMap ( )
inline
26 {}

◆ ~SocketMap()

inet::SocketMap::~SocketMap ( )
inline

Destructor does NOT delete the socket objects.

31 {}

Member Function Documentation

◆ addSocket()

◆ addWatch()

void inet::SocketMap::addWatch ( )
52 {
53  WATCH_PTRMAP(socketMap);
54 }

Referenced by inet::bgp::BgpRouter::addWatches().

◆ deleteSockets()

void inet::SocketMap::deleteSockets ( )

◆ findSocketFor()

ISocket * inet::SocketMap::findSocketFor ( cMessage *  msg)

Finds the socket for the given message.

20 {
21  auto& tags = check_and_cast<ITaggedObject *>(msg)->getTags();
22  int connId = tags.getTag<SocketInd>()->getSocketId();
23  auto i = socketMap.find(connId);
24  ASSERT(i == socketMap.end() || i->first == i->second->getSocketId());
25  return (i == socketMap.end()) ? nullptr : i->second;
26 }

Referenced by inet::TcpServerHostApp::handleMessageWhenUp(), inet::TunnelApp::handleMessageWhenUp(), inet::PingApp::handleMessageWhenUp(), inet::Ldp::handleMessageWhenUp(), and inet::bgp::BgpRouter::processMessageFromTCP().

◆ getMap()

◆ getSocketById()

ISocket* inet::SocketMap::getSocketById ( unsigned int  socketId)
inline

Returns the socket specified by socketId.

62 { return socketMap.at(socketId); }

◆ removeSocket()

ISocket * inet::SocketMap::removeSocket ( ISocket socket)

Removes the given socket.

Returns removed socket or returns nullptr when socket not found in the map

35 {
36  auto i = socketMap.find(socket->getSocketId());
37  if (i != socketMap.end()) {
38  socketMap.erase(i);
39  return socket;
40  }
41  return nullptr;
42 }

Referenced by inet::bgp::BgpRouter::listenConnectionFromPeer(), inet::bgp::BgpRouter::openTCPConnectionToPeer(), inet::bgp::BgpRouter::processMessageFromTCP(), inet::TcpServerHostApp::removeThread(), inet::PingApp::socketClosed(), inet::TcpServerHostApp::socketDeleted(), and inet::TcpServerHostApp::threadClosed().

◆ size()

unsigned int inet::SocketMap::size ( ) const
inline

Member Data Documentation

◆ socketMap

std::map<int, ISocket *> inet::SocketMap::socketMap
protected

The documentation for this class was generated from the following files:
connId
az accept haszálja pcb új connId
Definition: lwip_tcp.txt:42
tags
* tags
Definition: IUdp-gates.txt:3
inet::SocketMap::socketMap
std::map< int, ISocket * > socketMap
Definition: SocketMap.h:23
inet::containsKey
bool containsKey(const std::map< K, V, _C > &m, const Tk &a)
Definition: stlutils.h:80