申请udp端口使用全局互斥锁保护,防止端口重复分配

This commit is contained in:
xiongziliang 2022-01-08 16:07:08 +08:00
parent afc7b019f1
commit 6e445614b4

View File

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