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

Accepts any number of incoming connections, and discards whatever arrives on them. More...

#include <TCPSinkApp.h>

Inheritance diagram for inet::TCPSinkApp:
inet::ILifecycle

Protected Member Functions

virtual void initialize (int stage) override
 
virtual int numInitStages () const override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void finish () override
 
virtual void refreshDisplay () const override
 
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 

Protected Attributes

long bytesRcvd
 
TCPSocket socket
 

Static Protected Attributes

static simsignal_t rcvdPkSignal = registerSignal("rcvdPk")
 

Additional Inherited Members

- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Detailed Description

Accepts any number of incoming connections, and discards whatever arrives on them.

Member Function Documentation

void inet::TCPSinkApp::finish ( )
overrideprotectedvirtual
76 {
77 }
void inet::TCPSinkApp::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
55 {
56  if (msg->getKind() == TCP_I_PEER_CLOSED) {
57  // we close too
58  msg->setName("close");
59  msg->setKind(TCP_C_CLOSE);
60  send(msg, "tcpOut");
61  }
62  else if (msg->getKind() == TCP_I_DATA || msg->getKind() == TCP_I_URGENT_DATA) {
63  cPacket *pk = PK(msg);
64  long packetLength = pk->getByteLength();
65  bytesRcvd += packetLength;
66  emit(rcvdPkSignal, pk);
67  delete msg;
68  }
69  else {
70  // must be data or some kind of indication -- can be dropped
71  delete msg;
72  }
73 }
Definition: TCPCommand_m.h:101
Definition: TCPCommand_m.h:99
long bytesRcvd
Definition: TCPSinkApp.h:35
Definition: TCPCommand_m.h:64
#define PK(msg)
Definition: INETDefs.h:92
static simsignal_t rcvdPkSignal
Definition: TCPSinkApp.h:39
Definition: TCPCommand_m.h:98
virtual bool inet::TCPSinkApp::handleOperationStage ( LifecycleOperation operation,
int  stage,
IDoneCallback doneCallback 
)
inlineoverrideprotectedvirtual

Perform one stage of a lifecycle operation.

Processing may be done entirely within this method, or may be a longer process that involves nonzero simulation time or several events, and is triggered by this method call.

Return value: true = "done"; false = "not yet done, will invoke doneCallback when done"

Implements inet::ILifecycle.

48  { Enter_Method_Silent(); throw cRuntimeError("Unsupported lifecycle operation '%s'", operation->getClassName()); return true; }
void inet::TCPSinkApp::initialize ( int  stage)
overrideprotectedvirtual
31 {
32  cSimpleModule::initialize(stage);
33 
34  if (stage == INITSTAGE_LOCAL) {
35  bytesRcvd = 0;
36  WATCH(bytesRcvd);
37  }
38  else if (stage == INITSTAGE_APPLICATION_LAYER) {
39  bool isOperational;
40  NodeStatus *nodeStatus = dynamic_cast<NodeStatus *>(findContainingNode(this)->getSubmodule("status"));
41  isOperational = (!nodeStatus) || nodeStatus->getState() == NodeStatus::UP;
42  if (!isOperational)
43  throw cRuntimeError("This module doesn't support starting in node DOWN state");
44 
45  const char *localAddress = par("localAddress");
46  int localPort = par("localPort");
47  socket.setOutputGate(gate("tcpOut"));
49  socket.bind(localAddress[0] ? L3AddressResolver().resolve(localAddress) : L3Address(), localPort);
50  socket.listen();
51  }
52 }
TCPSocket socket
Definition: TCPSinkApp.h:36
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:56
void bind(int localPort)
Bind the socket to a local port number.
Definition: TCPSocket.cc:101
Local initializations.
Definition: InitStages.h:35
long bytesRcvd
Definition: TCPSinkApp.h:35
void listen(bool fork)
Definition: TCPSocket.cc:127
void setOutputGate(cGate *toTcp)
Sets the gate on which to send to TCP.
Definition: TCPSocket.h:228
void readDataTransferModePar(cComponent &component)
Read "dataTransferMode" parameter from ini/ned, and set dataTransferMode member value.
Definition: TCPSocket.cc:355
Initialization of applications.
Definition: InitStages.h:106
Definition: NodeStatus.h:40
virtual int inet::TCPSinkApp::numInitStages ( ) const
inlineoverrideprotectedvirtual
42 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::TCPSinkApp::refreshDisplay ( ) const
overrideprotectedvirtual
80 {
81  std::ostringstream os;
82  os << TCPSocket::stateName(socket.getState()) << "\nrcvd: " << bytesRcvd << " bytes";
83  getDisplayString().setTagArg("t", 0, os.str().c_str());
84 }
TCPSocket socket
Definition: TCPSinkApp.h:36
static const char * stateName(int state)
Returns name of socket state code returned by getState().
Definition: TCPSocket.cc:73
long bytesRcvd
Definition: TCPSinkApp.h:35
int getState() const
Returns the socket state, one of NOT_BOUND, CLOSED, LISTENING, CONNECTING, CONNECTED, etc.
Definition: TCPSocket.h:204

Member Data Documentation

long inet::TCPSinkApp::bytesRcvd
protected
simsignal_t inet::TCPSinkApp::rcvdPkSignal = registerSignal("rcvdPk")
staticprotected

Referenced by handleMessage().

TCPSocket inet::TCPSinkApp::socket
protected

Referenced by initialize(), and refreshDisplay().


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