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

Example server thread, to be used with TcpServerHostApp. More...

#include <TcpGenericServerThread.h>

Inheritance diagram for inet::TcpGenericServerThread:
inet::TcpServerThreadBase inet::TcpSocket::ICallback

Public Member Functions

 TcpGenericServerThread ()
 
virtual void established () override
 Called when connection is established. More...
 
virtual void dataArrived (Packet *msg, bool urgent) override
 
virtual void timerExpired (cMessage *timer) override
 
- Public Member Functions inherited from inet::TcpServerThreadBase
 TcpServerThreadBase ()
 
virtual ~TcpServerThreadBase ()
 
virtual void init (TcpServerHostApp *hostmodule, TcpSocket *socket)
 
virtual TcpSocketgetSocket ()
 
virtual TcpServerHostAppgetHostModule ()
 
virtual void peerClosed ()
 
virtual void failure (int code)
 
virtual void statusArrived (TcpStatusInfo *status)
 
- Public Member Functions inherited from inet::TcpSocket::ICallback
virtual ~ICallback ()
 

Additional Inherited Members

- Protected Member Functions inherited from inet::TcpServerThreadBase
virtual void socketDataArrived (TcpSocket *socket, Packet *msg, 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
 
virtual void refreshDisplay () const override
 
- Protected Attributes inherited from inet::TcpServerThreadBase
TcpServerHostApphostmod
 
TcpSocketsock
 

Detailed Description

Example server thread, to be used with TcpServerHostApp.

Constructor & Destructor Documentation

◆ TcpGenericServerThread()

inet::TcpGenericServerThread::TcpGenericServerThread ( )
inline
22 {}

Member Function Documentation

◆ dataArrived()

void inet::TcpGenericServerThread::dataArrived ( Packet msg,
bool  urgent 
)
overridevirtual

Implements inet::TcpServerThreadBase.

24 {
25  const auto& appmsg = msg->peekData<GenericAppMsg>();
26 
27  if (!appmsg)
28  throw cRuntimeError("Message (%s)%s is not a GenericAppMsg -- probably wrong client app",
29  msg->getClassName(), msg->getName());
30 
31  if (appmsg->getReplyDelay() > 0)
32  throw cRuntimeError("Cannot process (%s)%s: %s class doesn't support replyDelay field"
33  " of GenericAppMsg, try to use TcpGenericServerApp instead",
34  msg->getClassName(), msg->getName(), getClassName());
35 
36  // process message: send back requested number of bytes, then close
37  // connection if that was requested too
38  B requestedBytes = appmsg->getExpectedReplyLength();
39  bool doClose = appmsg->getServerClose();
40 
41  if (requestedBytes > B(0)) {
42  Packet *outPacket = new Packet(msg->getName());
43  const auto& payload = makeShared<ByteCountChunk>(requestedBytes);
44  payload->addTag<CreationTimeTag>()->setCreationTime(simTime());
45  outPacket->insertAtBack(payload);
46  getSocket()->send(outPacket);
47  }
48 
49  if (doClose)
50  getSocket()->close();
51  delete msg;
52 }

◆ established()

void inet::TcpGenericServerThread::established ( )
overridevirtual

Called when connection is established.

To be redefined.

Implements inet::TcpServerThreadBase.

19 {
20  // no initialization needed
21 }

◆ timerExpired()

void inet::TcpGenericServerThread::timerExpired ( cMessage *  timer)
overridevirtual

Implements inet::TcpServerThreadBase.

55 {
56  // no timers in this serverThread
57 }

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::units::units::B
intscale< b, 1, 8 > B
Definition: Units.h:1168
inet::TcpServerThreadBase::getSocket
virtual TcpSocket * getSocket()
Definition: TcpServerHostApp.h:95
inet::TcpSocket::close
void close() override
Closes the local end of the connection.
Definition: TcpSocket.cc:161