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

#include <TcpClientSocketIo.h>

Inheritance diagram for inet::TcpClientSocketIo:
inet::TcpSocket::ICallback

Public Member Functions

virtual ~TcpClientSocketIo ()
 
virtual void socketDataArrived (TcpSocket *socket, Packet *packet, bool urgent) override
 Notifies about data arrival, packet ownership is transferred to the callee. More...
 
virtual void socketAvailable (TcpSocket *socket, TcpAvailableInfo *availableInfo) override
 
virtual void socketEstablished (TcpSocket *socket) override
 
virtual void socketPeerClosed (TcpSocket *socket) override
 
virtual void socketClosed (TcpSocket *socket) override
 
virtual void socketFailure (TcpSocket *socket, int code) override
 
virtual void socketStatusArrived (TcpSocket *socket, TcpStatusInfo *status) override
 
virtual void socketDeleted (TcpSocket *socket) override
 
- Public Member Functions inherited from inet::TcpSocket::ICallback
virtual ~ICallback ()
 

Protected Member Functions

virtual void handleMessage (cMessage *message) override
 
virtual void open ()
 

Protected Attributes

TcpSocketsocket = nullptr
 

Constructor & Destructor Documentation

◆ ~TcpClientSocketIo()

virtual inet::TcpClientSocketIo::~TcpClientSocketIo ( )
inlinevirtual
25 { delete socket; }

Member Function Documentation

◆ handleMessage()

void inet::TcpClientSocketIo::handleMessage ( cMessage *  message)
overrideprotectedvirtual
33 {
34  if (message->arrivedOn("socketIn")) {
35  ASSERT(socket && socket->belongsToSocket(message));
36  socket->processMessage(message);
37  }
38  else if (message->arrivedOn("trafficIn")) {
39  if (socket == nullptr)
40  open();
41  socket->send(check_and_cast<Packet *>(message));
42  }
43  else
44  throw cRuntimeError("Unknown message");
45 }

◆ open()

void inet::TcpClientSocketIo::open ( )
protectedvirtual
18 {
19  socket = new TcpSocket();
20  socket->setOutputGate(gate("socketOut"));
21  socket->setCallback(this);
22  const char *localAddress = par("localAddress");
23  int localPort = par("localPort");
24  socket->bind(*localAddress ? L3AddressResolver().resolve(localAddress) : L3Address(), localPort);
25  const char *connectAddress = par("connectAddress");
26  int connectPort = par("connectPort");
27  L3Address destination;
28  L3AddressResolver().tryResolve(connectAddress, destination);
29  socket->connect(destination, connectPort);
30 }

Referenced by handleMessage().

◆ socketAvailable()

virtual void inet::TcpClientSocketIo::socketAvailable ( TcpSocket socket,
TcpAvailableInfo availableInfo 
)
inlineoverridevirtual

Implements inet::TcpSocket::ICallback.

28 {}

◆ socketClosed()

virtual void inet::TcpClientSocketIo::socketClosed ( TcpSocket socket)
inlineoverridevirtual

Implements inet::TcpSocket::ICallback.

31 {}

◆ socketDataArrived()

void inet::TcpClientSocketIo::socketDataArrived ( TcpSocket socket,
Packet packet,
bool  urgent 
)
overridevirtual

Notifies about data arrival, packet ownership is transferred to the callee.

Implements inet::TcpSocket::ICallback.

48 {
49  packet->removeTag<SocketInd>();
50  send(packet, "trafficOut");
51 }

◆ socketDeleted()

virtual void inet::TcpClientSocketIo::socketDeleted ( TcpSocket socket)
inlineoverridevirtual

Implements inet::TcpSocket::ICallback.

34 {}

◆ socketEstablished()

virtual void inet::TcpClientSocketIo::socketEstablished ( TcpSocket socket)
inlineoverridevirtual

Implements inet::TcpSocket::ICallback.

29 {}

◆ socketFailure()

virtual void inet::TcpClientSocketIo::socketFailure ( TcpSocket socket,
int  code 
)
inlineoverridevirtual

Implements inet::TcpSocket::ICallback.

32 {}

◆ socketPeerClosed()

virtual void inet::TcpClientSocketIo::socketPeerClosed ( TcpSocket socket)
inlineoverridevirtual

Implements inet::TcpSocket::ICallback.

30 {}

◆ socketStatusArrived()

virtual void inet::TcpClientSocketIo::socketStatusArrived ( TcpSocket socket,
TcpStatusInfo status 
)
inlineoverridevirtual

Implements inet::TcpSocket::ICallback.

33 {}

Member Data Documentation

◆ socket

TcpSocket* inet::TcpClientSocketIo::socket = nullptr
protected

Referenced by handleMessage(), and open().


The documentation for this class was generated from the following files:
inet::TcpSocket::send
virtual void send(Packet *msg) override
Sends data packet.
Definition: TcpSocket.cc:147
inet::TcpSocket::setCallback
void setCallback(ICallback *cb)
Sets a callback object, to be used with processMessage().
Definition: TcpSocket.cc:276
inet::TcpSocket::connect
void connect(L3Address remoteAddr, int remotePort)
Active OPEN to the given remote socket.
Definition: TcpSocket.cc:122
inet::TcpSocket::belongsToSocket
virtual bool belongsToSocket(cMessage *msg) const override
Returns true if the message belongs to this socket instance (message has a TcpCommand as getControlIn...
Definition: TcpSocket.cc:365
inet::TcpClientSocketIo::socket
TcpSocket * socket
Definition: TcpClientSocketIo.h:18
inet::TcpSocket::processMessage
void processMessage(cMessage *msg) override
Examines the message (which should have arrived from TCP), updates socket state, and if there is a ca...
Definition: TcpSocket.cc:281
inet::TcpClientSocketIo::open
virtual void open()
Definition: TcpClientSocketIo.cc:17
inet::TcpSocket::bind
void bind(int localPort)
Bind the socket to a local port number.
Definition: TcpSocket.cc:69
inet::TcpSocket::setOutputGate
void setOutputGate(cGate *toTcp)
Sets the gate on which to send to TCP.
Definition: TcpSocket.h:242