[Jslib] Non-blocking sockets?
stknight at ultralifebatteries.com
Tue Dec 2 09:24:59 EST 2003
Rick Morris wrote:
> Pete (and all),
> Is there currently any way to get non-blocking sockets in Jslib?
> Anything planned?
The default in Socket (network/socket.js) is to be non-blocking (as far as I can tell). However,
the underlying implementation will perform a throw if an attempt is made to read more bytes than
currently "available" on the socket. This is why Socket.read is so clunky in its attempts to avoid
triggering that throw on the read. As for write, well...I've never had a problem with it (YMMV).
Unfortunately, there doesn't seem to be any explicitly defined mechanism for specifying non-blocking
sockets (see http://www.xulplanet.com/references/xpcomref/ifaces/nsITransport.html). This tends to
make me suspicious.
When I implemented the current Socket, I attempted to make sure that it was possible to set the
various flags when creating the streams (openInputStream/openOutputStream) without going thru too
var newSocket = new Socket;
newSocket.openInputFlags = ....
newSocket.openOutputFlags = ....
newSocket.open( host, port );
I expect more of a problem when somebody wants to do a blocking read/write.
hope this helps.
Ultralife Batteries, Inc.
More information about the Jslib