Nmap Development mailing list archives

Re: A sleep function for NSE


From: David Fifield <david () bamsoftware com>
Date: Fri, 20 Feb 2009 14:40:09 -0700

On Fri, Feb 20, 2009 at 09:26:07PM +0000, jah wrote:
On 20/02/2009 18:55, David Fifield wrote:
A function called "sleep" normally takes an argument in seconds, even if
it only provides integer precision. So if the function changes to take
milliseconds its name has to change too. In the name of consistency, I
think there are only two choices: sleep taking a floating-point number
of seconds, or sleep_ms taking an integer number of milliseconds.

My preference would be to have sleep take floating-point seconds, and to
change nmap.clock_ms and nmap.set_timeout to deal in seconds also. The
settimeout in Python does it in seconds:

http://docs.python.org/library/socket.html#socket.socket.settimeout

Furthermore, clock_ms should be renamed "time" because it is more like
the time function in C or os.time in Lua (seconds since 1970) than it is
the C clock function (time since some arbitrary point in arbitrary
units). clock_ms is doubly frustrating because it uses gettimeofday,
which provides microsecond precision, then purposely degrades the result
to return milliseconds.

It may be too late for nmap.set_timeout because that would be an
incompatible change. nmap.clock_ms is easier because it is currently
hardly used and its name should change anyway. Any thoughts?

Yeah, tricky.  As you (and Arturo) point out, sleep() normally takes
seconds and it would be daft to stray from the norm without compelling
reasons to do so.  If it's a lot of work to change set_timeout to
seconds then we probably shouldn't - it's only a small detail after all
and the function is well documented and probably fixed in people's minds
by now.

I agree, set_timeout is just a detail.

I agree with the name change for clock_ms, but are you suggesting
changing it to accept seconds or to return microseconds?   It might be
useful to have a fine-grained measurement of time - Doug's Qscan
implemented as a script springs to mind.

Return seconds, as a floating-point number. Again I'm thinking of how it
works in Python:

$ python -c "import time; print '%.6f' % time.time()"
1235165681.158787

Maybe I didn't make it clear, but stdnse.sleep takes fractional seconds
too: stdnse.sleep(0.005) sleeps for 5 ms. Implementing a millisecond
sleep function over it is trivial: function(ms) stdnse.sleep(ms / 1000) end.

David

_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://SecLists.Org


Current thread: