Re: droped out precise time calculations in src/interfaces/libpq/fe-connect.c - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: droped out precise time calculations in src/interfaces/libpq/fe-connect.c
Date
Msg-id 200210161502.g9GF2Ac25831@candle.pha.pa.us
Whole thread Raw
In response to Re: droped out precise time calculations in src/interfaces/libpq/fe-connect.c  (Denis A Ustimenko <denis@oldham.ru>)
List pgsql-hackers
I will keep this in case we need it later.  I think we worked around
this problem by having timeout == 1 set equal to 2 so we get at least
one second for the connection.

---------------------------------------------------------------------------

Denis A Ustimenko wrote:
> On Mon, Oct 14, 2002 at 01:00:07AM -0400, Bruce Momjian wrote:
> > Denis A Ustimenko wrote:
> > > On Sun, Oct 13, 2002 at 09:02:55PM -0700, Joe Conway wrote:
> > > > Denis A Ustimenko wrote:
> > > > >>Bruce, why have all precise time calculations been droped out in 1.206? 
> > > > >>If there is no
> > > > >>gettimeofday in win32?
> > > > 
> > > > gettimeofday was not portable to win32 (at least not that I could find) and 
> > > > hence broke the win32 build of the clients.
> > > > 
> > > 
> > > GetSystemTimeAsFileTime should help.
> > > 
> > > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getsystemtimeasfiletime.asp
> > 
> > It's not clear to me how we could get this into something we can deal
> > with like gettimeofday.
> > 
> > I looked at the Apache APR project, and they have a routine that returns
> > the microseconds since 1970 for Unix:
> >     
> 
> Here is my version of gettimeofday for win32. It was tested with Watcom C 11.0c. I think it can be used. I still
belivethat fine time calculation is the right way.
 
> 
> #include<stdio.h>
> #ifdef _WIN32
> #include<winsock.h>
> #else
> #include<sys/time.h>
> #endif
> 
> main()
> {
>     struct timeval t;
>     if (gettimeofday(&t,NULL)) {
>         printf("error\n\r");
>     } else {
>         printf("the time is %ld.%ld\n\r", t.tv_sec, t.tv_usec);
>     }
>     fflush(stdout);
> }
> 
> #ifdef _WIN32
> int gettimeofday(struct timeval *tp, void *tzp)
> {
>     FILETIME time;
>     __int64 tmp;
> 
>     if ( NULL == tp) return -1;
> 
>     GetSystemTimeAsFileTime(&time);
> 
>     tmp = time.dwHighDateTime;
>     tmp <<= 32;
>     tmp |= time.dwLowDateTime;
>     tmp /= 10; // it was in 100 nanosecond periods
>     tp->tv_sec = tmp / 1000000 - 11644473600L; // Windows Epoch begins at 12:00 AM 01.01.1601
>     tp->tv_usec = tmp % 1000000;
>     return 0;
> }
> #endif
> 
> 
> 
> -- 
> Regards
> Denis
> 

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073
 


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: droped out precise time calculations in src/interfaces/libpq/fe-connect.c
Next
From: Bruce Momjian
Date:
Subject: Re: droped out precise time calculations in src/interfaces/libpq/fe-connect.c