<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div></div><div><br></div><br><div><div>ÔÚ 2011-5-1£¬11:44£¬ Elliott Slaughter Ð´µÀ£º</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><div>I have another minimal testcase. It actually doesn't exhibit a freeze like I see in my application, but it's definitely not working, so I think it's worth looking at.</div><div><br></div><div>The code:</div>
<div><br></div><div><div>(defun receive-each (connections)</div><div>  (let ((ready (usocket:wait-for-input connections :timeout 0 :ready-only t)))</div><div>    (loop for connection in ready</div><div>       collect (read-line (usocket:socket-stream connection)))))</div>
<div><br></div><div>(defun receive-all (connections)</div><div>  (loop for messages = (receive-each connections)</div><div>     then (receive-each connections)</div><div>     while messages append messages))</div><div><br>
</div><div>(defun send (connection message)</div><div>  (format (usocket:socket-stream connection) "~a~%" message)</div><div>  (force-output (usocket:socket-stream connection)))</div><div><br></div><div>(defun server ()</div>
<div>  (let* ((listen (usocket:socket-listen usocket:*wildcard-host* 12345))</div><div>         (connection (usocket:socket-accept listen)))</div><div>    (loop for messages = (receive-all connection) then (receive-all connection)</div>
<div>       do (format t "Got messages:~%~s~%" messages)</div><div>       do (sleep 1/50))))</div><div><br></div><div>(defun client ()</div><div>  (let ((connection (usocket:socket-connect "localhost" 12345)))</div>
<div>    (loop for i from 0</div><div>       do (send connection (format nil "This is message ~a." i))</div><div>       do (sleep 1/100))))</div></div><div><br></div><div>Here is what the output looks like on everything I've tested except SBCL on Windows. (Tested on SBCL on Mac, and Clozure CL on Windows.)</div>
<div><br></div><div>* (server)</div><div>Got messages:</div><div>("This is message 0." "This is message 1." "This is message 2.")</div><div>Got messages:</div><div>("This is message 3." "This is message 4.")</div>
</div><div>...</div><div><br></div><div>Here is the output on SBCL on Windows.</div><div><br></div><div><div>* (server)</div><div>Got messages:</div><div>NIL</div><div>Got messages:</div><div>NIL</div></div><div>...</div>
<div><br></div><div>I think in this case wait-for-input never returns anything as ready so I never read from the socket.</div><br><div class="gmail_quote">On Sat, Apr 30, 2011 at 1:13 AM, Elliott Slaughter <span dir="ltr"><<a href="mailto:elliottslaughter@gmail.com" target="_blank">elliottslaughter@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<div><br></div><div>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</div>


<div><br></div><div><div>(iter (for ready next (wait-for-input socket :timeout 0))</div><div>      (while (read-message socket)))</div></div><div><br></div><div>I'm avoiding multithreading to preserve compatibility with Lisps that don't support (or have unstable support for) threads.</div>


<div><br></div><div>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.</div><div><br></div><div>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)?</div>


<div><br></div><div>Thanks.</div><div><br>-- <br>Elliott Slaughter<br><br>"Don't worry about what anybody else is going to do. The best way to predict the future is to invent it." - Alan Kay<br>
</div>
</blockquote></div><br><br clear="all"><br>-- <br>Elliott Slaughter<br><br>"Don't worry about what anybody else is going to do. The best way to predict the future is to invent it." - Alan Kay<br>
_______________________________________________<br>usocket-devel mailing list<br><a href="mailto:usocket-devel@common-lisp.net">usocket-devel@common-lisp.net</a><br>http://common-lisp.net/cgi-bin/mailman/listinfo/usocket-devel<br></blockquote></div><br></body></html>