[ENet-discuss] Platforms other then Windows and *nix?

Patrick Klos pklos at lauferwind.com
Thu Aug 8 13:42:12 PDT 2013


On 8/8/2013 4:18 PM, Lee Salzman wrote:
> Not quite, enet_time_get() is for returning a running time counter, 
> and is not really intended for providing a time-differentiated random 
> seed. If you start up enet in quick succession making connections, 
> then the random seeds can more easily accidentally overlap. The idea 
> here is to get actual time in seconds so that on successive startups 
> of enet the chance of collisions is much smaller. And it's intended 
> that time() is pretty standard, and originally that's all that was 
> used... Except that Win32 in its usual rebelliousness, doesn't quite 
> like this without linking against more extra libraries, so I opted for 
> timeGetTime() there. Chill out. It's not the end of the world.

That doesn't make sense.

First, let's look at the Windows version:  in both host.c and the 
enet_time_get() function in win32.c, you use timeGetTime(), so your 
results will be identical.  Of course, you do have the "timeBase" 
variable to offset your times from enet_time_get(), but how many people 
really use that?  For all practical purposes, Windows is going to have 
the same behavior either way.

OK, so now let's look at the Unix version:  in host.c, you use the 
standard Unix time() function, which returns the number of seconds since 
Jan 1, 1970.  In unix.c, the enet_time_get() function uses 
gettimeofday(), and then builds a value which is essentially the number 
of milliseconds since midnight Jan 1, 1970.  So you're using whole 
seconds for the random seed, and milliseconds for the time counter.  I'm 
sure the chance of collisions is much greater (especially when you start 
up enet in quick succession) when you're using seconds for the random 
seed instead of milliseconds!?!  Please correct me if I'm wrong?

Patrick



More information about the ENet-discuss mailing list