Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "TCPSegment.h"
00020
00021 Register_Class(TCPSegment);
00022
00023
00024 TCPSegment& TCPSegment::operator=(const TCPSegment& other)
00025 {
00026 TCPSegment_Base::operator=(other);
00027
00028 for (std::list<TCPPayloadMessage>::const_iterator i=other.payloadList.begin(); i!=other.payloadList.end(); ++i)
00029 addPayloadMessage(i->msg->dup(), i->endSequenceNo);
00030
00031 return *this;
00032 }
00033
00034 TCPSegment::~TCPSegment()
00035 {
00036 while (!payloadList.empty())
00037 {
00038 cPacket *msg = payloadList.front().msg;
00039 payloadList.pop_front();
00040 dropAndDelete(msg);
00041 }
00042 }
00043
00044 void TCPSegment::truncateSegment(uint32 firstSeqNo, uint32 endSeqNo)
00045 {
00046 if(seqLess(sequenceNo_var, firstSeqNo))
00047 {
00048 unsigned int truncleft = firstSeqNo - sequenceNo_var;
00049
00050 while (!payloadList.empty())
00051 {
00052 if (seqGE(payloadList.front().endSequenceNo, firstSeqNo))
00053 break;
00054
00055 cPacket *msg = payloadList.front().msg;
00056 payloadList.pop_front();
00057 dropAndDelete(msg);
00058 }
00059
00060 payloadLength_var -= truncleft;
00061 sequenceNo_var = firstSeqNo;
00062
00063 }
00064
00065 if(seqGreater(sequenceNo_var+payloadLength_var, endSeqNo))
00066 {
00067 unsigned int truncright = sequenceNo_var + payloadLength_var - endSeqNo;
00068
00069 while (!payloadList.empty())
00070 {
00071 if (seqLE(payloadList.back().endSequenceNo, endSeqNo))
00072 break;
00073
00074 cPacket *msg = payloadList.back().msg;
00075 payloadList.pop_back();
00076 dropAndDelete(msg);
00077 }
00078 payloadLength_var -= truncright;
00079
00080 }
00081 }
00082
00083 void TCPSegment::parsimPack(cCommBuffer *b)
00084 {
00085 TCPSegment_Base::parsimPack(b);
00086 doPacking(b, payloadList);
00087 }
00088
00089 void TCPSegment::parsimUnpack(cCommBuffer *b)
00090 {
00091 TCPSegment_Base::parsimUnpack(b);
00092 doUnpacking(b, payloadList);
00093 }
00094
00095 void TCPSegment::setPayloadArraySize(unsigned int size)
00096 {
00097 throw cRuntimeError(this, "setPayloadArraySize() not supported, use addPayloadMessage()");
00098 }
00099
00100 unsigned int TCPSegment::getPayloadArraySize() const
00101 {
00102 return payloadList.size();
00103 }
00104
00105 TCPPayloadMessage& TCPSegment::getPayload(unsigned int k)
00106 {
00107 std::list<TCPPayloadMessage>::iterator i = payloadList.begin();
00108 while (k>0 && i!=payloadList.end())
00109 (++i, --k);
00110 return *i;
00111 }
00112
00113 void TCPSegment::setPayload(unsigned int k, const TCPPayloadMessage& payload_var)
00114 {
00115 throw cRuntimeError(this, "setPayload() not supported, use addPayloadMessage()");
00116 }
00117
00118 void TCPSegment::addPayloadMessage(cPacket *msg, uint32 endSequenceNo)
00119 {
00120 take(msg);
00121
00122 TCPPayloadMessage payload;
00123 payload.endSequenceNo = endSequenceNo;
00124 payload.msg = msg;
00125 payloadList.push_back(payload);
00126 }
00127
00128 cPacket *TCPSegment::removeFirstPayloadMessage(uint32& endSequenceNo)
00129 {
00130 if (payloadList.empty())
00131 return NULL;
00132
00133 cPacket *msg = payloadList.front().msg;
00134 endSequenceNo = payloadList.front().endSequenceNo;
00135 payloadList.pop_front();
00136 drop(msg);
00137 return msg;
00138 }
00139