On Mon, Sep 8, 2008 at 5:44 PM, Kyle Hamilton <[EMAIL PROTECTED]> wrote:
>
> What is the semantic if someone opens the TCP socket in O_NONBLOCK in
> the first place?

The PRFileDesc* returned by PR_ImportTCPSocket is in blocking
mode.  If the caller intends to use the PRFileDesc* in non-blocking
mode, he needs to call PR_SetSocketOption to set the PRFileDesc*
in non-blocking mode.

The reason that NSPR puts the native file descriptor in non-blocking
mode for a PRFileDesc* in blocking mode is to implement the I/O
timeout and interrupt of PR_Recv and PR_Send.  PR_Recv blocks
in poll() instead of recv() because poll() takes a timeout parameter.

So, PR_ImportTCPSocket doesn't check if the native file
descriptor is already in non-blocking mode.  It always sets the
O_NONBLOCK flag on the native file descriptor, and the returned
PRFileDesc* starts in blocking mode.

> (Also, I found http://www.faqs.org/faqs/unix-faq/socket/ section 2.9.
> It doesn't exactly help all that much in explaining what goes on, but
> does PR_ImportTCPSocket's implementation (and thus the entirety of
> NSPR) add something to handle SIGIO?  Or is it more of a select() with
> a timeout of 0?)

NSPR doesn't use SIGIO.  NSPR uses poll() (equivalent to select())
because it has a timeout parameter as I explained above.

Note that the first paragraph of Section 2.9 of Unix-socket-faq
that you cited is misleading.  Non-blocking I/O is usually used
with select()/poll().  Non-blocking I/O doesn't mean you have to
poll the sockets individually.

Wan-Teh
_______________________________________________
dev-tech-crypto mailing list
dev-tech-crypto@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-tech-crypto

Reply via email to