summaryrefslogtreecommitdiff
path: root/psycopg/pqpath.c
diff options
context:
space:
mode:
authorOleksandr Shulgin <oleksandr.shulgin@zalando.de>2015-07-02 14:39:51 +0200
committerOleksandr Shulgin <oleksandr.shulgin@zalando.de>2015-07-02 14:39:51 +0200
commit9c1f2acf3e3608ba0d13b0b3c3d01b68f2a29d90 (patch)
tree1ca5b4fbadc84cc4385925686a5fc4d731dd5b2e /psycopg/pqpath.c
parentdab41c699a3e20a3577ad52529d879741185df13 (diff)
downloadpsycopg2-9c1f2acf3e3608ba0d13b0b3c3d01b68f2a29d90.tar.gz
Check return value of PQsocket
When connection is closed by the server, we might get -1 there.
Diffstat (limited to 'psycopg/pqpath.c')
-rw-r--r--psycopg/pqpath.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c
index ed8b37f..e550d79 100644
--- a/psycopg/pqpath.c
+++ b/psycopg/pqpath.c
@@ -1689,13 +1689,10 @@ _pq_copy_both_v3(cursorObject *curs)
{
PyObject *msg, *tmp = NULL;
PyObject *write_func = NULL;
- int ret = -1;
- int is_text;
-
+ int is_text, fd, sel, ret = -1;
PGconn *pgconn;
fd_set fds;
struct timeval curr_time, ping_time, time_diff;
- int sel;
if (!curs->copyfile) {
psyco_set_error(ProgrammingError, curs,
@@ -1724,8 +1721,14 @@ _pq_copy_both_v3(cursorObject *curs)
else if (msg == Py_None) {
Py_DECREF(msg);
+ fd = PQsocket(pgconn);
+ if (fd < 0) {
+ pq_raise(curs->conn, curs, NULL);
+ goto exit;
+ }
+
FD_ZERO(&fds);
- FD_SET(PQsocket(pgconn), &fds);
+ FD_SET(fd, &fds);
gettimeofday(&curr_time, NULL);
@@ -1736,7 +1739,7 @@ _pq_copy_both_v3(cursorObject *curs)
timersub(&ping_time, &curr_time, &time_diff);
if (time_diff.tv_sec > 0) {
Py_BEGIN_ALLOW_THREADS;
- sel = select(PQsocket(pgconn) + 1, &fds, NULL, NULL, &time_diff);
+ sel = select(fd + 1, &fds, NULL, NULL, &time_diff);
Py_END_ALLOW_THREADS;
}
else {