#include <TCPGenericSrvApp.h>
Protected Member Functions | |
| void | sendBack (cMessage *msg) |
| void | sendOrSchedule (cMessage *msg, simtime_t delay) |
| virtual void | initialize () |
| virtual void | handleMessage (cMessage *msg) |
| virtual void | finish () |
Protected Attributes | |
| simtime_t | delay |
| simtime_t | maxMsgDelay |
| long | msgsRcvd |
| long | msgsSent |
| long | bytesRcvd |
| long | bytesSent |
|
|
00137 {
00138 EV << fullPath() << ": sent " << bytesSent << " bytes in " << msgsSent << " packets\n";
00139 EV << fullPath() << ": received " << bytesRcvd << " bytes in " << msgsRcvd << " packets\n";
00140
00141 recordScalar("packets sent", msgsSent);
00142 recordScalar("packets rcvd", msgsRcvd);
00143 recordScalar("bytes sent", bytesSent);
00144 recordScalar("bytes rcvd", bytesRcvd);
00145 }
|
|
|
00060 {
00061 if (msg->isSelfMessage())
00062 {
00063 sendBack(msg);
00064 }
00065 else if (msg->kind()==TCP_I_PEER_CLOSED)
00066 {
00067 // we'll close too, but only after there's surely no message
00068 // pending to be sent back in this connection
00069 msg->setName("close");
00070 msg->setKind(TCP_C_CLOSE);
00071 sendOrSchedule(msg,delay+maxMsgDelay);
00072 }
00073 else if (msg->kind()==TCP_I_DATA || msg->kind()==TCP_I_URGENT_DATA)
00074 {
00075 msgsRcvd++;
00076 bytesRcvd += msg->byteLength();
00077
00078 GenericAppMsg *appmsg = dynamic_cast<GenericAppMsg *>(msg);
00079 if (!appmsg)
00080 error("Message (%s)%s is not a GenericAppMsg -- "
00081 "probably wrong client app, or wrong setting of TCP's "
00082 "sendQueueClass/receiveQueueClass parameters "
00083 "(try \"TCPMsgBasedSendQueue\" and \"TCPMsgBasedRcvQueue\")",
00084 msg->className(), msg->name());
00085
00086 long requestedBytes = appmsg->expectedReplyLength();
00087
00088 simtime_t msgDelay = appmsg->replyDelay();
00089 if (msgDelay>maxMsgDelay)
00090 maxMsgDelay = msgDelay;
00091
00092 bool doClose = appmsg->close();
00093 int connId = check_and_cast<TCPCommand *>(msg->controlInfo())->connId();
00094
00095 if (requestedBytes==0)
00096 {
00097 delete msg;
00098 }
00099 else
00100 {
00101 delete msg->removeControlInfo();
00102 TCPSendCommand *cmd = new TCPSendCommand();
00103 cmd->setConnId(connId);
00104 msg->setControlInfo(cmd);
00105
00106 // set length and send it back
00107 msg->setKind(TCP_C_SEND);
00108 msg->setByteLength(requestedBytes);
00109 sendOrSchedule(msg, delay+msgDelay);
00110 }
00111
00112 if (doClose)
00113 {
00114 cMessage *msg = new cMessage("close");
00115 msg->setKind(TCP_C_CLOSE);
00116 TCPCommand *cmd = new TCPCommand();
00117 cmd->setConnId(connId);
00118 msg->setControlInfo(cmd);
00119 sendOrSchedule(msg, delay+maxMsgDelay);
00120 }
00121 }
00122 else
00123 {
00124 // some indication -- ignore
00125 delete msg;
00126 }
00127
00128 if (ev.isGUI())
00129 {
00130 char buf[64];
00131 sprintf(buf, "rcvd: %ld pks %ld bytes\nsent: %ld pks %ld bytes", msgsRcvd, bytesRcvd, msgsSent, bytesSent);
00132 displayString().setTagArg("t",0,buf);
00133 }
00134 }
|
|
|
00024 {
00025 const char *address = par("address");
00026 int port = par("port");
00027 delay = par("replyDelay");
00028 maxMsgDelay = 0;
00029
00030 msgsRcvd = msgsSent = bytesRcvd = bytesSent = 0;
00031 WATCH(msgsRcvd);
00032 WATCH(msgsSent);
00033 WATCH(bytesRcvd);
00034 WATCH(bytesSent);
00035
00036 TCPSocket socket;
00037 socket.setOutputGate(gate("tcpOut"));
00038 socket.bind(address[0] ? IPvXAddress(address) : IPvXAddress(), port);
00039 socket.listen();
00040 }
|
|
|
00051 {
00052 msgsSent++;
00053 bytesSent += msg->byteLength();
00054
00055 EV << "sending \"" << msg->name() << "\" to TCP, " << msg->byteLength() << " bytes\n";
00056 send(msg, "tcpOut");
00057 }
|
|
||||||||||||
|
00043 {
00044 if (delay==0)
00045 sendBack(msg);
00046 else
00047 scheduleAt(simTime()+delay, msg);
00048 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1.4.1