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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 // to spend a few seconds attempting a reconnect before saying we're | 327 // to spend a few seconds attempting a reconnect before saying we're |
328 // unwritable. | 328 // unwritable. |
329 if (!connected()) { | 329 if (!connected()) { |
330 MaybeReconnect(); | 330 MaybeReconnect(); |
331 return SOCKET_ERROR; | 331 return SOCKET_ERROR; |
332 } | 332 } |
333 | 333 |
334 // Note that this is important to put this after the previous check to give | 334 // Note that this is important to put this after the previous check to give |
335 // the connection a chance to reconnect. | 335 // the connection a chance to reconnect. |
336 if (pretending_to_be_writable_ || write_state() != STATE_WRITABLE) { | 336 if (pretending_to_be_writable_ || write_state() != STATE_WRITABLE) { |
337 // TODO: Should STATE_WRITE_TIMEOUT return a non-blocking error? | 337 // TODO: Should STATE_WRITE_TIMEOUT return a non-blocking error? |
pthatcher1
2015/08/20 03:47:27
Would this be a better way to address it? Not use
| |
338 error_ = EWOULDBLOCK; | 338 error_ = EWOULDBLOCK; |
339 return SOCKET_ERROR; | 339 return SOCKET_ERROR; |
340 } | 340 } |
341 sent_packets_total_++; | 341 sent_packets_total_++; |
342 int sent = socket_->Send(data, size, options); | 342 int sent = socket_->Send(data, size, options); |
343 if (sent < 0) { | 343 if (sent < 0) { |
344 sent_packets_discarded_++; | 344 sent_packets_discarded_++; |
345 error_ = socket_->GetError(); | 345 error_ = socket_->GetError(); |
346 } else { | 346 } else { |
347 send_rate_tracker_.Update(sent); | 347 send_rate_tracker_.Update(sent); |
348 } | 348 } |
349 return sent; | 349 return sent; |
350 } | 350 } |
351 | 351 |
352 int TCPConnection::GetError() { | 352 int TCPConnection::GetError() { |
353 return error_; | 353 return error_; |
354 } | 354 } |
355 | 355 |
356 void TCPConnection::OnConnectionRequestResponse(ConnectionRequest* req, | 356 void TCPConnection::OnConnectionRequestResponse(ConnectionRequest* req, |
357 StunMessage* response) { | 357 StunMessage* response) { |
358 // Once we receive a binding response, we are really writable, and not just | 358 // If we're in the state of pretending to be writeable, we should inform the |
359 // pretending to be writable. | 359 // upper layer it's ready to send again as previous EWOULDLBLOCK from socket |
360 // would have stopped the outgoing stream. | |
361 if (pretending_to_be_writable_) { | |
362 Connection::OnReadyToSend(); | |
pthatcher1
2015/08/20 03:47:27
If we fire OnReadyToSend() when we go from pretend
juberti1
2015/08/20 05:33:00
That is driven by EWOULDBLOCK being returned from
guoweis_webrtc
2015/08/21 05:05:50
Yes, this is possible. Moved this down
| |
363 } | |
360 pretending_to_be_writable_ = false; | 364 pretending_to_be_writable_ = false; |
361 Connection::OnConnectionRequestResponse(req, response); | 365 Connection::OnConnectionRequestResponse(req, response); |
362 ASSERT(write_state() == STATE_WRITABLE); | 366 ASSERT(write_state() == STATE_WRITABLE); |
363 } | 367 } |
364 | 368 |
365 void TCPConnection::OnConnect(rtc::AsyncPacketSocket* socket) { | 369 void TCPConnection::OnConnect(rtc::AsyncPacketSocket* socket) { |
366 ASSERT(socket == socket_); | 370 ASSERT(socket == socket_); |
367 // Do not use this connection if the socket bound to a different address than | 371 // Do not use this connection if the socket bound to a different address than |
368 // the one we asked for. This is seen in Chrome, where TCP sockets cannot be | 372 // the one we asked for. This is seen in Chrome, where TCP sockets cannot be |
369 // given a binding address, and the platform is expected to pick the | 373 // given a binding address, and the platform is expected to pick the |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
468 void TCPConnection::ConnectSocketSignals(rtc::AsyncPacketSocket* socket) { | 472 void TCPConnection::ConnectSocketSignals(rtc::AsyncPacketSocket* socket) { |
469 if (outgoing_) { | 473 if (outgoing_) { |
470 socket->SignalConnect.connect(this, &TCPConnection::OnConnect); | 474 socket->SignalConnect.connect(this, &TCPConnection::OnConnect); |
471 } | 475 } |
472 socket->SignalReadPacket.connect(this, &TCPConnection::OnReadPacket); | 476 socket->SignalReadPacket.connect(this, &TCPConnection::OnReadPacket); |
473 socket->SignalReadyToSend.connect(this, &TCPConnection::OnReadyToSend); | 477 socket->SignalReadyToSend.connect(this, &TCPConnection::OnReadyToSend); |
474 socket->SignalClose.connect(this, &TCPConnection::OnClose); | 478 socket->SignalClose.connect(this, &TCPConnection::OnClose); |
475 } | 479 } |
476 | 480 |
477 } // namespace cricket | 481 } // namespace cricket |
OLD | NEW |