Opened 20 years ago

Closed 20 years ago

#602 closed defect (fixed)

timeval structure and gettimeofday on windows

Reported by: assefa Owned by: sdlime
Priority: high Milestone:
Component: MapServer C Library Version: 4.1
Severity: major Keywords:
Cc: sgillies@…, nhv@…


I was having trouble yesterday builing mapserver on windows.

Couple of issues :

  - the timval structure is available on windows (in winsock.h) but including 
this was leading to other undfined symbols. I could not quickly figure out 
what was wrong.

  - gettimeofday seems to be unavailable on Windows.

 To be able to build this I did the following modifications :

 - define an mstimeval structure (equivalent to timeval) inside maptime.h and 
modify all code to refer to this new structure

 - define a function gettimeofday in maptime.c that would be avilable on 
windows.  Right now the function is only available inside #ifdef windows. 

 I have this modified loaclly but not commited. What do you think about the 
changes ?

   to use this structure instaed

Change History (15)

comment:1 by assefa, 20 years ago

Cc: mapserver-bugs@… added
add in cc

comment:2 by sdlime, 20 years ago

I need to check the source, what a pain in the butt. What windows time 
functionality is there? I'll look today and get back with you. Much of that 
code will likely change anyway.


comment:3 by dmorissette, 20 years ago

FYI Steve, I was the one who added the use of gettimeofday() to produce timing
reports in msDrawMap()... useful for tuning mapfiles or finding why things are
slow sometimes.

comment:4 by sdlime, 20 years ago

I didn't remember using that function, thanks for the update. If that's how 
it's being used, just for timing, then there's probably no reason not to 
commit the fix right?


comment:5 by sgillies@…, 20 years ago

Cc: sgillies@… added
op_sys: Windows XPWindows 2000

comment:6 by nhv@…, 20 years ago

#if defined(_MSC_VER) || defined(__MINGW32__)
#  include <time.h>
#ifndef _TIMEVAL_DEFINED /* also in winsock[2].h */
struct timeval {
    long tv_sec;
    long tv_usec;
#endif /* _TIMEVAL_DEFINED */
#  include <sys/time.h>

#if defined(_MSC_VER) || defined(__MINGW32__)
int gettimeofday(struct timeval* tp, void* tzp) {
    DWORD t;
    t = timeGetTime();
    tp->tv_sec = t / 1000;
    tp->tv_usec = t % 1000;
    /* 0 indicates that the call succeeded. */
    return 0;

comment:7 by sdlime, 20 years ago

That'll work, thanks Norman.

comment:8 by sgillies@…, 20 years ago

Severity: normalcritical
Should've bumped up the severity when I cc'd myself.  How about we rollback
the changes that broke MapServer until we get a fix?  Where would I start?

comment:9 by sdlime, 20 years ago

Can't Assefa or someone else just apply Noman's code? Looks pretty straight 
forward if he's right. I've no idea ho big Daniel's modifications were or when 
they were done.


comment:10 by sgillies@…, 20 years ago

Severity: criticalmajor
Nevermind, I'll roll it back in my own checkout
   cvs update -j 1.56 -j 1.54 mapdraw.c

and lower the severity.  Apologies for the noise.

comment:11 by assefa, 20 years ago

I am out of the office for a couple of days. I will look into it tomoroow.

comment:12 by dmorissette, 20 years ago

Cc: nhv@… added
Thanks for the patch Norman. Just one quick note: the tv_usec member is in
microseconds, so I think we should change its value to:
   tp->tv_usec = (t % 1000) * 1000;

I would propose that the include part of Norman's patch be added to maptime.h,
and the definition of gettimeofday to maptime.c, then a #include "maptime.h" may
need to be added to the files that call gettimeofday().  

Can someone test and apply the patch on Windows please?

comment:13 by assefa, 20 years ago

I have commited the changes so we can do a build on windows.

I have used the mstimeval internal structure as described earlier. the ifdef did
not work since other dependant libraries (libcurl, php) include winsock.  If
someone else want to do other modifications, please look into files maptime.c/h

comment:14 by dmorissette, 20 years ago

Your changes break things on Linux/Unix because gettimeofday() doesn't like the
custom struct mstimeval... there has to be a clean way to solve that.  I'll look
at what curl does.

comment:15 by dmorissette, 20 years ago

Resolution: fixed
Status: newclosed
Curl seems to have a better solution to this problem in lib/timeval.c and
lib/timeval.h but I can't test it on windows.  :(

For now I have modified the definition of gettimeofday() in maptime.c to be
msGettimeofday(), this should work fine on windows together with the custom
struct mstimeval.

On Unix/Linux, there are #defines that map struct mstimeval and msGettimeofday()
to the real things: struct timeval and gettimeofday() respectively.

Hopefully my changes didn't break the Windows build again.
Note: See TracTickets for help on using tickets.