mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2024-11-14 04:57:21 +01:00
Small improvements.
This commit is contained in:
parent
38a28ee9ce
commit
059cae3625
@ -138,8 +138,7 @@ public:
|
||||
}
|
||||
|
||||
// set callbacks
|
||||
virtual void setHighWaterMarkCallback(const HighWaterMarkCallback &cb,
|
||||
size_t markLen) override {
|
||||
virtual void setHighWaterMarkCallback(const HighWaterMarkCallback &cb, size_t markLen) override {
|
||||
highWaterMarkCallback_ = cb;
|
||||
highWaterMarkLen_ = markLen;
|
||||
}
|
||||
@ -186,8 +185,7 @@ private:
|
||||
size_t idleTimeout_{ 0 };
|
||||
Date lastTimingWheelUpdateTime_;
|
||||
|
||||
void enableKickingOff(size_t timeout,
|
||||
const std::shared_ptr<TimingWheel> &timingWheel) {
|
||||
void enableKickingOff(size_t timeout, const std::shared_ptr<TimingWheel> &timingWheel) {
|
||||
assert(timingWheel);
|
||||
assert(timingWheel->getLoop() == loop_);
|
||||
assert(timeout > 0);
|
||||
@ -207,15 +205,19 @@ private:
|
||||
void setRecvMsgCallback(const RecvMessageCallback &cb) {
|
||||
recvMsgCallback_ = cb;
|
||||
}
|
||||
|
||||
void setConnectionCallback(const ConnectionCallback &cb) {
|
||||
connectionCallback_ = cb;
|
||||
}
|
||||
|
||||
void setWriteCompleteCallback(const WriteCompleteCallback &cb) {
|
||||
writeCompleteCallback_ = cb;
|
||||
}
|
||||
|
||||
void setCloseCallback(const CloseCallback &cb) {
|
||||
closeCallback_ = cb;
|
||||
}
|
||||
|
||||
void setSSLErrorCallback(const SSLErrorCallback &cb) {
|
||||
sslErrorCallback_ = cb;
|
||||
}
|
||||
|
@ -81,12 +81,7 @@ void TcpServer::newConnection(int sockfd, const InetAddress &peer) {
|
||||
|
||||
if (sslCtxPtr_) {
|
||||
#ifdef USE_OPENSSL
|
||||
newPtr = std::make_shared<TcpConnectionImpl>(
|
||||
ioLoop,
|
||||
sockfd,
|
||||
InetAddress(Socket::getLocalAddr(sockfd)),
|
||||
peer,
|
||||
sslCtxPtr_);
|
||||
newPtr = std::make_shared<TcpConnectionImpl>(ioLoop, sockfd, InetAddress(Socket::getLocalAddr(sockfd)), peer, sslCtxPtr_);
|
||||
#else
|
||||
LOG_FATAL << "OpenSSL is not found in your system!";
|
||||
abort();
|
||||
@ -123,26 +118,21 @@ void TcpServer::start() {
|
||||
loop_->runInLoop([this]() {
|
||||
assert(!started_);
|
||||
started_ = true;
|
||||
|
||||
if (idleTimeout_ > 0) {
|
||||
timingWheelMap_[loop_] =
|
||||
std::make_shared<TimingWheel>(loop_,
|
||||
idleTimeout_,
|
||||
1.0F,
|
||||
idleTimeout_ < 500 ? idleTimeout_ + 1 : 100);
|
||||
timingWheelMap_[loop_] = std::make_shared<TimingWheel>(loop_, idleTimeout_, 1.0F, idleTimeout_ < 500 ? idleTimeout_ + 1 : 100);
|
||||
|
||||
if (loopPoolPtr_) {
|
||||
auto loopNum = loopPoolPtr_->size();
|
||||
while (loopNum > 0) {
|
||||
// LOG_TRACE << "new Wheel loopNum=" << loopNum;
|
||||
auto poolLoop = loopPoolPtr_->getNextLoop();
|
||||
timingWheelMap_[poolLoop] =
|
||||
std::make_shared<TimingWheel>(poolLoop,
|
||||
idleTimeout_,
|
||||
1.0F,
|
||||
idleTimeout_ < 500 ? idleTimeout_ + 1 : 100);
|
||||
timingWheelMap_[poolLoop] = std::make_shared<TimingWheel>(poolLoop, idleTimeout_, 1.0F, idleTimeout_ < 500 ? idleTimeout_ + 1 : 100);
|
||||
--loopNum;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LOG_TRACE << "map size=" << timingWheelMap_.size();
|
||||
acceptorPtr_->listen();
|
||||
});
|
||||
@ -150,17 +140,22 @@ void TcpServer::start() {
|
||||
|
||||
void TcpServer::stop() {
|
||||
loop_->runInLoop([this]() { acceptorPtr_.reset(); });
|
||||
|
||||
for (auto connection : connSet_) {
|
||||
connection->forceClose();
|
||||
}
|
||||
|
||||
loopPoolPtr_.reset();
|
||||
|
||||
for (auto &iter : timingWheelMap_) {
|
||||
std::promise<int> pro;
|
||||
auto f = pro.get_future();
|
||||
|
||||
iter.second->getLoop()->runInLoop([&iter, &pro]() mutable {
|
||||
iter.second.reset();
|
||||
pro.set_value(1);
|
||||
});
|
||||
|
||||
f.get();
|
||||
}
|
||||
}
|
||||
@ -169,9 +164,11 @@ void TcpServer::connectionClosed(const TcpConnectionPtr &connectionPtr) {
|
||||
LOG_TRACE << "connectionClosed";
|
||||
// loop_->assertInLoopThread();
|
||||
loop_->runInLoop([this, connectionPtr]() {
|
||||
|
||||
size_t n = connSet_.erase(connectionPtr);
|
||||
(void)n;
|
||||
assert(n == 1);
|
||||
|
||||
});
|
||||
|
||||
static_cast<TcpConnectionImpl *>(connectionPtr.get())->connectDestroyed();
|
||||
|
Loading…
Reference in New Issue
Block a user