mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00
Add AsyncListenSocket, as alias for AsyncPacketSocket
A preparation for splitting server sockets out into a separate interface, see https://webrtc-review.googlesource.com/c/src/+/232607. Transition plan: 1. Land this cl. 2. Update downstream code to use the new name. 3. Attempt landing https://webrtc-review.googlesource.com/c/src/+/232607. May need additional steps to not break downstream implementations of PacketSocketFactory::CreateServerTcpSocket. Bug: webrtc:13065 Change-Id: Ife448c705222f4c9f66a096e3dc7eb07e0f9c3af Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/233700 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35155}
This commit is contained in:
parent
a0577605b0
commit
6d19d14c26
9 changed files with 37 additions and 31 deletions
|
@ -59,7 +59,7 @@ class RTC_EXPORT PacketSocketFactory {
|
|||
virtual AsyncPacketSocket* CreateUdpSocket(const SocketAddress& address,
|
||||
uint16_t min_port,
|
||||
uint16_t max_port) = 0;
|
||||
virtual AsyncPacketSocket* CreateServerTcpSocket(
|
||||
virtual AsyncListenSocket* CreateServerTcpSocket(
|
||||
const SocketAddress& local_address,
|
||||
uint16_t min_port,
|
||||
uint16_t max_port,
|
||||
|
|
|
@ -105,7 +105,7 @@ class AsyncStunTCPSocketTest : public ::testing::Test,
|
|||
++sent_packets_;
|
||||
}
|
||||
|
||||
void OnNewConnection(rtc::AsyncPacketSocket* /*server*/,
|
||||
void OnNewConnection(rtc::AsyncListenSocket* /*server*/,
|
||||
rtc::AsyncPacketSocket* new_socket) {
|
||||
recv_socket_ = absl::WrapUnique(new_socket);
|
||||
new_socket->SignalReadPacket.connect(this,
|
||||
|
@ -133,7 +133,7 @@ class AsyncStunTCPSocketTest : public ::testing::Test,
|
|||
std::unique_ptr<rtc::VirtualSocketServer> vss_;
|
||||
rtc::AutoSocketServerThread thread_;
|
||||
std::unique_ptr<AsyncStunTCPSocket> send_socket_;
|
||||
std::unique_ptr<rtc::AsyncPacketSocket> listen_socket_;
|
||||
std::unique_ptr<rtc::AsyncListenSocket> listen_socket_;
|
||||
std::unique_ptr<rtc::AsyncPacketSocket> recv_socket_;
|
||||
std::list<std::string> recv_packets_;
|
||||
int sent_packets_ = 0;
|
||||
|
|
|
@ -50,7 +50,7 @@ AsyncPacketSocket* BasicPacketSocketFactory::CreateUdpSocket(
|
|||
return new AsyncUDPSocket(socket);
|
||||
}
|
||||
|
||||
AsyncPacketSocket* BasicPacketSocketFactory::CreateServerTcpSocket(
|
||||
AsyncListenSocket* BasicPacketSocketFactory::CreateServerTcpSocket(
|
||||
const SocketAddress& local_address,
|
||||
uint16_t min_port,
|
||||
uint16_t max_port,
|
||||
|
|
|
@ -36,7 +36,7 @@ class BasicPacketSocketFactory : public PacketSocketFactory {
|
|||
AsyncPacketSocket* CreateUdpSocket(const SocketAddress& local_address,
|
||||
uint16_t min_port,
|
||||
uint16_t max_port) override;
|
||||
AsyncPacketSocket* CreateServerTcpSocket(const SocketAddress& local_address,
|
||||
AsyncListenSocket* CreateServerTcpSocket(const SocketAddress& local_address,
|
||||
uint16_t min_port,
|
||||
uint16_t max_port,
|
||||
int opts) override;
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
#include "test/field_trial.h"
|
||||
#include "test/gtest.h"
|
||||
|
||||
using rtc::AsyncListenSocket;
|
||||
using rtc::AsyncPacketSocket;
|
||||
using rtc::ByteBufferReader;
|
||||
using rtc::ByteBufferWriter;
|
||||
|
@ -970,12 +971,12 @@ class FakePacketSocketFactory : public rtc::PacketSocketFactory {
|
|||
return result;
|
||||
}
|
||||
|
||||
AsyncPacketSocket* CreateServerTcpSocket(const SocketAddress& local_address,
|
||||
AsyncListenSocket* CreateServerTcpSocket(const SocketAddress& local_address,
|
||||
uint16_t min_port,
|
||||
uint16_t max_port,
|
||||
int opts) override {
|
||||
EXPECT_TRUE(next_server_tcp_socket_ != NULL);
|
||||
AsyncPacketSocket* result = next_server_tcp_socket_;
|
||||
AsyncListenSocket* result = next_server_tcp_socket_;
|
||||
next_server_tcp_socket_ = NULL;
|
||||
return result;
|
||||
}
|
||||
|
@ -995,7 +996,7 @@ class FakePacketSocketFactory : public rtc::PacketSocketFactory {
|
|||
void set_next_udp_socket(AsyncPacketSocket* next_udp_socket) {
|
||||
next_udp_socket_ = next_udp_socket;
|
||||
}
|
||||
void set_next_server_tcp_socket(AsyncPacketSocket* next_server_tcp_socket) {
|
||||
void set_next_server_tcp_socket(AsyncListenSocket* next_server_tcp_socket) {
|
||||
next_server_tcp_socket_ = next_server_tcp_socket;
|
||||
}
|
||||
void set_next_client_tcp_socket(AsyncPacketSocket* next_client_tcp_socket) {
|
||||
|
@ -1008,7 +1009,7 @@ class FakePacketSocketFactory : public rtc::PacketSocketFactory {
|
|||
|
||||
private:
|
||||
AsyncPacketSocket* next_udp_socket_;
|
||||
AsyncPacketSocket* next_server_tcp_socket_;
|
||||
AsyncListenSocket* next_server_tcp_socket_;
|
||||
absl::optional<AsyncPacketSocket*> next_client_tcp_socket_;
|
||||
};
|
||||
|
||||
|
|
|
@ -71,6 +71,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "absl/algorithm/container.h"
|
||||
#include "absl/memory/memory.h"
|
||||
#include "p2p/base/p2p_constants.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/ip_address.h"
|
||||
|
@ -99,7 +100,6 @@ TCPPort::TCPPort(rtc::Thread* thread,
|
|||
username,
|
||||
password),
|
||||
allow_listen_(allow_listen),
|
||||
socket_(NULL),
|
||||
error_(0) {
|
||||
// TODO(mallinath) - Set preference value as per RFC 6544.
|
||||
// http://b/issue?id=7141794
|
||||
|
@ -109,7 +109,7 @@ TCPPort::TCPPort(rtc::Thread* thread,
|
|||
}
|
||||
|
||||
TCPPort::~TCPPort() {
|
||||
delete socket_;
|
||||
listen_socket_ = nullptr;
|
||||
std::list<Incoming>::iterator it;
|
||||
for (it = incoming_.begin(); it != incoming_.end(); ++it)
|
||||
delete it->socket;
|
||||
|
@ -165,16 +165,16 @@ Connection* TCPPort::CreateConnection(const Candidate& address,
|
|||
}
|
||||
|
||||
void TCPPort::PrepareAddress() {
|
||||
if (socket_) {
|
||||
if (listen_socket_) {
|
||||
// Socket may be in the CLOSED state if Listen()
|
||||
// failed, we still want to add the socket address.
|
||||
RTC_LOG(LS_VERBOSE) << "Preparing TCP address, current state: "
|
||||
<< socket_->GetState();
|
||||
if (socket_->GetState() == rtc::AsyncPacketSocket::STATE_BOUND ||
|
||||
socket_->GetState() == rtc::AsyncPacketSocket::STATE_CLOSED)
|
||||
AddAddress(socket_->GetLocalAddress(), socket_->GetLocalAddress(),
|
||||
rtc::SocketAddress(), TCP_PROTOCOL_NAME, "",
|
||||
TCPTYPE_PASSIVE_STR, LOCAL_PORT_TYPE,
|
||||
<< listen_socket_->GetState();
|
||||
if (listen_socket_->GetState() == rtc::AsyncPacketSocket::STATE_BOUND ||
|
||||
listen_socket_->GetState() == rtc::AsyncPacketSocket::STATE_CLOSED)
|
||||
AddAddress(listen_socket_->GetLocalAddress(),
|
||||
listen_socket_->GetLocalAddress(), rtc::SocketAddress(),
|
||||
TCP_PROTOCOL_NAME, "", TCPTYPE_PASSIVE_STR, LOCAL_PORT_TYPE,
|
||||
ICE_TYPE_PREFERENCE_HOST_TCP, 0, "", true);
|
||||
} else {
|
||||
RTC_LOG(LS_INFO) << ToString()
|
||||
|
@ -245,16 +245,16 @@ int TCPPort::SendTo(const void* data,
|
|||
}
|
||||
|
||||
int TCPPort::GetOption(rtc::Socket::Option opt, int* value) {
|
||||
if (socket_) {
|
||||
return socket_->GetOption(opt, value);
|
||||
if (listen_socket_) {
|
||||
return listen_socket_->GetOption(opt, value);
|
||||
} else {
|
||||
return SOCKET_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
int TCPPort::SetOption(rtc::Socket::Option opt, int value) {
|
||||
if (socket_) {
|
||||
return socket_->SetOption(opt, value);
|
||||
if (listen_socket_) {
|
||||
return listen_socket_->SetOption(opt, value);
|
||||
} else {
|
||||
return SOCKET_ERROR;
|
||||
}
|
||||
|
@ -272,9 +272,9 @@ ProtocolType TCPPort::GetProtocol() const {
|
|||
return PROTO_TCP;
|
||||
}
|
||||
|
||||
void TCPPort::OnNewConnection(rtc::AsyncPacketSocket* socket,
|
||||
void TCPPort::OnNewConnection(rtc::AsyncListenSocket* socket,
|
||||
rtc::AsyncPacketSocket* new_socket) {
|
||||
RTC_DCHECK(socket == socket_);
|
||||
RTC_DCHECK(socket == listen_socket_.get());
|
||||
|
||||
Incoming incoming;
|
||||
incoming.addr = new_socket->GetRemoteAddress();
|
||||
|
@ -289,16 +289,16 @@ void TCPPort::OnNewConnection(rtc::AsyncPacketSocket* socket,
|
|||
}
|
||||
|
||||
void TCPPort::TryCreateServerSocket() {
|
||||
socket_ = socket_factory()->CreateServerTcpSocket(
|
||||
listen_socket_ = absl::WrapUnique(socket_factory()->CreateServerTcpSocket(
|
||||
rtc::SocketAddress(Network()->GetBestIP(), 0), min_port(), max_port(),
|
||||
false /* ssl */);
|
||||
if (!socket_) {
|
||||
false /* ssl */));
|
||||
if (!listen_socket_) {
|
||||
RTC_LOG(LS_WARNING)
|
||||
<< ToString()
|
||||
<< ": TCP server socket creation failed; continuing anyway.";
|
||||
return;
|
||||
}
|
||||
socket_->SignalNewConnection.connect(this, &TCPPort::OnNewConnection);
|
||||
listen_socket_->SignalNewConnection.connect(this, &TCPPort::OnNewConnection);
|
||||
}
|
||||
|
||||
rtc::AsyncPacketSocket* TCPPort::GetIncoming(const rtc::SocketAddress& addr,
|
||||
|
|
|
@ -76,7 +76,7 @@ class TCPPort : public Port {
|
|||
bool payload) override;
|
||||
|
||||
// Accepts incoming TCP connection.
|
||||
void OnNewConnection(rtc::AsyncPacketSocket* socket,
|
||||
void OnNewConnection(rtc::AsyncListenSocket* socket,
|
||||
rtc::AsyncPacketSocket* new_socket);
|
||||
|
||||
private:
|
||||
|
@ -103,7 +103,7 @@ class TCPPort : public Port {
|
|||
void OnReadyToSend(rtc::AsyncPacketSocket* socket);
|
||||
|
||||
bool allow_listen_;
|
||||
rtc::AsyncPacketSocket* socket_;
|
||||
std::unique_ptr<rtc::AsyncListenSocket> listen_socket_;
|
||||
int error_;
|
||||
std::list<Incoming> incoming_;
|
||||
|
||||
|
|
|
@ -135,6 +135,11 @@ class RTC_EXPORT AsyncPacketSocket : public sigslot::has_slots<> {
|
|||
RTC_DISALLOW_COPY_AND_ASSIGN(AsyncPacketSocket);
|
||||
};
|
||||
|
||||
// TODO(bugs.webrtc.org/13065): Intended to be broken out into a separate class,
|
||||
// after downstream has adapted the new name. The main feature to move from
|
||||
// AsyncPacketSocket to AsyncListenSocket is the SignalNewConnection.
|
||||
using AsyncListenSocket = AsyncPacketSocket;
|
||||
|
||||
void CopySocketInformationToPacketInfo(size_t packet_size_bytes,
|
||||
const AsyncPacketSocket& socket_from,
|
||||
bool is_connectionless,
|
||||
|
|
|
@ -86,7 +86,7 @@ class PacketSocketFactoryWrapper : public rtc::PacketSocketFactory {
|
|||
return turn_server_->CreatePeerSocket();
|
||||
}
|
||||
|
||||
rtc::AsyncPacketSocket* CreateServerTcpSocket(
|
||||
rtc::AsyncListenSocket* CreateServerTcpSocket(
|
||||
const rtc::SocketAddress& local_address,
|
||||
uint16_t min_port,
|
||||
uint16_t max_port,
|
||||
|
|
Loading…
Reference in a new issue