Re: PR_Poll() and non-blocking sockets?
"Wan-Teh Chang" <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.nspr |
|---|---|
| Message-ID | <[email protected]> |
On Tue, Jul 29, 2008 at 5:17 PM, Matt Lawson <[email protected]> wrote: > Hi, > > I am attempting to use PR_Poll() in a server application to poll a collection of non-blocking sockets (which have been accepted using PR_Accept()) The problem is, no matter what I do, the call to PR_Poll() always returns immediately indicating the socket is readable. > > Is this the normal behavior? Will PR_Poll() never pause for any length of time with non-blocking sockets? I don't want to be hogging CPU at 100% if it's not necessary. > > I have searched for solutions online. I have already been through the exercise of calling PR_GetConnectStatus() and PR_Poll() with write|exception to ensure that the socket gets fully established (and in fact this was part of the problem) > > So now I have an incoming PR_Accept()ed socket, which PR_GetConnectStatus() says is good, and I PR_Poll() it (with PR_POLL_READ) and it always returns true. > > This is all from the server's point of view. All sockets including the bind/listen sockets are non-blocking. PR_Poll works with non-blocking sockets. In fact, PR_Poll is intended to be used with non-blocking sockets. PR_Poll blocks until the events you're interested in have occurred. The fact that the socket is in non-blocking mode affects PR_Recv, PR_Send, etc., but doesn't affect PR_Poll. PR_GetConnectStatus() should only be used with a non-blocking socket on which a connect has just completed. So you should not call PR_GetConnectStatus() on an incoming PR_Accept()ed socket. Other than that, your description seems correct. I'll need to look at your code snippets to see what's wrong. Wan-Teh