Index: src/internet/model/tcp-socket-base.cc =================================================================== --- src/internet/model/tcp-socket-base.cc (revision 1027) +++ src/internet/model/tcp-socket-base.cc (working copy) @@ -1928,19 +1928,16 @@ m_errno = ERROR_SHUTDOWN; return false; } - // Stop sending if we need to wait for a larger Tx window (prevent silly window syndrome) - if (w < m_segmentSize && m_txBuffer.SizeFromSequence (m_nextTxSequence) > w) - { - break; // No more - } + + if (w == 0) break; // window empty + // Nagle's algorithm (RFC896): Hold off sending if there is unacked data - // in the buffer and the amount of data to send is less than one segment - if (!m_noDelay && UnAckDataCount () > 0 - && m_txBuffer.SizeFromSequence (m_nextTxSequence) < m_segmentSize) - { - NS_LOG_LOGIC ("Invoking Nagle's algorithm. Wait to send."); - break; - } + // in the buffer and the amount of data to send or the window size is + // less than one segment + if (m_txBuffer.SizeFromSequence (m_nextTxSequence) < m_segmentSize || w < m_segmentSize ) + if (UnAckDataCount () > 0) + break; + uint32_t s = std::min (w, m_segmentSize); // Send no more than window uint32_t sz = SendDataPacket (m_nextTxSequence, s, withAck); nPacketsSent++; // Count sent this loop @@ -1984,7 +1981,10 @@ uint16_t TcpSocketBase::AdvertisedWindowSize () { - return std::min (m_rxBuffer.MaxBufferSize () - m_rxBuffer.Size (), (uint32_t)m_maxWinSize); + uint16_t w = std::min (m_rxBuffer.MaxBufferSize () - m_rxBuffer.Size (), (uint32_t)m_maxWinSize); + // Clark's algorithm (RFC813): close window when the buffer space is smaller + // than an MSS and smaller than its half capacity + return (w < m_segmentSize && w < m_rxBuffer.MaxBufferSize ()/2 ) ? 0 : w; } // Receipt of new packet, put into Rx buffer