From 4e704d398daf7e36b9521514d6d61fa26a66ca84 Mon Sep 17 00:00:00 2001 From: antao Date: Thu, 10 Jan 2019 15:54:25 +0800 Subject: [PATCH] Make pg connections automatically reconnect --- orm_lib/src/postgresql_impl/PgConnection.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/orm_lib/src/postgresql_impl/PgConnection.cc b/orm_lib/src/postgresql_impl/PgConnection.cc index f6780d1e..d8b833af 100644 --- a/orm_lib/src/postgresql_impl/PgConnection.cc +++ b/orm_lib/src/postgresql_impl/PgConnection.cc @@ -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(),