Samuel, (forwarded to the mailing list also)
Basically, as I understand the problem, is that lisp LISTEN does not notify end of file/connection and characters avaiable in the same manner READ-CHAR-NO-HANG (and the character stream system) does. LISTEN returns false on char not available and end-of-file. READ-CHAR-NO-HANG (as well as READLINE) uses conditions. So, my question is, is there any different way (using usockets) of identifying when a non-char connection is closed? Thanks! ---------- Forwarded message ---------- From: Roger Sen Montero <roger....@gmail.com> Date: Thu, Mar 21, 2013 at 8:07 PM Subject: Re: Detecting whether the other end has closed my socket stream To: Samuel Edwin Ward <sew...@cytochro.me> Samuel, I have identified the issue to a call to a listen when waiting to read the socket so I can multiplex multiple socket reading. http://paste.lisp.org/display/136157 With the current code COLLECT-INPUT (listen stream) is not raising the end of file condition. (defun collect-input (socket buffer &optional (end-char 13)) (loop :with stream = (usocket:socket-stream socket) :with byte :while (listen stream) :doing (setf byte (read-byte stream)) (when (= byte end-char) (return t)) (vector-push-extend byte buffer))) Taking out the listen and changing it to :while t raises the condition correctly when the connection is closed from client side, but then I'm unable to multiplex. On Thu, Mar 21, 2013 at 1:00 AM, Roger Sen Montero <roger....@gmail.com>wrote: > Samuel, > > Let me create a simple test case from the current code and I'll post it > here. > > > El miércoles, 13 de marzo de 2013, Samuel Edwin Ward escribió: > > Hi Roger/all, >> >> I wasn't able to reproduce this with my setup; I seem to get the end of >> file condition either way. >> >> I'm using usocket 0.6.0.1 on sbcl 1.0.54.0-185b926 on Mac OS 10.7.5. >> >> Can you provide your versions and/or a runnable test case? >> >> On Mar 13, 2013, at 12:24, Roger Sen Montero <roger....@gmail.com> wrote: >> >> Hi all!! >> >> The FAQ states: >> >> Reading from a stream which has been closed at the remote end signals an >> END-OF-FILE condition, meaning that reading from the stream and detecting >> that condition is the way to do it. >> >> But when a create a server with: >> >> :element-type 'character >> >> I'm able to get an "Unexpected end of file" condition on the server side >> when the client disconnect. >> >> Unfortunately, when I create the server with: >> >> :element-type 'unsigned-byte >> >> I do not get the condition, so I'm unable to detect when a client has >> disconnected. >> >> Also, is there any plan to support utf8 streams directly without >> creating unsigned-byte sockets and converting from/to string to >> string-utf-8-bytes? >> >> >> thanks! >> -- >> Roger Sen Montero >> roger....@gmail.com >> >> _______________________________________________ >> usocket-devel mailing list >> usocket-devel@common-lisp.net >> http://lists.common-lisp.net/cgi-bin/mailman/listinfo/usocket-devel >> >> > > -- > Roger Sen Montero > roger....@gmail.com > -- Roger Sen Montero roger....@gmail.com -- Roger Sen Montero roger....@gmail.com
_______________________________________________ usocket-devel mailing list usocket-devel@common-lisp.net http://lists.common-lisp.net/cgi-bin/mailman/listinfo/usocket-devel