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 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 if (socket_ip == port()->ip()) { | 371 if (socket_ip == port()->ip()) { |
| 372 LOG_J(LS_VERBOSE, this) << "Connection established to " | 372 LOG_J(LS_VERBOSE, this) << "Connection established to " |
| 373 << socket->GetRemoteAddress().ToSensitiveString(); | 373 << socket->GetRemoteAddress().ToSensitiveString(); |
| 374 set_connected(true); | 374 set_connected(true); |
| 375 connection_pending_ = false; | 375 connection_pending_ = false; |
| 376 } else { | 376 } else { |
| 377 LOG_J(LS_WARNING, this) << "Dropping connection as TCP socket bound to IP " | 377 LOG_J(LS_WARNING, this) << "Dropping connection as TCP socket bound to IP " |
| 378 << socket_ip.ToSensitiveString() | 378 << socket_ip.ToSensitiveString() |
| 379 << ", different from the local candidate IP " | 379 << ", different from the local candidate IP " |
| 380 << port()->ip().ToSensitiveString(); | 380 << port()->ip().ToSensitiveString(); |
| 381 // This doesn't trigger OnClose. We should either fix that behavior or call | |
| 382 // Destroy() to ensure this connection doesn't linger. | |
|
pthatcher1
2015/08/22 05:05:22
It seems like we should call OnClose here. Is the
guoweis_webrtc
2015/08/22 05:29:49
Done.
| |
| 381 socket_->Close(); | 383 socket_->Close(); |
| 382 } | 384 } |
| 383 } | 385 } |
| 384 | 386 |
| 385 void TCPConnection::OnClose(rtc::AsyncPacketSocket* socket, int error) { | 387 void TCPConnection::OnClose(rtc::AsyncPacketSocket* socket, int error) { |
| 386 ASSERT(socket == socket_); | 388 ASSERT(socket == socket_); |
| 387 LOG_J(LS_INFO, this) << "Connection closed with error " << error; | 389 LOG_J(LS_INFO, this) << "Connection closed with error " << error; |
| 388 | 390 |
| 389 // Guard against the condition where IPC socket will call OnClose for every | 391 // Guard against the condition where IPC socket will call OnClose for every |
| 390 // packet it can't send. | 392 // packet it can't send. |
| 391 if (connected()) { | 393 if (connected()) { |
| 392 set_connected(false); | 394 set_connected(false); |
| 393 pretending_to_be_writable_ = true; | 395 pretending_to_be_writable_ = true; |
| 394 | 396 |
| 395 // We don't attempt reconnect right here. This is to avoid a case where the | 397 // We don't attempt reconnect right here. This is to avoid a case where the |
| 396 // shutdown is intentional and reconnect is not necessary. We only reconnect | 398 // shutdown is intentional and reconnect is not necessary. We only reconnect |
| 397 // when the connection is used to Send() or Ping(). | 399 // when the connection is used to Send() or Ping(). |
| 398 port()->thread()->PostDelayed(reconnection_timeout(), this, | 400 port()->thread()->PostDelayed(reconnection_timeout(), this, |
| 399 MSG_TCPCONNECTION_DELAYED_ONCLOSE); | 401 MSG_TCPCONNECTION_DELAYED_ONCLOSE); |
| 402 } else { | |
| 403 // OnClose could be called when the underneath socket times out during | |
| 404 // connect(). We have to manually destroy here as this connection, as never | |
| 405 // connected, will not be scheduled for ping to trigger destroy. | |
| 406 Destroy(); | |
|
pthatcher1
2015/08/22 05:05:22
I don't think this matches the state diagram at th
guoweis_webrtc
2015/08/22 05:29:49
the diagram above misses an arrow from state 1 to
| |
| 400 } | 407 } |
| 401 } | 408 } |
| 402 | 409 |
| 403 void TCPConnection::OnMessage(rtc::Message* pmsg) { | 410 void TCPConnection::OnMessage(rtc::Message* pmsg) { |
| 404 switch (pmsg->message_id) { | 411 switch (pmsg->message_id) { |
| 405 case MSG_TCPCONNECTION_DELAYED_ONCLOSE: | 412 case MSG_TCPCONNECTION_DELAYED_ONCLOSE: |
| 406 // If this connection can't become connected and writable again in 5 | 413 // If this connection can't become connected and writable again in 5 |
| 407 // seconds, it's time to tear this down. This is the case for the original | 414 // seconds, it's time to tear this down. This is the case for the original |
| 408 // TCP connection on passive side during a reconnect. | 415 // TCP connection on passive side during a reconnect. |
| 409 if (pretending_to_be_writable_) { | 416 if (pretending_to_be_writable_) { |
| 410 set_write_state(STATE_WRITE_TIMEOUT); | 417 // Make sure this connection is destroyed. It will linger around if it |
| 418 // has been READABLE. | |
|
pthatcher1
2015/08/22 05:05:22
This part seems correct. It matches the state dia
guoweis_webrtc
2015/08/22 05:29:50
Will remove.
| |
| 419 Destroy(); | |
| 411 } | 420 } |
| 412 break; | 421 break; |
| 413 default: | 422 default: |
| 414 Connection::OnMessage(pmsg); | 423 Connection::OnMessage(pmsg); |
| 415 } | 424 } |
| 416 } | 425 } |
| 417 | 426 |
| 418 void TCPConnection::MaybeReconnect() { | 427 void TCPConnection::MaybeReconnect() { |
| 419 // Only reconnect for an outgoing TCPConnection when OnClose was signaled and | 428 // Only reconnect for an outgoing TCPConnection when OnClose was signaled and |
| 420 // no outstanding reconnect is pending. | 429 // no outstanding reconnect is pending. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 void TCPConnection::ConnectSocketSignals(rtc::AsyncPacketSocket* socket) { | 476 void TCPConnection::ConnectSocketSignals(rtc::AsyncPacketSocket* socket) { |
| 468 if (outgoing_) { | 477 if (outgoing_) { |
| 469 socket->SignalConnect.connect(this, &TCPConnection::OnConnect); | 478 socket->SignalConnect.connect(this, &TCPConnection::OnConnect); |
| 470 } | 479 } |
| 471 socket->SignalReadPacket.connect(this, &TCPConnection::OnReadPacket); | 480 socket->SignalReadPacket.connect(this, &TCPConnection::OnReadPacket); |
| 472 socket->SignalReadyToSend.connect(this, &TCPConnection::OnReadyToSend); | 481 socket->SignalReadyToSend.connect(this, &TCPConnection::OnReadyToSend); |
| 473 socket->SignalClose.connect(this, &TCPConnection::OnClose); | 482 socket->SignalClose.connect(this, &TCPConnection::OnClose); |
| 474 } | 483 } |
| 475 | 484 |
| 476 } // namespace cricket | 485 } // namespace cricket |
| OLD | NEW |