summaryrefslogtreecommitdiff
path: root/psycopg
diff options
context:
space:
mode:
authorOleksandr Shulgin <oleksandr.shulgin@zalando.de>2015-06-04 11:00:08 +0200
committerOleksandr Shulgin <oleksandr.shulgin@zalando.de>2015-06-04 11:00:08 +0200
commit50df864f8c63144bad281a1de1d6d38d4a06d4aa (patch)
treec5530a447c5e956edaad821c30f83701535cc446 /psycopg
parentf14521f8cb567c98814d392ba7ec196b4a7df77c (diff)
downloadpsycopg2-50df864f8c63144bad281a1de1d6d38d4a06d4aa.tar.gz
Add timersub for Win32. Fix gettimeofday on MinGW.
Diffstat (limited to 'psycopg')
-rw-r--r--psycopg/pqpath.c7
-rw-r--r--psycopg/win32_support.c17
-rw-r--r--psycopg/win32_support.h4
3 files changed, 23 insertions, 5 deletions
diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c
index 4fb4771..e87befa 100644
--- a/psycopg/pqpath.c
+++ b/psycopg/pqpath.c
@@ -1616,15 +1616,14 @@ _pq_copy_both_v3(cursorObject *curs)
ping_time = last_comm;
ping_time.tv_sec += curs->keepalive_interval;
- if (timercmp(&ping_time, &curr_time, >)) {
- timersub(&ping_time, &curr_time, &time_diff);
-
+ timersub(&ping_time, &curr_time, &time_diff);
+ if (time_diff.tv_sec > 0) {
Py_BEGIN_ALLOW_THREADS;
sel = select(PQsocket(conn) + 1, &fds, NULL, NULL, &time_diff);
Py_END_ALLOW_THREADS;
}
else {
- sel = 0; /* pretend select() timed out */
+ sel = 0; /* we're past target time, pretend select() timed out */
}
if (sel < 0) {
diff --git a/psycopg/win32_support.c b/psycopg/win32_support.c
index 8a760b9..d508b22 100644
--- a/psycopg/win32_support.c
+++ b/psycopg/win32_support.c
@@ -29,6 +29,8 @@
#include "psycopg/win32_support.h"
#ifdef _WIN32
+
+#ifndef __MINGW32__
/* millisecond-precision port of gettimeofday for Win32, taken from
src/port/gettimeofday.c in PostgreSQL core */
@@ -58,4 +60,17 @@ gettimeofday(struct timeval * tp, struct timezone * tzp)
return 0;
}
-#endif /* _WIN32 */
+#endif /* !defined(__MINGW32__) */
+
+/* timersub is missing on mingw */
+void
+timersub(struct timeval *a, struct timeval *b, struct timeval *c)
+{
+ c->tv_sec = a->tv_sec - b->tv_sec;
+ c->tv_usec = a->tv_usec - b->tv_usec;
+ if (tv_usec < 0) {
+ c->tv_usec += 1000000;
+ c->tv_sec -= 1;
+ }
+}
+#endif /* defined(_WIN32) */
diff --git a/psycopg/win32_support.h b/psycopg/win32_support.h
index c657731..be963df 100644
--- a/psycopg/win32_support.h
+++ b/psycopg/win32_support.h
@@ -30,7 +30,11 @@
#include <sys/time.h>
#ifdef _WIN32
+#ifndef __MINGW32__
HIDDEN int gettimeofday(struct timeval * tp, struct timezone * tzp);
#endif
+HIDDEN void timersub(struct timeval *a, struct timeval *b, struct timeval *c);
+#endif
+
#endif /* !defined(PSYCOPG_WIN32_SUPPORT_H) */