Index: webrtc/p2p/base/turnport.cc |
diff --git a/webrtc/p2p/base/turnport.cc b/webrtc/p2p/base/turnport.cc |
index 328683b5ae8dbe3126988efc5b00696a6604c9d2..022207aa5b82f157ea15ca919e7d8c75b9f8c7b9 100644 |
--- a/webrtc/p2p/base/turnport.cc |
+++ b/webrtc/p2p/base/turnport.cc |
@@ -409,11 +409,7 @@ void TurnPort::OnSocketConnect(rtc::AsyncPacketSocket* socket) { |
void TurnPort::OnSocketClose(rtc::AsyncPacketSocket* socket, int error) { |
LOG_J(LS_WARNING, this) << "Connection with server failed, error=" << error; |
ASSERT(socket == socket_); |
- if (!ready()) { |
- OnAllocateError(); |
- } |
- request_manager_.Clear(); |
- state_ = STATE_DISCONNECTED; |
+ Close(); |
} |
void TurnPort::OnAllocateMismatch() { |
@@ -717,7 +713,18 @@ void TurnPort::OnAllocateError() { |
thread()->Post(this, MSG_ALLOCATE_ERROR); |
} |
+void TurnPort::OnTurnRefreshError() { |
+ // Need to Close the port asynchronously because otherwise, the refresh |
+ // request may be deleted twice: once at the end of the message processing |
+ // and the other in Close(). |
+ thread()->Post(this, MSG_REFRESH_ERROR); |
+} |
+ |
void TurnPort::Close() { |
+ if (!ready()) { |
+ OnAllocateError(); |
+ } |
+ request_manager_.Clear(); |
// Stop the port from creating new connections. |
state_ = STATE_DISCONNECTED; |
// Delete all existing connections; stop sending data. |
@@ -734,6 +741,9 @@ void TurnPort::OnMessage(rtc::Message* message) { |
case MSG_ALLOCATE_MISMATCH: |
OnAllocateMismatch(); |
break; |
+ case MSG_REFRESH_ERROR: |
+ Close(); |
+ break; |
case MSG_TRY_ALTERNATE_SERVER: |
if (server_address().proto == PROTO_UDP) { |
// Send another allocate request to alternate server, with the received |