Chromium Code Reviews| Index: webrtc/p2p/base/tcpport.cc |
| diff --git a/webrtc/p2p/base/tcpport.cc b/webrtc/p2p/base/tcpport.cc |
| index 7dc416f923aa7e9925803d7e42e6669d4550f6fa..d77d8e48670c2550c336a02f08a78c355d594efa 100644 |
| --- a/webrtc/p2p/base/tcpport.cc |
| +++ b/webrtc/p2p/base/tcpport.cc |
| @@ -29,32 +29,32 @@ |
| * Data could only be sent in state 3. Sening data during state 2 & 6 will get |
| * EWOULDBLOCK, 4 & 5 EPIPE. |
| * |
| - * 7 -------------+ |
| - * |Connected: N | |
| - * Timeout |Writable: N | Timeout |
| - * +------------------->|Connection is |<----------------+ |
| - * | |Dead | | |
| - * | +--------------+ | |
| - * | ^ | |
| - * | OnClose | | |
| - * | +-----------------------+ | | |
| - * | | | |Timeout | |
| - * | v | | | |
| - * 4 +----------+ 5 -----+--+--+ 6 -----+-----+ |
| - * |Connected: N|Send() or |Connected: N| |Connected: Y| |
| - * |Writable: Y|Ping() |Writable: Y|OnConnect |Writable: Y| |
| - * |PendingTCP:N+--------> |PendingTCP:Y+---------> |PendingTCP:N| |
| - * |PretendWri:Y| |PretendWri:Y| |PretendWri:Y| |
| - * +-----+------+ +------------+ +---+--+-----+ |
| - * ^ ^ | | |
| - * | | OnClose | | |
| - * | +----------------------------------------------+ | |
| - * | | |
| - * | Stun Binding Completed | |
| - * | | |
| - * | OnClose | |
| - * +------------------------------------------------+ | |
| - * | v |
| + * OS Timeout 7 -------------+ |
| + * +----------------------->|Connected: N | |
| + * | |Writable: N | Timeout |
| + * | Timeout |Connection is |<----------------+ |
| + * | +------------------->|Dead | | |
| + * | | +--------------+ | |
| + * | | ^ | |
| + * | | OnClose | | |
| + * | | +-----------------------+ | | |
| + * | | | | |Timeout | |
| + * | | v | | | |
| + * | 4 +----------+ 5 -----+--+--+ 6 -----+-----+ |
| + * | |Connected: N|Send() or |Connected: N| |Connected: Y| |
| + * | |Writable: Y|Ping() |Writable: Y|OnConnect |Writable: Y| |
| + * | |PendingTCP:N+--------> |PendingTCP:Y+---------> |PendingTCP:N| |
| + * | |PretendWri:Y| |PretendWri:Y| |PretendWri:Y| |
| + * | +-----+------+ +------------+ +---+--+-----+ |
| + * | ^ ^ | | |
| + * | | | OnClose | | |
| + * | | +----------------------------------------------+ | |
| + * | | | |
| + * | | Stun Binding Completed | |
| + * | | | |
| + * | | OnClose | |
| + * | +------------------------------------------------+ | |
| + * | | v |
| * 1 -----------+ 2 -----------+Stun 3 -----------+ |
| * |Connected: N| |Connected: Y|Binding |Connected: Y| |
| * |Writable: N|OnConnect |Writable: N|Completed |Writable: Y| |
| @@ -384,7 +384,7 @@ void TCPConnection::OnConnect(rtc::AsyncPacketSocket* socket) { |
| << socket_ip.ToSensitiveString() |
| << ", different from the local candidate IP " |
| << port()->ip().ToSensitiveString(); |
| - socket_->Close(); |
| + OnClose(socket, 0); |
| } |
| } |
| @@ -396,6 +396,8 @@ void TCPConnection::OnClose(rtc::AsyncPacketSocket* socket, int error) { |
| // packet it can't send. |
| if (connected()) { |
| set_connected(false); |
| + |
| + // Prevent the connection to be destroyed. |
|
pthatcher1
2015/08/25 17:58:41
to be destroyed => from being destroyed
|
| pretending_to_be_writable_ = true; |
| // We don't attempt reconnect right here. This is to avoid a case where the |
| @@ -403,6 +405,12 @@ void TCPConnection::OnClose(rtc::AsyncPacketSocket* socket, int error) { |
| // when the connection is used to Send() or Ping(). |
| port()->thread()->PostDelayed(reconnection_timeout(), this, |
| MSG_TCPCONNECTION_DELAYED_ONCLOSE); |
| + } else if (!pretending_to_be_writable_) { |
| + // OnClose could be called when the underneath socket times out during the |
| + // initial connect() (i.e. |pretending_to_be_writable_| is false) . We have |
| + // to manually destroy here as this connection, as never connected, will not |
| + // be scheduled for ping to trigger destroy. |
| + Destroy(); |
| } |
| } |
| @@ -413,7 +421,7 @@ void TCPConnection::OnMessage(rtc::Message* pmsg) { |
| // seconds, it's time to tear this down. This is the case for the original |
| // TCP connection on passive side during a reconnect. |
| if (pretending_to_be_writable_) { |
| - set_write_state(STATE_WRITE_TIMEOUT); |
| + Destroy(); |
| } |
| break; |
| default: |