Page 1 of 1

Value of timeout.tv_usec off by a factor of 1000

Posted: Tue May 06, 2008 6:12 am
by chrisj
In zm_remote_camera.cpp, a timeval struct is initialized as follows:

Code: Select all

                timeout.tv_sec = config.http_timeout/1000;
                timeout.tv_usec = config.http_timeout%1000;
Since the tv_usec field is supposed to be the number of microseconds, it should actually be initialized as:

Code: Select all

               timeout.tv_sec = config.http_timeout/1000;
               timeout.tv_usec = (config.http_timeout%1000) * 1000;
Since the value of config.http_timeout%1000 gives the remaining number of milliseconds not covered by the tv_sec field.

Not a big deal, really, but if you set the timeout to less than 1000ms, then you may notice the difference.

Posted: Mon Jun 29, 2009 1:44 am
by Normando
I have knoledge with C++ but it is a simple mathematics.

1 sec = 1000000 usec

So:

Code: Select all

                timeout.tv_sec = config.http_timeout/1000;
                timeout.tv_usec = config.http_timeout%1000; 
should be:

Code: Select all

                timeout.tv_sec = config.http_timeout/1000;
                timeout.tv_usec = config.http_timeout*1000; 
Phil, can you confirm this?

Thanks

Posted: Mon Jun 29, 2009 10:59 am
by zoneminder
The correct way is

Code: Select all

timeout.tv_usec = (config.http_timeout%1000) * 1000; 
however this is how it is currently implemented anyway.

You need to do the %1000 to get the milliseconds and then multiply by 1000 to get microseconds. Just multiplying by 1000 will include the seconds in the calculation and so will be too large.

Posted: Mon Jun 29, 2009 1:45 pm
by Normando
Ohh, yes, I now I understand the concept.

Thanks for the clarification Phil

Regards