Connect TurnPort and TCPPort to AsyncPacketSocket::SignalSentPacket.
To reduce the risk of future mistakes when connecting Ports, Port::OnSentPacket was made pure virtual to ensure that new implementations take care of it.
BUG=4173
R=pthatcher@webrtc.org
Review URL: https://codereview.webrtc.org/1577873003 .
Cr-Commit-Position: refs/heads/master@{#11247}
diff --git a/webrtc/p2p/base/p2ptransportchannel.cc b/webrtc/p2p/base/p2ptransportchannel.cc
index c58a235..952cfab 100644
--- a/webrtc/p2p/base/p2ptransportchannel.cc
+++ b/webrtc/p2p/base/p2ptransportchannel.cc
@@ -1424,8 +1424,7 @@
}
}
-void P2PTransportChannel::OnSentPacket(PortInterface* port,
- const rtc::SentPacket& sent_packet) {
+void P2PTransportChannel::OnSentPacket(const rtc::SentPacket& sent_packet) {
ASSERT(worker_thread_ == rtc::Thread::Current());
SignalSentPacket(this, sent_packet);
diff --git a/webrtc/p2p/base/p2ptransportchannel.h b/webrtc/p2p/base/p2ptransportchannel.h
index 3927b17..f2e9315 100644
--- a/webrtc/p2p/base/p2ptransportchannel.h
+++ b/webrtc/p2p/base/p2ptransportchannel.h
@@ -232,7 +232,7 @@
void OnConnectionStateChange(Connection* connection);
void OnReadPacket(Connection *connection, const char *data, size_t len,
const rtc::PacketTime& packet_time);
- void OnSentPacket(PortInterface* port, const rtc::SentPacket& sent_packet);
+ void OnSentPacket(const rtc::SentPacket& sent_packet);
void OnReadyToSend(Connection* connection);
void OnConnectionDestroyed(Connection *connection);
diff --git a/webrtc/p2p/base/port.cc b/webrtc/p2p/base/port.cc
index f6a3009..9dd5c83 100644
--- a/webrtc/p2p/base/port.cc
+++ b/webrtc/p2p/base/port.cc
@@ -310,10 +310,6 @@
}
}
-void Port::OnSentPacket(const rtc::SentPacket& sent_packet) {
- PortInterface::SignalSentPacket(this, sent_packet);
-}
-
void Port::OnReadyToSend() {
AddressMap::iterator iter = connections_.begin();
for (; iter != connections_.end(); ++iter) {
diff --git a/webrtc/p2p/base/port.h b/webrtc/p2p/base/port.h
index 57608b5..436b1e7 100644
--- a/webrtc/p2p/base/port.h
+++ b/webrtc/p2p/base/port.h
@@ -280,7 +280,11 @@
const std::string& remote_ufrag);
// Called when a packet has been sent to the socket.
- void OnSentPacket(const rtc::SentPacket& sent_packet);
+ // This is made pure virtual to notify subclasses of Port that they MUST
+ // listen to AsyncPacketSocket::SignalSentPacket and then call
+ // PortInterface::OnSentPacket.
+ virtual void OnSentPacket(rtc::AsyncPacketSocket* socket,
+ const rtc::SentPacket& sent_packet) = 0;
// Called when the socket is currently able to send.
void OnReadyToSend();
diff --git a/webrtc/p2p/base/port_unittest.cc b/webrtc/p2p/base/port_unittest.cc
index 34806d9..449021ad 100644
--- a/webrtc/p2p/base/port_unittest.cc
+++ b/webrtc/p2p/base/port_unittest.cc
@@ -204,6 +204,10 @@
}
private:
+ void OnSentPacket(rtc::AsyncPacketSocket* socket,
+ const rtc::SentPacket& sent_packet) {
+ PortInterface::SignalSentPacket(sent_packet);
+ }
rtc::scoped_ptr<ByteBuffer> last_stun_buf_;
rtc::scoped_ptr<IceMessage> last_stun_msg_;
int type_preference_ = 0;
diff --git a/webrtc/p2p/base/portinterface.h b/webrtc/p2p/base/portinterface.h
index d1c371d..e83879f 100644
--- a/webrtc/p2p/base/portinterface.h
+++ b/webrtc/p2p/base/portinterface.h
@@ -116,7 +116,7 @@
const rtc::SocketAddress&> SignalReadPacket;
// Emitted each time a packet is sent on this port.
- sigslot::signal2<PortInterface*, const rtc::SentPacket&> SignalSentPacket;
+ sigslot::signal1<const rtc::SentPacket&> SignalSentPacket;
virtual std::string ToString() const = 0;
diff --git a/webrtc/p2p/base/relayport.cc b/webrtc/p2p/base/relayport.cc
index 88adcf2..19883a3 100644
--- a/webrtc/p2p/base/relayport.cc
+++ b/webrtc/p2p/base/relayport.cc
@@ -754,7 +754,7 @@
void RelayEntry::OnSentPacket(rtc::AsyncPacketSocket* socket,
const rtc::SentPacket& sent_packet) {
- port_->OnSentPacket(sent_packet);
+ port_->OnSentPacket(socket, sent_packet);
}
void RelayEntry::OnReadyToSend(rtc::AsyncPacketSocket* socket) {
diff --git a/webrtc/p2p/base/relayport.h b/webrtc/p2p/base/relayport.h
index 4b74b91..fdbf6e6 100644
--- a/webrtc/p2p/base/relayport.h
+++ b/webrtc/p2p/base/relayport.h
@@ -29,7 +29,7 @@
// is created. The RelayEntry will try to reach the remote destination
// by connecting to all available server addresses in a pre defined
// order with a small delay in between. When a connection is
-// successful all other connection attemts are aborted.
+// successful all other connection attempts are aborted.
class RelayPort : public Port {
public:
typedef std::pair<rtc::Socket::Option, int> OptionValue;
@@ -96,6 +96,11 @@
ProtocolType proto,
const rtc::PacketTime& packet_time);
+ // The OnSentPacket callback is left empty here since they are handled by
+ // RelayEntry.
+ void OnSentPacket(rtc::AsyncPacketSocket* socket,
+ const rtc::SentPacket& sent_packet) override {}
+
private:
friend class RelayEntry;
diff --git a/webrtc/p2p/base/stunport.cc b/webrtc/p2p/base/stunport.cc
index 67cf789..8f37dd5 100644
--- a/webrtc/p2p/base/stunport.cc
+++ b/webrtc/p2p/base/stunport.cc
@@ -340,7 +340,7 @@
void UDPPort::OnSentPacket(rtc::AsyncPacketSocket* socket,
const rtc::SentPacket& sent_packet) {
- Port::OnSentPacket(sent_packet);
+ PortInterface::SignalSentPacket(sent_packet);
}
void UDPPort::OnReadyToSend(rtc::AsyncPacketSocket* socket) {
diff --git a/webrtc/p2p/base/tcpport.cc b/webrtc/p2p/base/tcpport.cc
index 23afc2f..6a64174 100644
--- a/webrtc/p2p/base/tcpport.cc
+++ b/webrtc/p2p/base/tcpport.cc
@@ -258,6 +258,7 @@
incoming.socket = new_socket;
incoming.socket->SignalReadPacket.connect(this, &TCPPort::OnReadPacket);
incoming.socket->SignalReadyToSend.connect(this, &TCPPort::OnReadyToSend);
+ incoming.socket->SignalSentPacket.connect(this, &TCPPort::OnSentPacket);
LOG_J(LS_VERBOSE, this) << "Accepted connection from "
<< incoming.addr.ToSensitiveString();
@@ -286,6 +287,12 @@
Port::OnReadPacket(data, size, remote_addr, PROTO_TCP);
}
+void TCPPort::OnSentPacket(rtc::AsyncPacketSocket* socket,
+ const rtc::SentPacket& sent_packet) {
+ ASSERT(socket == socket_);
+ PortInterface::SignalSentPacket(sent_packet);
+}
+
void TCPPort::OnReadyToSend(rtc::AsyncPacketSocket* socket) {
Port::OnReadyToSend();
}
diff --git a/webrtc/p2p/base/tcpport.h b/webrtc/p2p/base/tcpport.h
index 568dc65..b298a17 100644
--- a/webrtc/p2p/base/tcpport.h
+++ b/webrtc/p2p/base/tcpport.h
@@ -96,6 +96,9 @@
const rtc::SocketAddress& remote_addr,
const rtc::PacketTime& packet_time);
+ void OnSentPacket(rtc::AsyncPacketSocket* socket,
+ const rtc::SentPacket& sent_packet) override;
+
void OnReadyToSend(rtc::AsyncPacketSocket* socket);
void OnAddressReady(rtc::AsyncPacketSocket* socket,
diff --git a/webrtc/p2p/base/turnport.cc b/webrtc/p2p/base/turnport.cc
index 022207a..5ed93dd 100644
--- a/webrtc/p2p/base/turnport.cc
+++ b/webrtc/p2p/base/turnport.cc
@@ -351,6 +351,8 @@
socket_->SignalReadyToSend.connect(this, &TurnPort::OnReadyToSend);
+ socket_->SignalSentPacket.connect(this, &TurnPort::OnSentPacket);
+
// TCP port is ready to send stun requests after the socket is connected,
// while UDP port is ready to do so once the socket is created.
if (server_address_.proto == PROTO_TCP) {
@@ -582,6 +584,11 @@
}
}
+void TurnPort::OnSentPacket(rtc::AsyncPacketSocket* socket,
+ const rtc::SentPacket& sent_packet) {
+ PortInterface::SignalSentPacket(sent_packet);
+}
+
void TurnPort::OnReadyToSend(rtc::AsyncPacketSocket* socket) {
if (ready()) {
Port::OnReadyToSend();
diff --git a/webrtc/p2p/base/turnport.h b/webrtc/p2p/base/turnport.h
index a19f676..4d83806 100644
--- a/webrtc/p2p/base/turnport.h
+++ b/webrtc/p2p/base/turnport.h
@@ -106,6 +106,8 @@
const rtc::SocketAddress& remote_addr,
const rtc::PacketTime& packet_time);
+ virtual void OnSentPacket(rtc::AsyncPacketSocket* socket,
+ const rtc::SentPacket& sent_packet);
virtual void OnReadyToSend(rtc::AsyncPacketSocket* socket);
virtual bool SupportsProtocol(const std::string& protocol) const {
// Turn port only connects to UDP candidates.