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

From: Denis A Ustimenko <denis(at)oldham(dot)ru>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: droped out precise time calculations in src/interfaces/libpq/fe-connect.c
Date: 2002-10-16 09:50:47
Message-ID: 20021016095047.GA5053@store.oldham.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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 belive that 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dave Tenny 2002-10-16 11:55:07 Re: [JDBC] Out of memory error on huge resultset
Previous Message Justin Clift 2002-10-16 08:34:52 Re: Postgresql and multithreading