Implement GetRxAvailable ()

This commit is contained in:
Tom Henderson
2008-05-02 10:55:07 -07:00
parent bfe0533aa3
commit daddd90d07
7 changed files with 59 additions and 8 deletions

View File

@@ -29,7 +29,7 @@ NS_LOG_COMPONENT_DEFINE ("PacketSocket");
namespace ns3 {
PacketSocket::PacketSocket ()
PacketSocket::PacketSocket () : m_rxAvailable (0)
{
NS_LOG_FUNCTION_NOARGS ();
m_state = STATE_OPEN;
@@ -305,6 +305,7 @@ PacketSocket::ForwardUp (Ptr<NetDevice> device, Ptr<Packet> packet,
tag.SetAddress (address);
packet->AddTag (tag);
m_deliveryQueue.push (packet);
m_rxAvailable += packet->GetSize ();
NS_LOG_LOGIC ("UID is " << packet->GetUid() << " PacketSocket " << this);
NotifyDataRecv ();
}
@@ -317,9 +318,10 @@ PacketSocket::Recv (uint32_t maxSize, uint32_t flags)
return 0;
}
Ptr<Packet> p = m_deliveryQueue.front ();
if (p->GetSize() <= maxSize)
if (p->GetSize () <= maxSize)
{
m_deliveryQueue.pop ();
m_rxAvailable -= p->GetSize ();
}
else
{
@@ -328,4 +330,12 @@ PacketSocket::Recv (uint32_t maxSize, uint32_t flags)
return p;
}
uint32_t
PacketSocket::GetRxAvailable (void) const
{
// We separately maintain this state to avoid walking the queue
// every time this might be called
return m_rxAvailable;
}
}//namespace ns3

View File

@@ -89,6 +89,7 @@ public:
virtual int SendTo(const Address &address,Ptr<Packet> p);
virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
virtual uint32_t GetRxAvailable (void) const;
private:
@@ -114,6 +115,8 @@ private:
Address m_destAddr; /// Default destination address
std::queue<Ptr<Packet> > m_deliveryQueue;
uint32_t m_rxAvailable;
};
}//namespace ns3

View File

@@ -273,7 +273,13 @@ public:
* 0 if the socket cannot return a next in-sequence packet.
*/
Ptr<Packet> Recv (void);
/**
* Return number of bytes which can be returned from one or
* multiple calls to Recv.
* Must be possible to call this method from the Recv callback.
*/
virtual uint32_t GetRxAvailable (void) const = 0;
protected:
void NotifyCloseCompleted (void);
void NotifyConnectionSucceeded (void);