@@ -623,7 +623,7 @@ struct utp_socket_impl
623623 // this is done at startup of a socket in order to find its
624624 // link capacity faster. This behaves similar to TCP slow start
625625 bool m_slow_start:1 ;
626-
626+
627627 // this is true as long as we have as many packets in
628628 // flight as allowed by the congestion window (cwnd)
629629 bool m_cwnd_full:1 ;
@@ -1602,7 +1602,9 @@ struct holder
16021602// congestion window, false if there is no more space.
16031603bool utp_socket_impl::send_pkt (int flags)
16041604{
1605+ #ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS
16051606 INVARIANT_CHECK ;
1607+ #endif
16061608
16071609 bool force = (flags & pkt_ack) || (flags & pkt_fin);
16081610
@@ -2144,29 +2146,33 @@ void utp_socket_impl::experienced_loss(int seq_nr)
21442146 // less than or equal to. If we experience loss of the
21452147 // same packet again, ignore it.
21462148 if (compare_less_wrap (seq_nr, m_loss_seq_nr + 1 , ACK_MASK )) return ;
2147-
2149+
2150+ // cut window size in 2
2151+ m_cwnd = (std::max)(m_cwnd * m_sm->loss_multiplier () / 100 , boost::int64_t (m_mtu << 16 ));
2152+ m_loss_seq_nr = m_seq_nr;
2153+ UTP_LOGV (" %8p: Lost packet %d caused cwnd cut\n " , this , seq_nr);
2154+
21482155 // if we happen to be in slow-start mode, we need to leave it
2156+ // note that we set ssthres to the window size _after_ reducing it. Next slow
2157+ // start should end before we over shoot.
21492158 if (m_slow_start)
21502159 {
21512160 m_ssthres = m_cwnd >> 16 ;
21522161 m_slow_start = false ;
21532162 UTP_LOGV (" %8p: experienced loss, slow_start -> 0\n " , this );
21542163 }
21552164
2156- // cut window size in 2
2157- m_cwnd = (std::max)(m_cwnd * m_sm->loss_multiplier () / 100 , boost::int64_t (m_mtu << 16 ));
2158- m_loss_seq_nr = m_seq_nr;
2159- UTP_LOGV (" %8p: Lost packet %d caused cwnd cut\n " , this , seq_nr);
2160-
21612165 // the window size could go below one MMS here, if it does,
21622166 // we'll get a timeout in about one second
2163-
2167+
21642168 m_sm->inc_stats_counter (utp_socket_manager::packet_loss);
21652169}
21662170
21672171void utp_socket_impl::maybe_inc_acked_seq_nr ()
21682172{
2173+ #ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS
21692174 INVARIANT_CHECK ;
2175+ #endif
21702176
21712177 bool incremented = false ;
21722178 // don't pass m_seq_nr, since we move into sequence
@@ -2198,7 +2204,9 @@ void utp_socket_impl::maybe_inc_acked_seq_nr()
21982204void utp_socket_impl::ack_packet (packet* p, ptime const & receive_time
21992205 , boost::uint32_t & min_rtt, boost::uint16_t seq_nr)
22002206{
2207+ #ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS
22012208 INVARIANT_CHECK ;
2209+ #endif
22022210
22032211 TORRENT_ASSERT (p);
22042212
@@ -2244,7 +2252,9 @@ void utp_socket_impl::ack_packet(packet* p, ptime const& receive_time
22442252
22452253void utp_socket_impl::incoming (boost::uint8_t const * buf, int size, packet* p, ptime now)
22462254{
2255+ #ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS
22472256 INVARIANT_CHECK ;
2257+ #endif
22482258
22492259 while (!m_read_buffer.empty ())
22502260 {
@@ -3213,7 +3223,7 @@ void utp_socket_impl::do_ledbat(int acked_bytes, int delay, int in_flight, ptime
32133223 boost::int64_t window_factor = (boost::int64_t (acked_bytes) << 16 ) / in_flight;
32143224 boost::int64_t delay_factor = (boost::int64_t (target_delay - delay) << 16 ) / target_delay;
32153225 boost::int64_t scaled_gain;
3216-
3226+
32173227 if (delay >= target_delay)
32183228 {
32193229 if (m_slow_start)
@@ -3502,15 +3512,15 @@ void utp_socket_impl::check_receive_buffers() const
35023512void utp_socket_impl::check_invariant () const
35033513{
35043514 for (int i = m_outbuf.cursor ();
3505- i != int ((m_outbuf.cursor () + m_outbuf.span ()) & ACK_MASK );
3515+ i != int ((m_outbuf.cursor () + m_outbuf.span ()) & ACK_MASK );
35063516 i = (i + 1 ) & ACK_MASK )
35073517 {
35083518 packet* p = (packet*)m_outbuf.at (i);
3509- if (m_mtu_seq == i && m_mtu_seq != 0 && p)
3519+ if (!p) continue ;
3520+ if (m_mtu_seq == i && m_mtu_seq != 0 )
35103521 {
35113522 TORRENT_ASSERT (p->mtu_probe );
35123523 }
3513- if (!p) continue ;
35143524 TORRENT_ASSERT (((utp_header*)p->buf )->seq_nr == i);
35153525 }
35163526
0 commit comments