mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-10-06 20:23:43 +08:00
优化随机端口分配逻辑
This commit is contained in:
parent
8231c5c293
commit
251fe1f77c
|
@ -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));
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user