Chromium Code Reviews| 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 11 matching lines...) Expand all Loading... | |
| 22 * outstanding TCP connection in progress. | 22 * outstanding TCP connection in progress. |
| 23 * | 23 * |
| 24 * - PretendWri: Tracked by |pretending_to_be_writable_|. Marking connection as | 24 * - PretendWri: Tracked by |pretending_to_be_writable_|. Marking connection as |
| 25 * WRITE_TIMEOUT will cause the connection be deleted. Instead, we're | 25 * WRITE_TIMEOUT will cause the connection be deleted. Instead, we're |
| 26 * "pretending" we're still writable for a period of time such that reconnect | 26 * "pretending" we're still writable for a period of time such that reconnect |
| 27 * could work. | 27 * could work. |
| 28 * | 28 * |
| 29 * Data could only be sent in state 3. Sening data during state 2 & 6 will get | 29 * Data could only be sent in state 3. Sening data during state 2 & 6 will get |
| 30 * EWOULDBLOCK, 4 & 5 EPIPE. | 30 * EWOULDBLOCK, 4 & 5 EPIPE. |
| 31 * | 31 * |
| 32 * 7 -------------+ | 32 * OS Timeout 7 -------------+ |
| 33 * |Connected: N | | 33 * +----------------------->|Connected: N | |
| 34 * Timeout |Writable: N | Timeout | 34 * | |Writable: N | Timeout |
| 35 * +------------------->|Connection is |<----------------+ | 35 * | Timeout |Connection is |<----------------+ |
| 36 * | |Dead | | | 36 * | +------------------->|Dead | | |
| 37 * | +--------------+ | | 37 * | | +--------------+ | |
| 38 * | ^ | | 38 * | | ^ | |
| 39 * | OnClose | | | 39 * | | OnClose | | |
| 40 * | +-----------------------+ | | | 40 * | | +-----------------------+ | | |
| 41 * | | | |Timeout | | 41 * | | | | |Timeout | |
| 42 * | v | | | | 42 * | | v | | | |
| 43 * 4 +----------+ 5 -----+--+--+ 6 -----+-----+ | 43 * | 4 +----------+ 5 -----+--+--+ 6 -----+-----+ |
| 44 * |Connected: N|Send() or |Connected: N| |Connected: Y| | 44 * | |Connected: N|Send() or |Connected: N| |Connected: Y| |
| 45 * |Writable: Y|Ping() |Writable: Y|OnConnect |Writable: Y| | 45 * | |Writable: Y|Ping() |Writable: Y|OnConnect |Writable: Y| |
| 46 * |PendingTCP:N+--------> |PendingTCP:Y+---------> |PendingTCP:N| | 46 * | |PendingTCP:N+--------> |PendingTCP:Y+---------> |PendingTCP:N| |
| 47 * |PretendWri:Y| |PretendWri:Y| |PretendWri:Y| | 47 * | |PretendWri:Y| |PretendWri:Y| |PretendWri:Y| |
| 48 * +-----+------+ +------------+ +---+--+-----+ | 48 * | +-----+------+ +------------+ +---+--+-----+ |
| 49 * ^ ^ | | | 49 * | ^ ^ | | |
| 50 * | | OnClose | | | 50 * | | | OnClose | | |
| 51 * | +----------------------------------------------+ | | 51 * | | +----------------------------------------------+ | |
| 52 * | | | 52 * | | | |
| 53 * | Stun Binding Completed | | 53 * | | Stun Binding Completed | |
| 54 * | | | 54 * | | | |
| 55 * | OnClose | | 55 * | | OnClose | |
| 56 * +------------------------------------------------+ | | 56 * | +------------------------------------------------+ | |
| 57 * | v | 57 * | | v |
| 58 * 1 -----------+ 2 -----------+Stun 3 -----------+ | 58 * 1 -----------+ 2 -----------+Stun 3 -----------+ |
| 59 * |Connected: N| |Connected: Y|Binding |Connected: Y| | 59 * |Connected: N| |Connected: Y|Binding |Connected: Y| |
| 60 * |Writable: N|OnConnect |Writable: N|Completed |Writable: Y| | 60 * |Writable: N|OnConnect |Writable: N|Completed |Writable: Y| |
| 61 * |PendingTCP:Y+---------> |PendingTCP:N+--------> |PendingTCP:N| | 61 * |PendingTCP:Y+---------> |PendingTCP:N+--------> |PendingTCP:N| |
| 62 * |PretendWri:N| |PretendWri:N| |PretendWri:N| | 62 * |PretendWri:N| |PretendWri:N| |PretendWri:N| |
| 63 * +------------+ +------------+ +------------+ | 63 * +------------+ +------------+ +------------+ |
| 64 * | 64 * |
| 65 */ | 65 */ |
| 66 | 66 |
| 67 #include "webrtc/p2p/base/tcpport.h" | 67 #include "webrtc/p2p/base/tcpport.h" |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 if (socket_ip == port()->ip()) { | 377 if (socket_ip == port()->ip()) { |
| 378 LOG_J(LS_VERBOSE, this) << "Connection established to " | 378 LOG_J(LS_VERBOSE, this) << "Connection established to " |
| 379 << socket->GetRemoteAddress().ToSensitiveString(); | 379 << socket->GetRemoteAddress().ToSensitiveString(); |
| 380 set_connected(true); | 380 set_connected(true); |
| 381 connection_pending_ = false; | 381 connection_pending_ = false; |
| 382 } else { | 382 } else { |
| 383 LOG_J(LS_WARNING, this) << "Dropping connection as TCP socket bound to IP " | 383 LOG_J(LS_WARNING, this) << "Dropping connection as TCP socket bound to IP " |
| 384 << socket_ip.ToSensitiveString() | 384 << socket_ip.ToSensitiveString() |
| 385 << ", different from the local candidate IP " | 385 << ", different from the local candidate IP " |
| 386 << port()->ip().ToSensitiveString(); | 386 << port()->ip().ToSensitiveString(); |
| 387 socket_->Close(); | 387 OnClose(socket, 0); |
| 388 } | 388 } |
| 389 } | 389 } |
| 390 | 390 |
| 391 void TCPConnection::OnClose(rtc::AsyncPacketSocket* socket, int error) { | 391 void TCPConnection::OnClose(rtc::AsyncPacketSocket* socket, int error) { |
| 392 ASSERT(socket == socket_); | 392 ASSERT(socket == socket_); |
| 393 LOG_J(LS_INFO, this) << "Connection closed with error " << error; | 393 LOG_J(LS_INFO, this) << "Connection closed with error " << error; |
| 394 | 394 |
| 395 // Guard against the condition where IPC socket will call OnClose for every | 395 // Guard against the condition where IPC socket will call OnClose for every |
| 396 // packet it can't send. | 396 // packet it can't send. |
| 397 if (connected()) { | 397 if (connected()) { |
| 398 set_connected(false); | 398 set_connected(false); |
| 399 | |
| 400 // Prevent the connection to be destroyed. | |
|
pthatcher1
2015/08/25 17:58:41
to be destroyed => from being destroyed
| |
| 399 pretending_to_be_writable_ = true; | 401 pretending_to_be_writable_ = true; |
| 400 | 402 |
| 401 // We don't attempt reconnect right here. This is to avoid a case where the | 403 // We don't attempt reconnect right here. This is to avoid a case where the |
| 402 // shutdown is intentional and reconnect is not necessary. We only reconnect | 404 // shutdown is intentional and reconnect is not necessary. We only reconnect |
| 403 // when the connection is used to Send() or Ping(). | 405 // when the connection is used to Send() or Ping(). |
| 404 port()->thread()->PostDelayed(reconnection_timeout(), this, | 406 port()->thread()->PostDelayed(reconnection_timeout(), this, |
| 405 MSG_TCPCONNECTION_DELAYED_ONCLOSE); | 407 MSG_TCPCONNECTION_DELAYED_ONCLOSE); |
| 408 } else if (!pretending_to_be_writable_) { | |
| 409 // OnClose could be called when the underneath socket times out during the | |
| 410 // initial connect() (i.e. |pretending_to_be_writable_| is false) . We have | |
| 411 // to manually destroy here as this connection, as never connected, will not | |
| 412 // be scheduled for ping to trigger destroy. | |
| 413 Destroy(); | |
| 406 } | 414 } |
| 407 } | 415 } |
| 408 | 416 |
| 409 void TCPConnection::OnMessage(rtc::Message* pmsg) { | 417 void TCPConnection::OnMessage(rtc::Message* pmsg) { |
| 410 switch (pmsg->message_id) { | 418 switch (pmsg->message_id) { |
| 411 case MSG_TCPCONNECTION_DELAYED_ONCLOSE: | 419 case MSG_TCPCONNECTION_DELAYED_ONCLOSE: |
| 412 // If this connection can't become connected and writable again in 5 | 420 // If this connection can't become connected and writable again in 5 |
| 413 // seconds, it's time to tear this down. This is the case for the original | 421 // seconds, it's time to tear this down. This is the case for the original |
| 414 // TCP connection on passive side during a reconnect. | 422 // TCP connection on passive side during a reconnect. |
| 415 if (pretending_to_be_writable_) { | 423 if (pretending_to_be_writable_) { |
| 416 set_write_state(STATE_WRITE_TIMEOUT); | 424 Destroy(); |
| 417 } | 425 } |
| 418 break; | 426 break; |
| 419 default: | 427 default: |
| 420 Connection::OnMessage(pmsg); | 428 Connection::OnMessage(pmsg); |
| 421 } | 429 } |
| 422 } | 430 } |
| 423 | 431 |
| 424 void TCPConnection::MaybeReconnect() { | 432 void TCPConnection::MaybeReconnect() { |
| 425 // Only reconnect for an outgoing TCPConnection when OnClose was signaled and | 433 // Only reconnect for an outgoing TCPConnection when OnClose was signaled and |
| 426 // no outstanding reconnect is pending. | 434 // no outstanding reconnect is pending. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 void TCPConnection::ConnectSocketSignals(rtc::AsyncPacketSocket* socket) { | 481 void TCPConnection::ConnectSocketSignals(rtc::AsyncPacketSocket* socket) { |
| 474 if (outgoing_) { | 482 if (outgoing_) { |
| 475 socket->SignalConnect.connect(this, &TCPConnection::OnConnect); | 483 socket->SignalConnect.connect(this, &TCPConnection::OnConnect); |
| 476 } | 484 } |
| 477 socket->SignalReadPacket.connect(this, &TCPConnection::OnReadPacket); | 485 socket->SignalReadPacket.connect(this, &TCPConnection::OnReadPacket); |
| 478 socket->SignalReadyToSend.connect(this, &TCPConnection::OnReadyToSend); | 486 socket->SignalReadyToSend.connect(this, &TCPConnection::OnReadyToSend); |
| 479 socket->SignalClose.connect(this, &TCPConnection::OnClose); | 487 socket->SignalClose.connect(this, &TCPConnection::OnClose); |
| 480 } | 488 } |
| 481 | 489 |
| 482 } // namespace cricket | 490 } // namespace cricket |
| OLD | NEW |