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 |
(...skipping 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1120 | 1120 |
1121 bool Connection::dead(uint32_t now) const { | 1121 bool Connection::dead(uint32_t now) const { |
1122 if (now < (time_created_ms_ + MIN_CONNECTION_LIFETIME)) { | 1122 if (now < (time_created_ms_ + MIN_CONNECTION_LIFETIME)) { |
1123 // A connection that hasn't passed its minimum lifetime is still alive. | 1123 // A connection that hasn't passed its minimum lifetime is still alive. |
1124 // We do this to prevent connections from being pruned too quickly | 1124 // We do this to prevent connections from being pruned too quickly |
1125 // during a network change event when two networks would be up | 1125 // during a network change event when two networks would be up |
1126 // simultaneously but only for a brief period. | 1126 // simultaneously but only for a brief period. |
1127 return false; | 1127 return false; |
1128 } | 1128 } |
1129 | 1129 |
1130 if (receiving_) { | 1130 // It is dead if it has not received anything for |
1131 // A connection that is receiving is alive. | 1131 // DEAD_CONNECTION_RECEIVE_TIMEOUT milliseconds. |
1132 return false; | 1132 return (now > (last_received() + DEAD_CONNECTION_RECEIVE_TIMEOUT)); |
1133 } | |
1134 | |
1135 // A connection is alive until it is inactive. | |
1136 return !active(); | |
1137 | |
1138 // TODO(honghaiz): Move from using the write state to using the receiving | |
1139 // state with something like the following: | |
1140 // return (now > (last_received() + DEAD_CONNECTION_RECEIVE_TIMEOUT)); | |
1141 } | 1133 } |
1142 | 1134 |
1143 std::string Connection::ToDebugId() const { | 1135 std::string Connection::ToDebugId() const { |
1144 std::stringstream ss; | 1136 std::stringstream ss; |
1145 ss << std::hex << this; | 1137 ss << std::hex << this; |
1146 return ss.str(); | 1138 return ss.str(); |
1147 } | 1139 } |
1148 | 1140 |
1149 std::string Connection::ToString() const { | 1141 std::string Connection::ToString() const { |
1150 const char CONNECT_STATE_ABBREV[2] = { | 1142 const char CONNECT_STATE_ABBREV[2] = { |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1297 } | 1289 } |
1298 } | 1290 } |
1299 | 1291 |
1300 void Connection::OnMessage(rtc::Message *pmsg) { | 1292 void Connection::OnMessage(rtc::Message *pmsg) { |
1301 ASSERT(pmsg->message_id == MSG_DELETE); | 1293 ASSERT(pmsg->message_id == MSG_DELETE); |
1302 LOG_J(LS_INFO, this) << "Connection deleted"; | 1294 LOG_J(LS_INFO, this) << "Connection deleted"; |
1303 SignalDestroyed(this); | 1295 SignalDestroyed(this); |
1304 delete this; | 1296 delete this; |
1305 } | 1297 } |
1306 | 1298 |
1307 uint32_t Connection::last_received() { | 1299 uint32_t Connection::last_received() const { |
1308 return std::max(last_data_received_, | 1300 return std::max(last_data_received_, |
1309 std::max(last_ping_received_, last_ping_response_received_)); | 1301 std::max(last_ping_received_, last_ping_response_received_)); |
1310 } | 1302 } |
1311 | 1303 |
1312 size_t Connection::recv_bytes_second() { | 1304 size_t Connection::recv_bytes_second() { |
1313 return round(recv_rate_tracker_.ComputeRate()); | 1305 return round(recv_rate_tracker_.ComputeRate()); |
1314 } | 1306 } |
1315 | 1307 |
1316 size_t Connection::recv_total_bytes() { | 1308 size_t Connection::recv_total_bytes() { |
1317 return recv_rate_tracker_.TotalSampleCount(); | 1309 return recv_rate_tracker_.TotalSampleCount(); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1416 ASSERT(sent < 0); | 1408 ASSERT(sent < 0); |
1417 error_ = port_->GetError(); | 1409 error_ = port_->GetError(); |
1418 sent_packets_discarded_++; | 1410 sent_packets_discarded_++; |
1419 } else { | 1411 } else { |
1420 send_rate_tracker_.AddSamples(sent); | 1412 send_rate_tracker_.AddSamples(sent); |
1421 } | 1413 } |
1422 return sent; | 1414 return sent; |
1423 } | 1415 } |
1424 | 1416 |
1425 } // namespace cricket | 1417 } // namespace cricket |
OLD | NEW |