# HG changeset patch # User Tom Henderson # Date 1203057346 28800 # Node ID 64ed82ae5014f7a31bb2034b4bd7679b35b7b7d2 # Parent 1021234da54ee62194f3a19042ad36229a93ce97 reassign previous SendCallback to new DataSent callback; break infinite recursion on sending diff -r 1021234da54e -r 64ed82ae5014 src/internet-node/tcp-socket.cc --- a/src/internet-node/tcp-socket.cc Thu Feb 14 19:01:01 2008 +0000 +++ b/src/internet-node/tcp-socket.cc Thu Feb 14 22:35:46 2008 -0800 @@ -752,11 +752,13 @@ bool TcpSocket::SendPendingData (bool wi m_tcp->SendPacket (p, header, m_endPoint->GetLocalAddress (), m_defaultAddress); - m_rtt->SentSeq(m_nextTxSequence, sz); // notify the RTT - NotifyDataSent (p->GetSize () ); // notify the application - nPacketsSent++; // Count sent this loop - m_nextTxSequence += sz; // Advance next tx sequence - m_highTxMark = std::max (m_nextTxSequence, m_highTxMark);// Note the high water mark + m_rtt->SentSeq(m_nextTxSequence, sz); // notify the RTT + // Notify the application + Simulator::ScheduleNow(&TcpSocket::NotifyDataSent, this, p->GetSize ()); + nPacketsSent++; // Count sent this loop + m_nextTxSequence += sz; // Advance next tx sequence + // Note the high water mark + m_highTxMark = std::max (m_nextTxSequence, m_highTxMark); } NS_LOG_LOGIC ("Sent "<, uint32_t> dataSent) +bool +Socket::SetDataSentCallback (Callback, uint32_t> dataSent) { NS_LOG_FUNCTION; m_dataSent = dataSent; + return true; +} + +void +Socket::SetSendCallback (Callback > sendCb) +{ + NS_LOG_FUNCTION; + m_sendCb = sendCb; } void @@ -200,6 +208,16 @@ Socket::NotifyDataSent (uint32_t size) } void +Socket::NotifySend (void) +{ + NS_LOG_FUNCTION; + if (!m_sendCb.IsNull ()) + { + m_sendCb (this); + } +} + +void Socket::NotifyDataReceived (Ptr p, const Address &from) { NS_LOG_FUNCTION; diff -r 1021234da54e -r 64ed82ae5014 src/node/socket.h --- a/src/node/socket.h Thu Feb 14 19:01:01 2008 +0000 +++ b/src/node/socket.h Thu Feb 14 22:35:46 2008 -0800 @@ -120,7 +120,27 @@ public: Callback, const Address&> newConnectionCreated, Callback > closeRequested); - void SetSendCallback (Callback, uint32_t> dataSent); + /** + * \brief Notify application when a packet has been sent from transport + * protocol (non-standard socket call) + * \param dataSent Callback for the event that data is sent from the + * underlying transport protocol. This callback is passed a + * pointer to the socket, and the number of bytes sent. + * + * \returns whether or not this socket supports this callback. Note + * that this is a non-standard socket call. Some socket + * implementations in ns-3 may not support this call, so the + * user should check this return value to confirm that the + * callback is supported. + */ + virtual bool SetDataSentCallback (Callback, uint32_t> dataSent); + /** + * \brief Notify application when a previously blocked socket (blocked + * for writing) has unblocked and has space available + * \param sendCb Callback for the event that the socket becomes + * unblocked for sending + */ + void SetSendCallback (Callback > sendCb); /** * \brief Receive data * \param receivedData Invoked whenever new data is received. @@ -232,6 +252,7 @@ protected: void NotifyNewConnectionCreated (Ptr socket, const Address &from); void NotifyCloseRequested (void); void NotifyDataSent (uint32_t size); + void NotifySend (void); void NotifyDataReceived (Ptr p, const Address &from); Callback > m_closeCompleted; @@ -242,6 +263,7 @@ protected: Callback, const Address &> m_connectionRequest; Callback, const Address&> m_newConnectionCreated; Callback, uint32_t> m_dataSent; + Callback > m_sendCb; Callback, Ptr,const Address&> m_receivedData; };