diff --git a/code/log/log.cpp b/code/log/log.cpp index 0ce1b65..46bc929 100644 --- a/code/log/log.cpp +++ b/code/log/log.cpp @@ -85,11 +85,9 @@ void Log::init(int level = 1, const char* path, const char* suffix, } assert(fp_ != nullptr); } - } void Log::write(int level, const char *format, ...) { - if(isAsync_) { deque_->flush(); } struct timeval now = {0, 0}; gettimeofday(&now, nullptr); time_t tSec = now.tv_sec; @@ -147,7 +145,6 @@ void Log::write(int level, const char *format, ...) { fputs(buff_.Peek(), fp_); } buff_.RetrieveAll(); - } } diff --git a/code/log/log.h b/code/log/log.h index c26b3cd..6bb1a7b 100644 --- a/code/log/log.h +++ b/code/log/log.h @@ -70,6 +70,7 @@ class Log { if (log->IsOpen() && log->GetLevel() <= level) {\ log->write(level, format, ##__VA_ARGS__); \ log->flush();\ + if(isAsync_) { deque_->flush(); } \ }\ } while(0); diff --git a/code/main.cpp b/code/main.cpp index d367045..4a2d100 100644 --- a/code/main.cpp +++ b/code/main.cpp @@ -12,7 +12,7 @@ int main() { WebServer server( 1316, 3, 5000, false, /* 端口 ET模式 timeoutMs 优雅退出 */ 3306, "root", "root", "webserver", /* Mysql配置 */ - 100, 6, true, 0, 0); /* 连接池数量 线程池数量 日志开关 日志等级 日志异步队列容量 */ + 12, 6, false, 0, 1024); /* 连接池数量 线程池数量 日志开关 日志等级 日志异步队列容量 */ server.Start(); } \ No newline at end of file diff --git a/code/server/webserver.cpp b/code/server/webserver.cpp index 363d916..3e61213 100644 --- a/code/server/webserver.cpp +++ b/code/server/webserver.cpp @@ -235,6 +235,8 @@ bool WebServer::InitSocket_() { } int optval = 1; + /* 端口复用 */ + /* 。但是,这些套接字并不是所有都能读取信息,只有最后一个套接字会正常接收数据。 */ ret = setsockopt(listenFd_, SOL_SOCKET, SO_REUSEADDR, (const void*)&optval, sizeof(int)); if(ret == -1) { LOG_ERROR("set socket setsockopt error !");