OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 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 |
11 #include "webrtc/p2p/base/turnserver.h" | 11 #include "webrtc/p2p/base/turnserver.h" |
12 | 12 |
13 #include <tuple> // for std::tie | 13 #include <tuple> // for std::tie |
14 | 14 |
15 #include "webrtc/p2p/base/asyncstuntcpsocket.h" | 15 #include "webrtc/p2p/base/asyncstuntcpsocket.h" |
16 #include "webrtc/p2p/base/common.h" | 16 #include "webrtc/p2p/base/common.h" |
17 #include "webrtc/p2p/base/packetsocketfactory.h" | 17 #include "webrtc/p2p/base/packetsocketfactory.h" |
18 #include "webrtc/p2p/base/stun.h" | 18 #include "webrtc/p2p/base/stun.h" |
| 19 #include "webrtc/base/bind.h" |
19 #include "webrtc/base/bytebuffer.h" | 20 #include "webrtc/base/bytebuffer.h" |
20 #include "webrtc/base/helpers.h" | 21 #include "webrtc/base/helpers.h" |
21 #include "webrtc/base/logging.h" | 22 #include "webrtc/base/logging.h" |
22 #include "webrtc/base/messagedigest.h" | 23 #include "webrtc/base/messagedigest.h" |
23 #include "webrtc/base/socketadapters.h" | 24 #include "webrtc/base/socketadapters.h" |
24 #include "webrtc/base/stringencode.h" | 25 #include "webrtc/base/stringencode.h" |
25 #include "webrtc/base/thread.h" | 26 #include "webrtc/base/thread.h" |
26 | 27 |
27 namespace cricket { | 28 namespace cricket { |
28 | 29 |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 if (it != allocations_.end()) { | 519 if (it != allocations_.end()) { |
519 it->second.release(); | 520 it->second.release(); |
520 allocations_.erase(it); | 521 allocations_.erase(it); |
521 } | 522 } |
522 } | 523 } |
523 | 524 |
524 void TurnServer::DestroyInternalSocket(rtc::AsyncPacketSocket* socket) { | 525 void TurnServer::DestroyInternalSocket(rtc::AsyncPacketSocket* socket) { |
525 InternalSocketMap::iterator iter = server_sockets_.find(socket); | 526 InternalSocketMap::iterator iter = server_sockets_.find(socket); |
526 if (iter != server_sockets_.end()) { | 527 if (iter != server_sockets_.end()) { |
527 rtc::AsyncPacketSocket* socket = iter->first; | 528 rtc::AsyncPacketSocket* socket = iter->first; |
| 529 server_sockets_.erase(iter); |
528 // We must destroy the socket async to avoid invalidating the sigslot | 530 // We must destroy the socket async to avoid invalidating the sigslot |
529 // callback list iterator inside a sigslot callback. | 531 // callback list iterator inside a sigslot callback. (In other words, |
530 rtc::Thread::Current()->Dispose(socket); | 532 // deleting an object from within a callback from that object). |
531 server_sockets_.erase(iter); | 533 sockets_to_delete_.push_back( |
| 534 std::unique_ptr<rtc::AsyncPacketSocket>(socket)); |
| 535 invoker_.AsyncInvoke<void>(RTC_FROM_HERE, rtc::Thread::Current(), |
| 536 rtc::Bind(&TurnServer::FreeSockets, this)); |
532 } | 537 } |
533 } | 538 } |
534 | 539 |
| 540 void TurnServer::FreeSockets() { |
| 541 sockets_to_delete_.clear(); |
| 542 } |
| 543 |
535 TurnServerConnection::TurnServerConnection(const rtc::SocketAddress& src, | 544 TurnServerConnection::TurnServerConnection(const rtc::SocketAddress& src, |
536 ProtocolType proto, | 545 ProtocolType proto, |
537 rtc::AsyncPacketSocket* socket) | 546 rtc::AsyncPacketSocket* socket) |
538 : src_(src), | 547 : src_(src), |
539 dst_(socket->GetRemoteAddress()), | 548 dst_(socket->GetRemoteAddress()), |
540 proto_(proto), | 549 proto_(proto), |
541 socket_(socket) { | 550 socket_(socket) { |
542 } | 551 } |
543 | 552 |
544 bool TurnServerConnection::operator==(const TurnServerConnection& c) const { | 553 bool TurnServerConnection::operator==(const TurnServerConnection& c) const { |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
953 MSG_ALLOCATION_TIMEOUT); | 962 MSG_ALLOCATION_TIMEOUT); |
954 } | 963 } |
955 | 964 |
956 void TurnServerAllocation::Channel::OnMessage(rtc::Message* msg) { | 965 void TurnServerAllocation::Channel::OnMessage(rtc::Message* msg) { |
957 ASSERT(msg->message_id == MSG_ALLOCATION_TIMEOUT); | 966 ASSERT(msg->message_id == MSG_ALLOCATION_TIMEOUT); |
958 SignalDestroyed(this); | 967 SignalDestroyed(this); |
959 delete this; | 968 delete this; |
960 } | 969 } |
961 | 970 |
962 } // namespace cricket | 971 } // namespace cricket |
OLD | NEW |