From c0c79ad0667105e66666b5679a9264be58a92bb2 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 7 Dec 2015 14:15:26 +0000 Subject: Improve connection failure detection --- libpqpp/connection.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'libpqpp/connection.cpp') 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 +#include #include 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); } -- cgit v1.2.3