mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-29 20:23:45 +03:00
Add timersub for Win32. Fix gettimeofday on MinGW.
This commit is contained in:
parent
f14521f8cb
commit
50df864f8c
|
@ -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) {
|
||||
|
|
|
@ -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) */
|
||||
|
|
|
@ -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) */
|
||||
|
|
Loading…
Reference in New Issue
Block a user