不过该方式很少用,一般都是用udp的candidate或者turn的candidate。
调用栈
AllocationSequence::CreateTCPPorts
void AllocationSequence::CreateTCPPorts() {
if (IsFlagSet(PORTALLOCATOR_DISABLE_TCP)) {
RTC_LOG(LS_VERBOSE) << "AllocationSequence: TCP ports disabled, skipping.";
return;
}
std::unique_ptr<Port> port = TCPPort::Create(
session_->network_thread(), session_->socket_factory(), network_,
session_->allocator()->min_port(), session_->allocator()->max_port(),
session_->username(), session_->password(),
session_->allocator()->allow_tcp_listen());
if (port) {
session_->AddAllocatedPort(port.release(), this, true);
// Since TCPPort is not created using shared socket, |port| will not be
// added to the dequeue.
}
}
TCPPort::TryCreateServerSocket
BasicPacketSocketFactory::CreateServerTcpSocket
AsyncPacketSocket* BasicPacketSocketFactory::CreateServerTcpSocket(
const SocketAddress& local_address,
uint16_t min_port,
uint16_t max_port,
int opts) {
// Fail if TLS is required.
if (opts & PacketSocketFactory::OPT_TLS) {
RTC_LOG(LS_ERROR) << "TLS support currently is not available.";
return NULL;
}
AsyncSocket* socket =
socket_factory()->CreateAsyncSocket(local_address.family(), SOCK_STREAM);
if (!socket) {
return NULL;
}
if (BindSocket(socket, local_address, min_port, max_port) < 0) {
RTC_LOG(LS_ERROR) << "TCP bind failed with error " << socket->GetError();
delete socket;
return NULL;
}
// Set TCP_NODELAY (via OPT_NODELAY) for improved performance; this causes
// small media packets to be sent immediately rather than being buffered up,
// reducing latency.
if (socket->SetOption(Socket::OPT_NODELAY, 1) != 0) {
RTC_LOG(LS_ERROR) << "Setting TCP_NODELAY option failed with error "
<< socket->GetError();
}
// If using fake TLS, wrap the TCP socket in a pseudo-SSL socket.
if (opts & PacketSocketFactory::OPT_TLS_FAKE) {
RTC_DCHECK(!(opts & PacketSocketFactory::OPT_TLS));
socket = new AsyncSSLSocket(socket);
}
if (opts & PacketSocketFactory::OPT_STUN)
return new cricket::AsyncStunTCPSocket(socket, true);
return new AsyncTCPSocket(socket, true);
}
可见里面还包括了tls的处理
AllocationSequence::CreateTCPPorts
-》
BasicPortAllocatorSession::AddAllocatedPort
-》