Fix a mysql issue when connections are lost (#525)

This commit is contained in:
An Tao 2020-08-04 20:04:43 +08:00 committed by GitHub
parent 43a21ddc9c
commit dddc62a9fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 6 deletions

View File

@ -123,10 +123,6 @@ MysqlConnection::MysqlConnection(trantor::EventLoop *loop,
}
channelPtr_ =
std::unique_ptr<trantor::Channel>(new trantor::Channel(loop_, fd));
channelPtr_->setCloseCallback([=]() {
perror("sock close");
handleClosed();
});
channelPtr_->setEventCallback([=]() { handleEvent(); });
setChannel();
});
@ -549,9 +545,12 @@ void MysqlConnection::outputError()
callback_ = nullptr;
isWorking_ = false;
idleCb_();
if (errorNo != CR_SERVER_GONE_ERROR && errorNo != CR_SERVER_LOST)
{
idleCb_();
}
}
if (errorNo == CR_SERVER_GONE_ERROR)
if (errorNo == CR_SERVER_GONE_ERROR || errorNo == CR_SERVER_LOST)
{
handleClosed();
}