summaryrefslogtreecommitdiff
path: root/libpqpp/connection.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-12-07 14:15:26 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2015-12-07 14:15:26 +0000
commit6d8b2a4e9efa19e93d5cc3732ab7d00baf7566f1 (patch)
tree2bf6a1310271eddcd5127c34739c4ea6465b2150 /libpqpp/connection.cpp
parentFix leak of error message in exception (diff)
downloadlibdbpp-postgresql-6d8b2a4e9efa19e93d5cc3732ab7d00baf7566f1.tar.bz2
libdbpp-postgresql-6d8b2a4e9efa19e93d5cc3732ab7d00baf7566f1.tar.xz
libdbpp-postgresql-6d8b2a4e9efa19e93d5cc3732ab7d00baf7566f1.zip
Improve connection failure detection
Diffstat (limited to 'libpqpp/connection.cpp')
-rw-r--r--libpqpp/connection.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/libpqpp/connection.cpp b/libpqpp/connection.cpp
index 57531e3..de3f189 100644
--- a/libpqpp/connection.cpp
+++ b/libpqpp/connection.cpp
@@ -3,6 +3,7 @@
#include "selectcommand.h"
#include "modifycommand.h"
#include <unistd.h>
+#include <poll.h>
#include <boost/assert.hpp>
NAMEDFACTORY("postgresql", PQ::Connection, DB::ConnectionFactory);
@@ -108,7 +109,8 @@ PQ::Connection::bulkUpdateStyle() const
void
PQ::Connection::ping() const
{
- if (PQstatus(conn) != CONNECTION_OK) {
+ struct pollfd fd { PQsocket(conn), POLLRDHUP | POLLERR | POLLHUP | POLLNVAL, 0 };
+ if (PQstatus(conn) != CONNECTION_OK || poll(&fd, 1, 1)) {
if (inTx()) {
throw ConnectionError(conn);
}