mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-11-24 00:47:21 +08:00
修复全局变量构造顺序紊乱相关的bug (#4836)
This commit is contained in:
@@ -518,28 +518,10 @@ public:
|
||||
|
||||
static PortManager &Instance() {
|
||||
static auto instance = std::make_shared<PortManager>();
|
||||
static onceToken token([]() { instance->addListenConfigReload(); });
|
||||
return *instance;
|
||||
}
|
||||
|
||||
void addListenConfigReload(){
|
||||
weak_ptr<PortManager> weak_self = this->shared_from_this();
|
||||
static auto func = [weak_self](const string &str, int index) {
|
||||
uint16_t port[] = { 49152, 65535 };
|
||||
auto strong_self = weak_self.lock();
|
||||
if (!strong_self) {
|
||||
return port[index];
|
||||
}
|
||||
sscanf(str.data(), "%" SCNu16 "-%" SCNu16, port, port + 1);
|
||||
strong_self->setRange(port[0], port[1]);
|
||||
return port[index];
|
||||
};
|
||||
|
||||
GET_CONFIG_FUNC(uint16_t, dummy_min_port, kPortRange, [](const string &str) { return func(str, 0); });
|
||||
GET_CONFIG_FUNC(uint16_t, dummy_max_port, kPortRange, [](const string &str) { return func(str, 1); });
|
||||
UNUSED(dummy_min_port);
|
||||
UNUSED(dummy_max_port);
|
||||
}
|
||||
|
||||
std::shared_ptr<uint16_t> getSinglePort() {
|
||||
lock_guard<recursive_mutex> lck(_pool_mtx);
|
||||
if (_port_pool.empty()) {
|
||||
@@ -573,6 +555,25 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
void addListenConfigReload(){
|
||||
weak_ptr<PortManager> weak_self = this->shared_from_this();
|
||||
static auto func = [weak_self](const string &str, int index) {
|
||||
uint16_t port[] = { 49152, 65535 };
|
||||
auto strong_self = weak_self.lock();
|
||||
if (!strong_self) {
|
||||
return port[index];
|
||||
}
|
||||
sscanf(str.data(), "%" SCNu16 "-%" SCNu16, port, port + 1);
|
||||
strong_self->setRange(port[0], port[1]);
|
||||
return port[index];
|
||||
};
|
||||
|
||||
GET_CONFIG_FUNC(uint16_t, dummy_min_port, kPortRange, [](const string &str) { return func(str, 0); });
|
||||
GET_CONFIG_FUNC(uint16_t, dummy_max_port, kPortRange, [](const string &str) { return func(str, 1); });
|
||||
UNUSED(dummy_min_port);
|
||||
UNUSED(dummy_max_port);
|
||||
}
|
||||
|
||||
void setRange(uint16_t min_port, uint16_t max_port) {
|
||||
assert(max_port >= min_port + 36 - 1);
|
||||
lock_guard<recursive_mutex> lck(_pool_mtx);
|
||||
@@ -662,12 +663,6 @@ private:
|
||||
deque<uint16_t> _port_pool;
|
||||
};
|
||||
|
||||
//注册端口管理监听配置重载
|
||||
onceToken PortManager_token([](){
|
||||
PortManager<0>::Instance().addListenConfigReload();
|
||||
PortManager<1>::Instance().addListenConfigReload();
|
||||
});
|
||||
|
||||
static std::mutex s_relayed_session_mutex;
|
||||
std::unordered_map<sockaddr_storage /*peer ip:port*/, IceServer::WeakPtr, toolkit::SockUtil::SockAddrHash, toolkit::SockUtil::SockAddrEqual> _relayed_session;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user