Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: webrtc/p2p/base/tcpport.cc

Issue 1307083002: TCPConnection can never be deteted if they fail to connect (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/p2p/base/port_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 from being destroyed by redundant SignalClose
401 // events.
399 pretending_to_be_writable_ = true; 402 pretending_to_be_writable_ = true;
400 403
401 // We don't attempt reconnect right here. This is to avoid a case where the 404 // 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 405 // shutdown is intentional and reconnect is not necessary. We only reconnect
403 // when the connection is used to Send() or Ping(). 406 // when the connection is used to Send() or Ping().
404 port()->thread()->PostDelayed(reconnection_timeout(), this, 407 port()->thread()->PostDelayed(reconnection_timeout(), this,
405 MSG_TCPCONNECTION_DELAYED_ONCLOSE); 408 MSG_TCPCONNECTION_DELAYED_ONCLOSE);
409 } else if (!pretending_to_be_writable_) {
410 // OnClose could be called when the underneath socket times out during the
411 // initial connect() (i.e. |pretending_to_be_writable_| is false) . We have
412 // to manually destroy here as this connection, as never connected, will not
413 // be scheduled for ping to trigger destroy.
414 Destroy();
406 } 415 }
407 } 416 }
408 417
409 void TCPConnection::OnMessage(rtc::Message* pmsg) { 418 void TCPConnection::OnMessage(rtc::Message* pmsg) {
410 switch (pmsg->message_id) { 419 switch (pmsg->message_id) {
411 case MSG_TCPCONNECTION_DELAYED_ONCLOSE: 420 case MSG_TCPCONNECTION_DELAYED_ONCLOSE:
412 // If this connection can't become connected and writable again in 5 421 // 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 422 // seconds, it's time to tear this down. This is the case for the original
414 // TCP connection on passive side during a reconnect. 423 // TCP connection on passive side during a reconnect.
415 if (pretending_to_be_writable_) { 424 if (pretending_to_be_writable_) {
416 set_write_state(STATE_WRITE_TIMEOUT); 425 Destroy();
417 } 426 }
418 break; 427 break;
419 default: 428 default:
420 Connection::OnMessage(pmsg); 429 Connection::OnMessage(pmsg);
421 } 430 }
422 } 431 }
423 432
424 void TCPConnection::MaybeReconnect() { 433 void TCPConnection::MaybeReconnect() {
425 // Only reconnect for an outgoing TCPConnection when OnClose was signaled and 434 // Only reconnect for an outgoing TCPConnection when OnClose was signaled and
426 // no outstanding reconnect is pending. 435 // no outstanding reconnect is pending.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 void TCPConnection::ConnectSocketSignals(rtc::AsyncPacketSocket* socket) { 482 void TCPConnection::ConnectSocketSignals(rtc::AsyncPacketSocket* socket) {
474 if (outgoing_) { 483 if (outgoing_) {
475 socket->SignalConnect.connect(this, &TCPConnection::OnConnect); 484 socket->SignalConnect.connect(this, &TCPConnection::OnConnect);
476 } 485 }
477 socket->SignalReadPacket.connect(this, &TCPConnection::OnReadPacket); 486 socket->SignalReadPacket.connect(this, &TCPConnection::OnReadPacket);
478 socket->SignalReadyToSend.connect(this, &TCPConnection::OnReadyToSend); 487 socket->SignalReadyToSend.connect(this, &TCPConnection::OnReadyToSend);
479 socket->SignalClose.connect(this, &TCPConnection::OnClose); 488 socket->SignalClose.connect(this, &TCPConnection::OnClose);
480 } 489 }
481 490
482 } // namespace cricket 491 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/port_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698