Re: Interrupting a socket waiting on nlAcceptConnection() or nlRead()?


[ Follow Ups ] [ Post Followup ] [ Back To Message Board ]

Posted by David on February 08, 2006 at 17:48:36:

In Reply to: Re: Interrupting a socket waiting on nlAcceptConnection() or nlRead()? posted by Phil Frisbie, Jr. on February 08, 2006 at 15:20:23:

: OK, but let me explain WHY this is a VERY BAD idea.
:
: Internally, sockets are like file handles on most platforms, and are represented by an integer. When you forcibly shut down a socket on one thread while another thread is still listening, there is a possibility that the socket handle might be reused BEFORE the blocking socket call gets the 'invalid socket' error. When this occurs, that thread is now blocking on the WRONG socket!
:
: This REALLY does happen, and will cause you great grief. This is why you should ONLY forcibly shutdown a socket from another thread when you are shutting down the entire server.

But then what's the accepted way to interrupt a thread blocking on IO?

: : Also, nlThreadSleep() is listed internally- possibly make that public?
:
: You must be using an old version, because this is now exposed in the HawkThreads API.

I'm using the 1.6.8 version.

: : One last thing. I tried using nlEnable(NL_BLOCKING_IO) before making a connection, then nlDisable(NL_BLOCKING_IO) after connecting because it's handy to have it just block for connecting. The next time I use nlRead() however, it still blocks. Is this ... not a way I can use these features? [didn't check the error code on nlDisable() yet, but if/why would it fail?]
:
: nlEnable/Disable are global settings that effect the creation of new sockets. You must call nlSetSocketOpt() to directly change a socket's settings.
:
: Phil

Ah, I'll look at that, thanks.



Follow Ups:


Post a Followup

Name:
E-Mail:

Subject:

Comments:



[ Follow Ups ] [ Post Followup ] [ Back To Message Board ]