INET Framework for OMNeT++/OMNEST
queues/TCPMsgBasedRcvQueue.cc
Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2004 Andras Varga
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU Lesser General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU Lesser General Public License
00015 // along with this program; if not, see <http://www.gnu.org/licenses/>.
00016 //
00017 
00018 
00019 #include "TCPMsgBasedRcvQueue.h"
00020 
00021 Register_Class(TCPMsgBasedRcvQueue);
00022 
00023 
00024 TCPMsgBasedRcvQueue::TCPMsgBasedRcvQueue() : TCPVirtualDataRcvQueue()
00025 {
00026 }
00027 
00028 TCPMsgBasedRcvQueue::~TCPMsgBasedRcvQueue()
00029 {
00030 }
00031 
00032 void TCPMsgBasedRcvQueue::init(uint32 startSeq)
00033 {
00034     TCPVirtualDataRcvQueue::init(startSeq);
00035 }
00036 
00037 std::string TCPMsgBasedRcvQueue::info() const
00038 {
00039     std::stringstream os;
00040 
00041     os << "rcv_nxt=" << rcv_nxt;
00042 
00043     for (RegionList::const_iterator i = regionList.begin(); i != regionList.end(); ++i)
00044     {
00045         os << " [" << i->begin << ".." << i->end << ")";
00046     }
00047 
00048     os << " " << payloadList.size() << " msgs";
00049 
00050     return os.str();
00051 }
00052 
00053 uint32 TCPMsgBasedRcvQueue::insertBytesFromSegment(TCPSegment *tcpseg)
00054 {
00055     TCPVirtualDataRcvQueue::insertBytesFromSegment(tcpseg);
00056 
00057     cPacket *msg;
00058     uint32 endSeqNo;
00059     while ((msg=tcpseg->removeFirstPayloadMessage(endSeqNo))!=NULL)
00060     {
00061         // insert, avoiding duplicates
00062         PayloadList::iterator i = payloadList.find(endSeqNo);
00063         if (i!=payloadList.end()) {delete msg; continue;}
00064         payloadList[endSeqNo] = msg;
00065     }
00066 
00067     return rcv_nxt;
00068 }
00069 
00070 cPacket *TCPMsgBasedRcvQueue::extractBytesUpTo(uint32 seq)
00071 {
00072     extractTo(seq);
00073 
00074     // pass up payload messages, in sequence number order
00075     if (payloadList.empty() || seqGreater(payloadList.begin()->first, seq))
00076         return NULL;
00077 
00078     cPacket *msg = payloadList.begin()->second;
00079     payloadList.erase(payloadList.begin());
00080     return msg;
00081 }
00082