Make pg connections automatically reconnect

This commit is contained in:
antao 2019-01-10 15:54:25 +08:00
parent e8c7cf3c72
commit 4e704d398d
1 changed files with 5 additions and 1 deletions

View File

@ -95,6 +95,10 @@ void PgConnection::pgPoll()
{
case PGRES_POLLING_FAILED:
LOG_ERROR << "!!!Pg connection failed: " << PQerrorMessage(_connPtr.get());
if (_status == ConnectStatus_None)
{
handleClosed();
}
break;
case PGRES_POLLING_WRITING:
if (!_channel.isWriting())
@ -149,7 +153,7 @@ void PgConnection::execSql(std::string &&sql,
_isWorking = true;
_exceptCb = std::move(exceptCallback);
auto thisPtr = shared_from_this();
_loop->runInLoop([thisPtr, paraNum=std::move(paraNum), parameters=std::move(parameters), length=std::move(length), format=std::move(format)]() {
_loop->runInLoop([thisPtr, paraNum = std::move(paraNum), parameters = std::move(parameters), length = std::move(length), format = std::move(format)]() {
if (PQsendQueryParams(
thisPtr->_connPtr.get(),
thisPtr->_sql.c_str(),