优化随机端口分配逻辑

This commit is contained in:
xiongziliang 2022-05-14 23:34:33 +08:00
parent 8231c5c293
commit 251fe1f77c
2 changed files with 0 additions and 6 deletions

View File

@ -99,9 +99,6 @@ void RtpServer::start(uint16_t local_port, const string &stream_id, bool enable_
//随机端口rtp端口采用偶数
auto pair = std::make_pair(rtp_socket, rtcp_socket);
makeSockPair(pair, local_ip, re_use_port);
//取偶数端口
rtp_socket = pair.first;
rtcp_socket = pair.second;
} else if (!rtp_socket->bindUdpSock(local_port, local_ip, re_use_port)) {
//用户指定端口
throw std::runtime_error(StrPrinter << "创建rtp端口 " << local_ip << ":" << local_port << " 失败:" << get_uv_errmsg(true));

View File

@ -410,9 +410,6 @@ private:
};
void makeSockPair(std::pair<Socket::Ptr, Socket::Ptr> &pair, const string &local_ip, bool re_use_port, bool is_udp) {
//全局互斥锁保护,防止端口重复分配
static recursive_mutex s_mtx;
lock_guard<recursive_mutex> lck(s_mtx);
int try_count = 0;
while (true) {
try {