Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 38ffd9a

Browse files
deadbeefCommit Bot
authored andcommitted
Merge to M59: Fixing SignalSentPacket for TCP connections.
The signal was only being hooked up for incoming connections, not outgoing connections. As a result, the bandwidth estimator didn't know when packets were sent and couldn't calculate delays. BUG=webrtc:7509 [email protected] NOTRY=True NOPRESUBMIT=True Original Review-Url: https://codereview.webrtc.org/2834083002 Original Cr-Commit-Position: refs/heads/master@{#17817} (cherry picked from commit 0687829) Review-Url: https://codereview.webrtc.org/2917223002 Cr-Commit-Position: refs/branch-heads/59@{#16} Cr-Branched-From: 10d095d-refs/heads/master@{#17657}
1 parent 894c0c6 commit 38ffd9a

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

webrtc/p2p/base/tcpport.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,19 @@ Connection* TCPPort::CreateConnection(const Candidate& address,
157157
TCPConnection* conn = NULL;
158158
if (rtc::AsyncPacketSocket* socket =
159159
GetIncoming(address.address(), true)) {
160+
// Incoming connection; we already created a socket and connected signals,
161+
// so we need to hand off the "read packet" responsibility to
162+
// TCPConnection.
160163
socket->SignalReadPacket.disconnect(this);
161164
conn = new TCPConnection(this, address, socket);
162165
} else {
166+
// Outgoing connection, which will create a new socket for which we still
167+
// need to connect SignalReadyToSend and SignalSentPacket.
163168
conn = new TCPConnection(this, address);
169+
if (conn->socket()) {
170+
conn->socket()->SignalReadyToSend.connect(this, &TCPPort::OnReadyToSend);
171+
conn->socket()->SignalSentPacket.connect(this, &TCPPort::OnSentPacket);
172+
}
164173
}
165174
AddOrReplaceConnection(conn);
166175
return conn;

webrtc/p2p/base/tcpport_unittest.cc

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,58 @@ TEST_F(TCPPortTest, TestTCPPortWithLocalhostAddress) {
8585
lport->CreateConnection(rport->Candidates()[0], Port::ORIGIN_MESSAGE);
8686
EXPECT_TRUE_WAIT(conn->connected(), kTimeout);
8787
}
88+
89+
class SentPacketCounter : public sigslot::has_slots<> {
90+
public:
91+
SentPacketCounter(TCPPort* p) {
92+
p->SignalSentPacket.connect(this, &SentPacketCounter::OnSentPacket);
93+
}
94+
95+
int sent_packets() const { return sent_packets_; }
96+
97+
private:
98+
void OnSentPacket(const rtc::SentPacket&) { ++sent_packets_; }
99+
100+
int sent_packets_ = 0;
101+
};
102+
103+
// Test that SignalSentPacket is fired when a packet is successfully sent, for
104+
// both TCP client and server sockets.
105+
TEST_F(TCPPortTest, SignalSentPacket) {
106+
std::unique_ptr<TCPPort> client(CreateTCPPort(kLocalAddr));
107+
std::unique_ptr<TCPPort> server(CreateTCPPort(kRemoteAddr));
108+
client->SetIceRole(cricket::ICEROLE_CONTROLLING);
109+
server->SetIceRole(cricket::ICEROLE_CONTROLLED);
110+
client->PrepareAddress();
111+
server->PrepareAddress();
112+
113+
Connection* client_conn =
114+
client->CreateConnection(server->Candidates()[0], Port::ORIGIN_MESSAGE);
115+
ASSERT_NE(nullptr, client_conn);
116+
ASSERT_TRUE_WAIT(client_conn->connected(), kTimeout);
117+
118+
// Need to get the port of the actual outgoing socket, not the server socket..
119+
cricket::Candidate client_candidate = client->Candidates()[0];
120+
client_candidate.set_address(static_cast<cricket::TCPConnection*>(client_conn)
121+
->socket()
122+
->GetLocalAddress());
123+
Connection* server_conn =
124+
server->CreateConnection(client_candidate, Port::ORIGIN_THIS_PORT);
125+
ASSERT_NE(nullptr, server_conn);
126+
ASSERT_TRUE_WAIT(server_conn->connected(), kTimeout);
127+
128+
client_conn->Ping(rtc::TimeMillis());
129+
server_conn->Ping(rtc::TimeMillis());
130+
ASSERT_TRUE_WAIT(client_conn->writable(), kTimeout);
131+
ASSERT_TRUE_WAIT(server_conn->writable(), kTimeout);
132+
133+
SentPacketCounter client_counter(client.get());
134+
SentPacketCounter server_counter(server.get());
135+
static const char kData[] = "hello";
136+
for (int i = 0; i < 10; ++i) {
137+
client_conn->Send(&kData, sizeof(kData), rtc::PacketOptions());
138+
server_conn->Send(&kData, sizeof(kData), rtc::PacketOptions());
139+
}
140+
EXPECT_EQ_WAIT(10, client_counter.sent_packets(), kTimeout);
141+
EXPECT_EQ_WAIT(10, server_counter.sent_packets(), kTimeout);
142+
}

0 commit comments

Comments
 (0)