[usocket-devel] How to tell size of data waiting in a TCP socket?

Elliott Slaughter elliottslaughter at gmail.com
Sat Apr 30 08:13:23 UTC 2011


Hi,

I'm wondering if there is a good way to figure out how much data is
available on a socket. Right now I have a situation where my program accepts
messages over a TCP socket. To check to see if a single message is
available, I can just call wait-for-input with :timeout 0. But in order to
check for multiple messages on a single socket, I need multiple calls to
wait-for-input. So something like

(iter (for ready next (wait-for-input socket :timeout 0))
      (while (read-message socket)))

I'm avoiding multithreading to preserve compatibility with Lisps that don't
support (or have unstable support for) threads.

The above works on most implementations, but breaks on SBCL/Windows, where
subsequent calls to wait-for-input appear to block, despite the :timeout 0
parameter.

There may very well be a bug in the SBCL/Windows implementation in usocket
to chase down here. Alternatively, is there a better way to do the above
(assuming that multithread is unavailable in the implementation I want to
run this on)?

Thanks.

-- 
Elliott Slaughter

"Don't worry about what anybody else is going to do. The best way to predict
the future is to invent it." - Alan Kay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/usocket-devel/attachments/20110430/b3b79ac1/attachment.html>


More information about the usocket-devel mailing list