Nmap Development mailing list archives

Re: [NSE] Yielding to other threads?


From: "Patrick Donnelly" <batrick.donnelly () gmail com>
Date: Mon, 29 Dec 2008 20:37:50 -0700

On Mon, Dec 29, 2008 at 3:02 PM, Ron <ron () skullsecurity net> wrote:
Hi all,

In a NSE script, is it possible to yield to another thread if I'm doing
something that I know will take awhile?

I'd like to do something that I know will take at least 5 seconds to
respond. But instead of waiting on a socket that I know is going to time
out, is there some way I can sleep for 5 seconds then come back?

Is any of that possible/simple?

You can't make a thread sleep in the standard sense of having a
process sleep. The only thing a thread may do is yield and wait for
some mechanism to cause the thread to be put back into the running
queue (to be resumed by NSE). Right now the only mechanisms for that
are mutexes and the blocking socket operations.

I'm working on adding the option to dispatch a new NSE level thread, a
coroutine that NSE manages for you. With this you can have multiple
threads operate on behalf of one script thread. This will be useful
for many reasons, but to name two: (1) a network connection likely to
error (timeout) can be safely run without ending the parent thread,
(2) multiple connections can be made and managed by the parent script
thread.

Cheers,

-- 
-Patrick Donnelly

"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."

-Will Durant

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


Current thread: