H:\webrtc-20210315\webrtc-20210315\webrtc\webrtc-checkout\src\p2p\client\basic_port_allocator.cc
AllocationSequence的作用就是用于分配UDPPort和RelayPort,里面创建了Candidate。
AllocationSequence类
AllocationSequence创建时机
BasicPortAllocatorSession::DoAllocate
AllocationSequence::Init
CreateUdpSocket
H:\webrtc-20210315\webrtc-20210315\webrtc\webrtc-checkout\src\p2p\base\basic_packet_socket_factory.cc
AsyncPacketSocket* CreateUdpSocket(const SocketAddress& local_address, uint16_t min_port, uint16_t max_port) override;
CreateAsyncSocket
AsyncSocket* PhysicalSocketServer::CreateAsyncSocket(int family, int type)
SocketDispatcher::Create
PhysicalSocket::Create
SocketDispatcher::Initialize
bool SocketDispatcher::Initialize() {
RTC_DCHECK(s_ != INVALID_SOCKET);
// Must be a non-blocking
#if defined(WEBRTC_WIN)
u_long argp = 1;
ioctlsocket(s_, FIONBIO, &argp);
#elif defined(WEBRTC_POSIX)
fcntl(s_, F_SETFL, fcntl(s_, F_GETFL, 0) | O_NONBLOCK);
#endif
#if defined(WEBRTC_IOS)
// iOS may kill sockets when the app is moved to the background
// (specifically, if the app doesn't use the "voip" UIBackgroundMode). When
// we attempt to write to such a socket, SIGPIPE will be raised, which by
// default will terminate the process, which we don't want. By specifying
// this socket option, SIGPIPE will be disabled for the socket.
int value = 1;
::setsockopt(s_, SOL_SOCKET, SO_NOSIGPIPE, &value, sizeof(value));
#endif
ss_->Add(this);
return true;
}
创建Socket的调用栈
小结
1、收集candidate
2、BasicPortAllocatorSession::DoAllocate
3、看创建socket的调用堆栈