Skip to content

Commit 256d081

Browse files
authored
Merge pull request #35 from an-tao/dev
Add setIoLoopThreadPool() method to the TcpServer class
2 parents a971095 + 926bd1e commit 256d081

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

trantor/net/TcpServer.cc

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,7 @@ void TcpServer::start()
148148
});
149149
}
150150

151-
void TcpServer::setIoLoopNum(size_t num)
152-
{
153-
assert(num >= 0);
154-
assert(!_started);
155-
_loopPoolPtr =
156-
std::unique_ptr<EventLoopThreadPool>(new EventLoopThreadPool(num));
157-
_loopPoolPtr->start();
158-
}
151+
159152

160153
void TcpServer::connectionClosed(const TcpConnectionPtr &connectionPtr)
161154
{

trantor/net/TcpServer.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,20 @@ class TcpServer : NonCopyable
4646
bool reUsePort = true);
4747
~TcpServer();
4848
void start();
49-
void setIoLoopNum(size_t num);
49+
void setIoLoopNum(size_t num)
50+
{
51+
assert(num >= 0);
52+
assert(!_started);
53+
_loopPoolPtr = std::make_shared<EventLoopThreadPool>(num);
54+
_loopPoolPtr->start();
55+
}
56+
void setIoLoopThreadPool(const std::shared_ptr<EventLoopThreadPool> &pool)
57+
{
58+
assert(pool->getLoopNum() > 0);
59+
assert(!_started);
60+
_loopPoolPtr = pool;
61+
_loopPoolPtr->start();
62+
}
5063
void setRecvMessageCallback(const RecvMessageCallback &cb)
5164
{
5265
_recvMessageCallback = cb;
@@ -112,7 +125,7 @@ class TcpServer : NonCopyable
112125
size_t _idleTimeout = 0;
113126
std::map<EventLoop *, std::shared_ptr<TimingWheel>> _timingWheelMap;
114127
void connectionClosed(const TcpConnectionPtr &connectionPtr);
115-
std::unique_ptr<EventLoopThreadPool> _loopPoolPtr;
128+
std::shared_ptr<EventLoopThreadPool> _loopPoolPtr;
116129
class IgnoreSigPipe
117130
{
118131
public:

trantor/utils/Logger.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ Logger::Logger(SourceFile file, int line, bool isSysErr)
126126
: sourceFile_(file), fileLine_(line), level_(FATAL)
127127
{
128128
formatTime();
129+
logStream_ << T(logLevelStr[level_], 7);
129130
if (errno != 0)
130131
{
131-
logStream_ << T(logLevelStr[level_], 7);
132132
logStream_ << strerror(errno) << " (errno=" << errno << ") ";
133133
}
134134
}

0 commit comments

Comments
 (0)