TCPGenericSrvThread.cc

Go to the documentation of this file.
00001 //
00002 // Copyright 2004 Andras Varga
00003 //
00004 // This library is free software, you can redistribute it and/or modify
00005 // it under  the terms of the GNU Lesser General Public License
00006 // as published by the Free Software Foundation;
00007 // either version 2 of the License, or any later version.
00008 // The library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00011 // See the GNU Lesser General Public License for more details.
00012 //
00013 
00014 
00015 #include "TCPGenericSrvThread.h"
00016 #include "GenericAppMsg_m.h"
00017 
00018 
00019 
00020 Register_Class(TCPGenericSrvThread);
00021 
00022 
00023 void TCPGenericSrvThread::established()
00024 {
00025     // no initialization needed
00026 }
00027 
00028 void TCPGenericSrvThread::dataArrived(cMessage *msg, bool)
00029 {
00030     GenericAppMsg *appmsg = dynamic_cast<GenericAppMsg *>(msg);
00031     if (!appmsg)
00032         opp_error("Message (%s)%s is not a GenericAppMsg -- "
00033                   "probably wrong client app, or wrong setting of TCP's "
00034                   "sendQueueClass/receiveQueueClass parameters "
00035                   "(try \"TCPMsgBasedSendQueue\" and \"TCPMsgBasedRcvQueue\")",
00036                   msg->getClassName(), msg->getName());
00037     if (appmsg->getReplyDelay()>0)
00038         opp_error("Cannot process (%s)%s: %s class doesn't support replyDelay field"
00039                   " of GenericAppMsg, try to use TCPGenericSrvApp instead",
00040                   msg->getClassName(), msg->getName(), getClassName());
00041 
00042     // process message: send back requested number of bytes, then close
00043     // connection if that was requested too
00044     long requestedBytes = appmsg->getExpectedReplyLength();
00045     bool doClose = appmsg->getServerClose();
00046 
00047     if (requestedBytes==0)
00048     {
00049         delete appmsg;
00050     }
00051     else
00052     {
00053         appmsg->setByteLength(requestedBytes);
00054         delete appmsg->removeControlInfo();
00055         getSocket()->send(appmsg);
00056     }
00057 
00058     if (doClose)
00059     {
00060         getSocket()->close();
00061     }
00062 }
00063 
00064 void TCPGenericSrvThread::timerExpired(cMessage *timer)
00065 {
00066     // no timers in this serverThread
00067 }
00068 
00069