From 132da0bc7454e333683abe245ef853e9e366a7ed Mon Sep 17 00:00:00 2001 From: caozhiyi Date: Mon, 2 Sep 2019 21:41:17 +0800 Subject: [PATCH] fix only thread active bug. --- base/Log.cpp | 10 +++++----- net/CppNetImpl.cpp | 8 ++++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/base/Log.cpp b/base/Log.cpp index d59dec4..868fd59 100644 --- a/base/Log.cpp +++ b/base/Log.cpp @@ -54,7 +54,7 @@ LogLevel CLog::GetLogLevel() { } void CLog::LogDebug(const char* file, int line, const char* log...) { - if (!_stop) { + if (_stop) { return; } if (_log_level <= LOG_DEBUG_LEVEL) { @@ -66,7 +66,7 @@ void CLog::LogDebug(const char* file, int line, const char* log...) { } void CLog::LogInfo(const char* file, int line, const char* log...) { - if (!_stop) { + if (_stop) { return; } if (_log_level <= LOG_INFO_LEVEL) { @@ -78,7 +78,7 @@ void CLog::LogInfo(const char* file, int line, const char* log...) { } void CLog::LogWarn(const char* file, int line, const char* log...) { - if (!_stop) { + if (_stop) { return; } if (_log_level <= LOG_WARN_LEVEL) { @@ -90,7 +90,7 @@ void CLog::LogWarn(const char* file, int line, const char* log...) { } void CLog::LogError(const char* file, int line, const char* log...) { - if (!_stop) { + if (_stop) { return; } if (_log_level <= LOG_ERROR_LEVEL) { @@ -102,7 +102,7 @@ void CLog::LogError(const char* file, int line, const char* log...) { } void CLog::LogFatal(const char* file, int line, const char* log...) { - if (!_stop) { + if (_stop) { return; } if (_log_level <= LOG_FATAL_LEVEL) { diff --git a/net/CppNetImpl.cpp b/net/CppNetImpl.cpp index c4c4306..509ea47 100644 --- a/net/CppNetImpl.cpp +++ b/net/CppNetImpl.cpp @@ -23,7 +23,9 @@ CCppNetImpl::CCppNetImpl() : _per_epoll_handle(true) { } CCppNetImpl::~CCppNetImpl() { - + _thread_vec.clear(); + _actions_map.clear(); + _accept_socket.clear(); } void CCppNetImpl::Init(uint32_t thread_num, bool per_handl_thread) { @@ -150,12 +152,14 @@ bool CCppNetImpl::ListenAndAccept(uint16_t port, std::string ip, uint32_t listen } for (auto iter = _actions_map.begin(); iter != _actions_map.end(); ++iter) { - base::CMemSharePtr accept_socket = base::MakeNewSharedPtr(&_pool, _actions_map.begin()->second); + base::CMemSharePtr accept_socket = base::MakeNewSharedPtr(&_pool, iter->second); if (!accept_socket->Bind(port, ip)) { + base::LOG_ERROR("bind failed. port : %d, ip : %s ", port, ip.c_str()); return false; } if (!accept_socket->Listen(listen_num)) { + base::LOG_ERROR("listen failed. port : %d, ip : %s ", port, ip.c_str()); return false; }