2011/5/10 Chun Tian (binghe) <span dir="ltr"><<a href="mailto:binghe.lisp@gmail.com">binghe.lisp@gmail.com</a>></span><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div style="word-wrap:break-word"><div>Hi, Elliott</div><div><br></div><div>Sorry again for late response, but I think I've found the reason about this issue: WAIT-FOR-INPUT correctly detected that there're inputs on the server side socket, but due to a subtle bug when updating the STATE slot of the socket object, the socket wasn't marked as READY, so when W-F-I was called by (READY-ONLY T), a empty list returned (and your code have no chance to get touch with the stream behind the socket, and nothing could be output ...)</div>
<div><br></div><div>Due to some problems on USOCKET SVN, I cannot commit my work right now, but I have a patch as .diff file in attach, which could solve all your needs.  I hope you can take a little download it and apply to your local USOCKET directory and see if your application work well this time.</div>
<div><br></div><div>The bug you reported also affect ECL on Windows, but I don't sync my patch to ECL until I get your positive confirmation.</div></div></blockquote><div><br>Yes, it works! Thanks!<br><br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div style="word-wrap: break-word;"><div></div><div>Regards,</div><div><br></div><font color="#888888"><div>Chun Tian (binghe)</div><div><br></div><div></div></font></div><br><div style="word-wrap:break-word"><div></div><div>
<br></div><br><div><div>ÔÚ 2011-5-1£¬11:44£¬ Elliott Slaughter Ð´µÀ£º</div><br><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" target="_blank">usocket-devel@common-lisp.net</a><br><a href="http://common-lisp.net/cgi-bin/mailman/listinfo/usocket-devel" target="_blank">http://common-lisp.net/cgi-bin/mailman/listinfo/usocket-devel</a><br>
</blockquote></div><br></div><br></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>