Use callback_list for port destroy operation.
- During the process had to change port_interface sigslot usage and async_packet_socket sigslot usage. - Left the old code until down stream projects are modified. Change-Id: I59149b0bb982bacd4b57fdda51df656a54fe9e68 Bug: webrtc:11943 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/191520 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Jonas Oreland <jonaso@webrtc.org> Reviewed-by: Tommi <tommi@webrtc.org> Reviewed-by: Lahiru Ginnaliya Gamathige <glahiru@webrtc.org> Commit-Queue: Lahiru Ginnaliya Gamathige <glahiru@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33167}
This commit is contained in:
parent
db821652f6
commit
3ba7beba29
@ -118,8 +118,8 @@ class FakePortAllocatorSession : public PortAllocatorSession {
|
||||
username(), password(), std::string(),
|
||||
false));
|
||||
RTC_DCHECK(port_);
|
||||
port_->SignalDestroyed.connect(
|
||||
this, &FakePortAllocatorSession::OnPortDestroyed);
|
||||
port_->SubscribePortDestroyed(
|
||||
[this](PortInterface* port) { OnPortDestroyed(port); });
|
||||
AddPort(port_.get());
|
||||
}
|
||||
++port_config_count_;
|
||||
|
||||
@ -903,7 +903,8 @@ void P2PTransportChannel::OnPortReady(PortAllocatorSession* session,
|
||||
ports_.push_back(port);
|
||||
port->SignalUnknownAddress.connect(this,
|
||||
&P2PTransportChannel::OnUnknownAddress);
|
||||
port->SignalDestroyed.connect(this, &P2PTransportChannel::OnPortDestroyed);
|
||||
port->SubscribePortDestroyed(
|
||||
[this](PortInterface* port) { OnPortDestroyed(port); });
|
||||
|
||||
port->SignalRoleConflict.connect(this, &P2PTransportChannel::OnRoleConflict);
|
||||
port->SignalSentPacket.connect(this, &P2PTransportChannel::OnSentPacket);
|
||||
|
||||
@ -849,6 +849,14 @@ void Port::OnMessage(rtc::Message* pmsg) {
|
||||
}
|
||||
}
|
||||
|
||||
void Port::SubscribePortDestroyed(
|
||||
std::function<void(PortInterface*)> callback) {
|
||||
port_destroyed_callback_list_.AddReceiver(callback);
|
||||
}
|
||||
|
||||
void Port::SendPortDestroyed(Port* port) {
|
||||
port_destroyed_callback_list_.Send(port);
|
||||
}
|
||||
void Port::OnNetworkTypeChanged(const rtc::Network* network) {
|
||||
RTC_DCHECK(network == network_);
|
||||
|
||||
@ -914,6 +922,7 @@ void Port::Destroy() {
|
||||
RTC_DCHECK(connections_.empty());
|
||||
RTC_LOG(LS_INFO) << ToString() << ": Port deleted";
|
||||
SignalDestroyed(this);
|
||||
SendPortDestroyed(this);
|
||||
delete this;
|
||||
}
|
||||
|
||||
|
||||
@ -33,6 +33,7 @@
|
||||
#include "p2p/base/port_interface.h"
|
||||
#include "p2p/base/stun_request.h"
|
||||
#include "rtc_base/async_packet_socket.h"
|
||||
#include "rtc_base/callback_list.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/net_helper.h"
|
||||
#include "rtc_base/network.h"
|
||||
@ -269,6 +270,9 @@ class Port : public PortInterface,
|
||||
// connection.
|
||||
sigslot::signal1<Port*> SignalPortError;
|
||||
|
||||
void SubscribePortDestroyed(
|
||||
std::function<void(PortInterface*)> callback) override;
|
||||
void SendPortDestroyed(Port* port);
|
||||
// Returns a map containing all of the connections of this port, keyed by the
|
||||
// remote address.
|
||||
typedef std::map<rtc::SocketAddress, Connection*> AddressMap;
|
||||
@ -487,6 +491,7 @@ class Port : public PortInterface,
|
||||
bool is_final);
|
||||
|
||||
friend class Connection;
|
||||
webrtc::CallbackList<PortInterface*> port_destroyed_callback_list_;
|
||||
};
|
||||
|
||||
} // namespace cricket
|
||||
|
||||
@ -12,12 +12,14 @@
|
||||
#define P2P_BASE_PORT_INTERFACE_H_
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/candidate.h"
|
||||
#include "p2p/base/transport_description.h"
|
||||
#include "rtc_base/async_packet_socket.h"
|
||||
#include "rtc_base/callback_list.h"
|
||||
#include "rtc_base/socket_address.h"
|
||||
|
||||
namespace rtc {
|
||||
@ -113,6 +115,8 @@ class PortInterface {
|
||||
// Signaled when this port decides to delete itself because it no longer has
|
||||
// any usefulness.
|
||||
sigslot::signal1<PortInterface*> SignalDestroyed;
|
||||
virtual void SubscribePortDestroyed(
|
||||
std::function<void(PortInterface*)> callback) = 0;
|
||||
|
||||
// Signaled when Port discovers ice role conflict with the peer.
|
||||
sigslot::signal1<PortInterface*> SignalRoleConflict;
|
||||
|
||||
@ -270,7 +270,8 @@ class TestChannel : public sigslot::has_slots<> {
|
||||
explicit TestChannel(std::unique_ptr<Port> p1) : port_(std::move(p1)) {
|
||||
port_->SignalPortComplete.connect(this, &TestChannel::OnPortComplete);
|
||||
port_->SignalUnknownAddress.connect(this, &TestChannel::OnUnknownAddress);
|
||||
port_->SignalDestroyed.connect(this, &TestChannel::OnSrcPortDestroyed);
|
||||
port_->SubscribePortDestroyed(
|
||||
[this](PortInterface* port) { OnSrcPortDestroyed(port); });
|
||||
}
|
||||
|
||||
int complete_count() { return complete_count_; }
|
||||
|
||||
@ -335,8 +335,8 @@ class TurnPortTest : public ::testing::Test,
|
||||
this, &TurnPortTest::OnTurnRefreshResult);
|
||||
turn_port_->SignalTurnPortClosed.connect(this,
|
||||
&TurnPortTest::OnTurnPortClosed);
|
||||
turn_port_->SignalDestroyed.connect(this,
|
||||
&TurnPortTest::OnTurnPortDestroyed);
|
||||
turn_port_->SubscribePortDestroyed(
|
||||
[this](PortInterface* port) { OnTurnPortDestroyed(port); });
|
||||
}
|
||||
|
||||
void CreateUdpPort() { CreateUdpPort(kLocalAddr2); }
|
||||
|
||||
@ -900,8 +900,9 @@ void BasicPortAllocatorSession::AddAllocatedPort(Port* port,
|
||||
this, &BasicPortAllocatorSession::OnCandidateError);
|
||||
port->SignalPortComplete.connect(this,
|
||||
&BasicPortAllocatorSession::OnPortComplete);
|
||||
port->SignalDestroyed.connect(this,
|
||||
&BasicPortAllocatorSession::OnPortDestroyed);
|
||||
port->SubscribePortDestroyed(
|
||||
[this](PortInterface* port) { OnPortDestroyed(port); });
|
||||
|
||||
port->SignalPortError.connect(this, &BasicPortAllocatorSession::OnPortError);
|
||||
RTC_LOG(LS_INFO) << port->ToString() << ": Added port to allocator";
|
||||
|
||||
@ -1423,7 +1424,8 @@ void AllocationSequence::CreateUDPPorts() {
|
||||
// UDPPort.
|
||||
if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET)) {
|
||||
udp_port_ = port.get();
|
||||
port->SignalDestroyed.connect(this, &AllocationSequence::OnPortDestroyed);
|
||||
port->SubscribePortDestroyed(
|
||||
[this](PortInterface* port) { OnPortDestroyed(port); });
|
||||
|
||||
// If STUN is not disabled, setting stun server address to port.
|
||||
if (!IsFlagSet(PORTALLOCATOR_DISABLE_STUN)) {
|
||||
@ -1561,8 +1563,10 @@ void AllocationSequence::CreateTurnPort(const RelayServerConfig& config) {
|
||||
|
||||
relay_ports_.push_back(port.get());
|
||||
// Listen to the port destroyed signal, to allow AllocationSequence to
|
||||
// remove entrt from it's map.
|
||||
port->SignalDestroyed.connect(this, &AllocationSequence::OnPortDestroyed);
|
||||
// remove the entry from it's map.
|
||||
port->SubscribePortDestroyed(
|
||||
[this](PortInterface* port) { OnPortDestroyed(port); });
|
||||
|
||||
} else {
|
||||
port = session_->allocator()->relay_port_factory()->Create(
|
||||
args, session_->allocator()->min_port(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user