Delete unused listen-mode of AsyncStunTCPSocket

Small step towards using separate classes for TCP server sockets.
Added a new test-only class AsyncStunServerTCPSocket needed
for unit tests of AsyncStunTCPSocket.

Bug: webrtc:13065
Change-Id: I7d9713983d8f6b30aa3d3e7442bb34ea48b815eb
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/232324
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35047}
This commit is contained in:
Niels Möller 2021-09-17 16:27:56 +02:00 committed by WebRTC LUCI CQ
parent a37fa66463
commit 6da016ff71
5 changed files with 20 additions and 13 deletions

View File

@ -45,12 +45,11 @@ AsyncStunTCPSocket* AsyncStunTCPSocket::Create(
const rtc::SocketAddress& bind_address,
const rtc::SocketAddress& remote_address) {
return new AsyncStunTCPSocket(
AsyncTCPSocketBase::ConnectSocket(socket, bind_address, remote_address),
false);
AsyncTCPSocketBase::ConnectSocket(socket, bind_address, remote_address));
}
AsyncStunTCPSocket::AsyncStunTCPSocket(rtc::Socket* socket, bool listen)
: rtc::AsyncTCPSocketBase(socket, listen, kBufSize) {}
AsyncStunTCPSocket::AsyncStunTCPSocket(rtc::Socket* socket)
: rtc::AsyncTCPSocketBase(socket, /*listen=*/false, kBufSize) {}
int AsyncStunTCPSocket::Send(const void* pv,
size_t cb,
@ -127,7 +126,7 @@ void AsyncStunTCPSocket::ProcessInput(char* data, size_t* len) {
}
void AsyncStunTCPSocket::HandleIncomingConnection(rtc::Socket* socket) {
SignalNewConnection(this, new AsyncStunTCPSocket(socket, false));
SignalNewConnection(this, new AsyncStunTCPSocket(socket));
}
size_t AsyncStunTCPSocket::GetExpectedLength(const void* data,

View File

@ -30,7 +30,7 @@ class AsyncStunTCPSocket : public rtc::AsyncTCPSocketBase {
const rtc::SocketAddress& bind_address,
const rtc::SocketAddress& remote_address);
AsyncStunTCPSocket(rtc::Socket* socket, bool listen);
explicit AsyncStunTCPSocket(rtc::Socket* socket);
int Send(const void* pv,
size_t cb,

View File

@ -58,6 +58,15 @@ static unsigned char kTurnChannelDataMessageWithOddLength[] = {
static const rtc::SocketAddress kClientAddr("11.11.11.11", 0);
static const rtc::SocketAddress kServerAddr("22.22.22.22", 0);
class AsyncStunServerTCPSocket : public rtc::AsyncTCPSocket {
public:
explicit AsyncStunServerTCPSocket(rtc::Socket* socket)
: AsyncTCPSocket(socket, true) {}
void HandleIncomingConnection(rtc::Socket* socket) override {
SignalNewConnection(this, new AsyncStunTCPSocket(socket));
}
};
class AsyncStunTCPSocketTest : public ::testing::Test,
public sigslot::has_slots<> {
protected:
@ -69,7 +78,7 @@ class AsyncStunTCPSocketTest : public ::testing::Test,
void CreateSockets() {
rtc::Socket* server = vss_->CreateSocket(kServerAddr.family(), SOCK_STREAM);
server->Bind(kServerAddr);
recv_socket_.reset(new AsyncStunTCPSocket(server, true));
recv_socket_.reset(new AsyncStunServerTCPSocket(server));
recv_socket_->SignalNewConnection.connect(
this, &AsyncStunTCPSocketTest::OnNewConnection);
@ -95,7 +104,7 @@ class AsyncStunTCPSocketTest : public ::testing::Test,
++sent_packets_;
}
void OnNewConnection(rtc::AsyncPacketSocket* server,
void OnNewConnection(rtc::AsyncPacketSocket* /*server*/,
rtc::AsyncPacketSocket* new_socket) {
listen_socket_.reset(new_socket);
new_socket->SignalReadPacket.connect(this,
@ -123,7 +132,7 @@ class AsyncStunTCPSocketTest : public ::testing::Test,
std::unique_ptr<rtc::VirtualSocketServer> vss_;
rtc::AutoSocketServerThread thread_;
std::unique_ptr<AsyncStunTCPSocket> send_socket_;
std::unique_ptr<AsyncStunTCPSocket> recv_socket_;
std::unique_ptr<rtc::AsyncPacketSocket> recv_socket_;
std::unique_ptr<rtc::AsyncPacketSocket> listen_socket_;
std::list<std::string> recv_packets_;
int sent_packets_ = 0;

View File

@ -92,8 +92,7 @@ AsyncPacketSocket* BasicPacketSocketFactory::CreateServerTcpSocket(
socket = new AsyncSSLSocket(socket);
}
if (opts & PacketSocketFactory::OPT_STUN)
return new cricket::AsyncStunTCPSocket(socket, true);
RTC_CHECK(!(opts & PacketSocketFactory::OPT_STUN));
return new AsyncTCPSocket(socket, true);
}
@ -187,7 +186,7 @@ AsyncPacketSocket* BasicPacketSocketFactory::CreateClientTcpSocket(
// Finally, wrap that socket in a TCP or STUN TCP packet socket.
AsyncPacketSocket* tcp_socket;
if (tcp_options.opts & PacketSocketFactory::OPT_STUN) {
tcp_socket = new cricket::AsyncStunTCPSocket(socket, false);
tcp_socket = new cricket::AsyncStunTCPSocket(socket);
} else {
tcp_socket = new AsyncTCPSocket(socket, false);
}

View File

@ -183,7 +183,7 @@ void TurnServer::AcceptConnection(rtc::Socket* server_socket) {
if (accepted_socket != NULL) {
ProtocolType proto = server_listen_sockets_[server_socket];
cricket::AsyncStunTCPSocket* tcp_socket =
new cricket::AsyncStunTCPSocket(accepted_socket, false);
new cricket::AsyncStunTCPSocket(accepted_socket);
tcp_socket->SignalClose.connect(this, &TurnServer::OnInternalSocketClose);
// Finally add the socket so it can start communicating with the client.