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 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 | 881 |
882 // Send data to the other side, using our selected connection. | 882 // Send data to the other side, using our selected connection. |
883 int P2PTransportChannel::SendPacket(const char *data, size_t len, | 883 int P2PTransportChannel::SendPacket(const char *data, size_t len, |
884 const rtc::PacketOptions& options, | 884 const rtc::PacketOptions& options, |
885 int flags) { | 885 int flags) { |
886 ASSERT(worker_thread_ == rtc::Thread::Current()); | 886 ASSERT(worker_thread_ == rtc::Thread::Current()); |
887 if (flags != 0) { | 887 if (flags != 0) { |
888 error_ = EINVAL; | 888 error_ = EINVAL; |
889 return -1; | 889 return -1; |
890 } | 890 } |
891 if (selected_connection_ == NULL) { | 891 // If we don't think the connection is working yet, return EWOULDBLOCK |
| 892 // instead of sending a packet that will probably be dropped. |
| 893 if (!ReadyToSend()) { |
892 error_ = EWOULDBLOCK; | 894 error_ = EWOULDBLOCK; |
893 return -1; | 895 return -1; |
894 } | 896 } |
895 | 897 |
896 last_sent_packet_id_ = options.packet_id; | 898 last_sent_packet_id_ = options.packet_id; |
897 int sent = selected_connection_->Send(data, len, options); | 899 int sent = selected_connection_->Send(data, len, options); |
898 if (sent <= 0) { | 900 if (sent <= 0) { |
899 ASSERT(sent < 0); | 901 ASSERT(sent < 0); |
900 error_ = selected_connection_->GetError(); | 902 error_ = selected_connection_->GetError(); |
901 } | 903 } |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1255 // send; then it will only signal ready-to-send if the media channel | 1257 // send; then it will only signal ready-to-send if the media channel |
1256 // has been disallowed to send. | 1258 // has been disallowed to send. |
1257 if (selected_connection_->writable() || | 1259 if (selected_connection_->writable() || |
1258 PresumedWritable(selected_connection_)) { | 1260 PresumedWritable(selected_connection_)) { |
1259 SignalReadyToSend(this); | 1261 SignalReadyToSend(this); |
1260 } | 1262 } |
1261 } else { | 1263 } else { |
1262 LOG_J(LS_INFO, this) << "No selected connection"; | 1264 LOG_J(LS_INFO, this) << "No selected connection"; |
1263 } | 1265 } |
1264 SignalSelectedCandidatePairChanged(this, selected_connection_, | 1266 SignalSelectedCandidatePairChanged(this, selected_connection_, |
1265 last_sent_packet_id_); | 1267 last_sent_packet_id_, ReadyToSend()); |
1266 } | 1268 } |
1267 | 1269 |
1268 // Warning: UpdateState should eventually be called whenever a connection | 1270 // Warning: UpdateState should eventually be called whenever a connection |
1269 // is added, deleted, or the write state of any connection changes so that the | 1271 // is added, deleted, or the write state of any connection changes so that the |
1270 // transport controller will get the up-to-date channel state. However it | 1272 // transport controller will get the up-to-date channel state. However it |
1271 // should not be called too often; in the case that multiple connection states | 1273 // should not be called too often; in the case that multiple connection states |
1272 // change, it should be called after all the connection states have changed. For | 1274 // change, it should be called after all the connection states have changed. For |
1273 // example, we call this at the end of SortConnections. | 1275 // example, we call this at the end of SortConnections. |
1274 void P2PTransportChannel::UpdateState() { | 1276 void P2PTransportChannel::UpdateState() { |
1275 TransportChannelState state = ComputeState(); | 1277 TransportChannelState state = ComputeState(); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1349 void P2PTransportChannel::HandleAllTimedOut() { | 1351 void P2PTransportChannel::HandleAllTimedOut() { |
1350 for (Connection* connection : connections_) { | 1352 for (Connection* connection : connections_) { |
1351 connection->Destroy(); | 1353 connection->Destroy(); |
1352 } | 1354 } |
1353 } | 1355 } |
1354 | 1356 |
1355 bool P2PTransportChannel::weak() const { | 1357 bool P2PTransportChannel::weak() const { |
1356 return !selected_connection_ || selected_connection_->weak(); | 1358 return !selected_connection_ || selected_connection_->weak(); |
1357 } | 1359 } |
1358 | 1360 |
| 1361 bool P2PTransportChannel::ReadyToSend() const { |
| 1362 // Note that we allow sending on an unreliable connection, because it's |
| 1363 // possible that it became unreliable simply due to bad chance. |
| 1364 // So this shouldn't prevent attempting to send media. |
| 1365 return selected_connection_ != nullptr && |
| 1366 (selected_connection_->writable() || |
| 1367 PresumedWritable(selected_connection_) || |
| 1368 selected_connection_->write_state() == |
| 1369 Connection::STATE_WRITE_UNRELIABLE); |
| 1370 } |
| 1371 |
1359 // If we have a selected connection, return it, otherwise return top one in the | 1372 // If we have a selected connection, return it, otherwise return top one in the |
1360 // list (later we will mark it best). | 1373 // list (later we will mark it best). |
1361 Connection* P2PTransportChannel::GetBestConnectionOnNetwork( | 1374 Connection* P2PTransportChannel::GetBestConnectionOnNetwork( |
1362 rtc::Network* network) const { | 1375 rtc::Network* network) const { |
1363 // If the selected connection is on this network, then it wins. | 1376 // If the selected connection is on this network, then it wins. |
1364 if (selected_connection_ && | 1377 if (selected_connection_ && |
1365 (selected_connection_->port()->Network() == network)) { | 1378 (selected_connection_->port()->Network() == network)) { |
1366 return selected_connection_; | 1379 return selected_connection_; |
1367 } | 1380 } |
1368 | 1381 |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1799 | 1812 |
1800 // During the initial state when nothing has been pinged yet, return the first | 1813 // During the initial state when nothing has been pinged yet, return the first |
1801 // one in the ordered |connections_|. | 1814 // one in the ordered |connections_|. |
1802 return *(std::find_if(connections_.begin(), connections_.end(), | 1815 return *(std::find_if(connections_.begin(), connections_.end(), |
1803 [conn1, conn2](Connection* conn) { | 1816 [conn1, conn2](Connection* conn) { |
1804 return conn == conn1 || conn == conn2; | 1817 return conn == conn1 || conn == conn2; |
1805 })); | 1818 })); |
1806 } | 1819 } |
1807 | 1820 |
1808 } // namespace cricket | 1821 } // namespace cricket |
OLD | NEW |