| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/p2p/base/pseudotcp.h" | 11 #include "webrtc/p2p/base/pseudotcp.h" |
| 12 | 12 |
| 13 #include <stdio.h> | 13 #include <stdio.h> |
| 14 #include <stdlib.h> | 14 #include <stdlib.h> |
| 15 | 15 |
| 16 #include <algorithm> | 16 #include <algorithm> |
| 17 #include <memory> | 17 #include <memory> |
| 18 #include <set> | 18 #include <set> |
| 19 | 19 |
| 20 #include "webrtc/base/arraysize.h" | 20 #include "webrtc/base/arraysize.h" |
| 21 #include "webrtc/base/basictypes.h" | 21 #include "webrtc/base/basictypes.h" |
| 22 #include "webrtc/base/bytebuffer.h" | 22 #include "webrtc/base/bytebuffer.h" |
| 23 #include "webrtc/base/byteorder.h" | 23 #include "webrtc/base/byteorder.h" |
| 24 #include "webrtc/base/checks.h" | 24 #include "webrtc/base/checks.h" |
| 25 #include "webrtc/base/logging.h" | 25 #include "webrtc/base/logging.h" |
| 26 #include "webrtc/base/safe_minmax.h" |
| 26 #include "webrtc/base/socket.h" | 27 #include "webrtc/base/socket.h" |
| 27 #include "webrtc/base/stringutils.h" | 28 #include "webrtc/base/stringutils.h" |
| 28 #include "webrtc/base/timeutils.h" | 29 #include "webrtc/base/timeutils.h" |
| 29 | 30 |
| 30 // The following logging is for detailed (packet-level) analysis only. | 31 // The following logging is for detailed (packet-level) analysis only. |
| 31 #define _DBG_NONE 0 | 32 #define _DBG_NONE 0 |
| 32 #define _DBG_NORMAL 1 | 33 #define _DBG_NORMAL 1 |
| 33 #define _DBG_VERBOSE 2 | 34 #define _DBG_VERBOSE 2 |
| 34 #define _DEBUGMSG _DBG_NONE | 35 #define _DEBUGMSG _DBG_NONE |
| 35 | 36 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 } | 149 } |
| 149 | 150 |
| 150 inline uint32_t bytes_to_long(const void* buf) { | 151 inline uint32_t bytes_to_long(const void* buf) { |
| 151 return rtc::NetworkToHost32(*static_cast<const uint32_t*>(buf)); | 152 return rtc::NetworkToHost32(*static_cast<const uint32_t*>(buf)); |
| 152 } | 153 } |
| 153 | 154 |
| 154 inline uint16_t bytes_to_short(const void* buf) { | 155 inline uint16_t bytes_to_short(const void* buf) { |
| 155 return rtc::NetworkToHost16(*static_cast<const uint16_t*>(buf)); | 156 return rtc::NetworkToHost16(*static_cast<const uint16_t*>(buf)); |
| 156 } | 157 } |
| 157 | 158 |
| 158 uint32_t bound(uint32_t lower, uint32_t middle, uint32_t upper) { | |
| 159 return std::min(std::max(lower, middle), upper); | |
| 160 } | |
| 161 | |
| 162 ////////////////////////////////////////////////////////////////////// | 159 ////////////////////////////////////////////////////////////////////// |
| 163 // Debugging Statistics | 160 // Debugging Statistics |
| 164 ////////////////////////////////////////////////////////////////////// | 161 ////////////////////////////////////////////////////////////////////// |
| 165 | 162 |
| 166 #if 0 // Not used yet | 163 #if 0 // Not used yet |
| 167 | 164 |
| 168 enum Stat { | 165 enum Stat { |
| 169 S_SENT_PACKET, // All packet sends | 166 S_SENT_PACKET, // All packet sends |
| 170 S_RESENT_PACKET, // All packet sends that are retransmits | 167 S_RESENT_PACKET, // All packet sends that are retransmits |
| 171 S_RECV_PACKET, // All packet receives | 168 S_RECV_PACKET, // All packet receives |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 m_rx_srtt = rtt; | 715 m_rx_srtt = rtt; |
| 719 m_rx_rttvar = rtt / 2; | 716 m_rx_rttvar = rtt / 2; |
| 720 } else { | 717 } else { |
| 721 uint32_t unsigned_rtt = static_cast<uint32_t>(rtt); | 718 uint32_t unsigned_rtt = static_cast<uint32_t>(rtt); |
| 722 uint32_t abs_err = unsigned_rtt > m_rx_srtt | 719 uint32_t abs_err = unsigned_rtt > m_rx_srtt |
| 723 ? unsigned_rtt - m_rx_srtt | 720 ? unsigned_rtt - m_rx_srtt |
| 724 : m_rx_srtt - unsigned_rtt; | 721 : m_rx_srtt - unsigned_rtt; |
| 725 m_rx_rttvar = (3 * m_rx_rttvar + abs_err) / 4; | 722 m_rx_rttvar = (3 * m_rx_rttvar + abs_err) / 4; |
| 726 m_rx_srtt = (7 * m_rx_srtt + rtt) / 8; | 723 m_rx_srtt = (7 * m_rx_srtt + rtt) / 8; |
| 727 } | 724 } |
| 728 m_rx_rto = | 725 m_rx_rto = rtc::SafeClamp(m_rx_srtt + rtc::SafeMax(1, 4 * m_rx_rttvar), |
| 729 bound(MIN_RTO, m_rx_srtt + std::max<uint32_t>(1, 4 * m_rx_rttvar), | 726 MIN_RTO, MAX_RTO); |
| 730 MAX_RTO); | |
| 731 #if _DEBUGMSG >= _DBG_VERBOSE | 727 #if _DEBUGMSG >= _DBG_VERBOSE |
| 732 LOG(LS_INFO) << "rtt: " << rtt | 728 LOG(LS_INFO) << "rtt: " << rtt |
| 733 << " srtt: " << m_rx_srtt | 729 << " srtt: " << m_rx_srtt |
| 734 << " rto: " << m_rx_rto; | 730 << " rto: " << m_rx_rto; |
| 735 #endif // _DEBUGMSG | 731 #endif // _DEBUGMSG |
| 736 } else { | 732 } else { |
| 737 RTC_NOTREACHED(); | 733 RTC_NOTREACHED(); |
| 738 } | 734 } |
| 739 } | 735 } |
| 740 | 736 |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1277 m_rbuf_len = new_size; | 1273 m_rbuf_len = new_size; |
| 1278 m_rwnd_scale = scale_factor; | 1274 m_rwnd_scale = scale_factor; |
| 1279 m_ssthresh = new_size; | 1275 m_ssthresh = new_size; |
| 1280 | 1276 |
| 1281 size_t available_space = 0; | 1277 size_t available_space = 0; |
| 1282 m_rbuf.GetWriteRemaining(&available_space); | 1278 m_rbuf.GetWriteRemaining(&available_space); |
| 1283 m_rcv_wnd = static_cast<uint32_t>(available_space); | 1279 m_rcv_wnd = static_cast<uint32_t>(available_space); |
| 1284 } | 1280 } |
| 1285 | 1281 |
| 1286 } // namespace cricket | 1282 } // namespace cricket |
| OLD | NEW |