Bug 829 - TCP unbound memory problem (pending data)

This commit is contained in:
Josh Pelkey
2010-03-27 19:09:18 -04:00
parent d68f49a0f2
commit 0ee8bf099f
3 changed files with 47 additions and 0 deletions

View File

@@ -220,4 +220,36 @@ Ptr<Packet> PendingData::CopyFromSeq (uint32_t s, const SequenceNumber& f, const
NS_LOG_FUNCTION (this << s << f << o);
return CopyFromOffset (s, OffsetFromSeq(f,o));
}
uint32_t
PendingData::RemoveToSeq (const SequenceNumber& seqFront, const SequenceNumber& seqOffset)
{
NS_LOG_FUNCTION (this << seqFront << seqOffset);
uint32_t count = OffsetFromSeq (seqFront, seqOffset);
NS_ASSERT_MSG (count <= size, "Trying to remove more data than in the buffer");
if (count == size)
{
Clear ();
return size;
}
// Remove whole packets, if possible, from the front of the data
// Do not perform buffer manipulations within packet; if a whole packet
// cannot be removed, leave it alone
std::vector<Ptr<Packet> >::iterator endI = data.begin ();
uint32_t current = 0;
// Any packet whose data has been completely acked can be removed
for (std::vector<Ptr<Packet> >::iterator dataI = data.begin (); dataI < data.end (); dataI++)
{
if (current + (*dataI)->GetSize () > count)
{
break;
}
current += (*dataI)->GetSize ();
++endI;
}
data.erase (data.begin (), endI);
size -= current;
return current;
}
}//namepsace ns3

View File

@@ -92,6 +92,16 @@ public:
virtual Ptr<Packet> CopyFromOffset (uint32_t, uint32_t); // Size, offset, ret packet
// Copy data, size, offset specified by sequence difference
virtual Ptr<Packet> CopyFromSeq (uint32_t, const SequenceNumber&, const SequenceNumber&);
/**
* Permits object to clear any pending data between seqFront and
* seqOffset - 1). Callers should check the return value to determine
* whether any data was removed from the front.
*
* \param seqFront sequence number to start to try to remove from
* \param seqOffset first sequence number in buffer that should be retained
* \return number of bytes from the front that were removed from the buffer
*/
virtual uint32_t RemoveToSeq (const SequenceNumber& seqFront, const SequenceNumber& seqOffset);
PendingData* Copy () const; // Create a copy of this header
PendingData* CopyS (uint32_t); // Copy with new size
PendingData* CopySD (uint32_t, uint8_t*); // Copy with new size, new data

View File

@@ -1511,6 +1511,11 @@ void TcpSocketImpl::CommonNewAck (SequenceNumber ack, bool skipTimer)
Simulator::GetDelayLeft (m_retxEvent)).GetSeconds());
m_retxEvent.Cancel ();
}
else if (m_pendingData->SizeFromSeq (m_firstPendingSequence, m_highestRxAck) > 0)
{
// Remove from front, if possible
m_firstPendingSequence += m_pendingData->RemoveToSeq (m_firstPendingSequence, m_highestRxAck);
}
}
// Try to send more data
SendPendingData (m_connected);