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

Chun Tian (binghe) binghe.lisp at gmail.com
Tue May 10 16:15:00 UTC 2011


Hi again, Elliott

To find "how much (bytes) data is available on a socket", you can use a internal function called USOCKET::BYTES-AVAILABLE-FOR-READ, the only argument is the STREAM-SOCKET object, and it returns the number of bytes.

But if you want to know how many "messages" is available, I'm afraid that unless you know exactly the length of your messages, above function still cannot let you cut down the number of calls to WAIT-FOR-INPUT.

And this function is currently only available on Windows for LispWorks, SBCL and ECL.

Hope this helps.

Regards,

Chun Tian (binghe)

在 2011-4-30,16:13, Elliott Slaughter 写道:

> 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
> _______________________________________________
> usocket-devel mailing list
> usocket-devel at common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/usocket-devel





More information about the usocket-devel mailing list