Hello.
I am using usocket 0.5.0 and it has a bug for CLISP.
In the function wait-for-input-internal there is a do* cycle which analyzes the result of the CLISP function socket-status (its docs are here: http://www.clisp.org/impnotes/socket.html#so-status)
Here is how the cycle is written now:
(do* ((x (pop sockets) (pop sockets)) (y (pop status-list) (pop status-list))) ((null x)) (when (eq y :INPUT) (setf (state x) :READ)))
This cycle never recognizes that a server socket is ready to accept a connection.
The fixed cycle
(do* ((x (pop sockets) (pop sockets)) (y (cdr (pop status-list)) (cdr (pop status-list)))) ; <- fixed here ((null x)) (when (member y '(T :INPUT)) ; <- and here (setf (state x) :READ)))
The first mistake was that the code expects socket-status to return a list of statuses, but it actually returns a list of cons cells, according to the doc:
If you want to avoid consing[3] up a fresh list, you can make the elements of socket-stream-or-list to be (socket-stream direction . x) or (socket-server . x). Then SOCKET:SOCKET-STATUS will destructively modify its argument and replace x or NIL with the status and return the modified list.
The second mistake is that socket-status specifies ready SOCKET-SERVER as T (and :INPUTS is for SOCKET-STREAM). As far as I understood usocket intention for the wait-for-input-internal function, we should check both.
With these changes, I have hunchentoot 1.1.1 working with clisp 2.49.
Best regards, - Anton
Hi, Anton
Thank you very much for looking into this issue and finally fixed it! I believe this also closed another open issue reported by other users on Hunchentoot mailing list, in which they have to disable the use of READY-ONLY argument when calling WAIT-FOR-INPUT.
Any way, I've merged your patch (r640 on usocket 0.5.x branch [1]), and hope we can make another quick release (0.5.2) in next week, with at least one more planned new feature.
Best Regards,
Chun Tian (binghe)
[1] svn://common-lisp.net/project/usocket/svn/usocket/branches/0.5.x
在 2011-4-10,13:02, Anton Vodonosov 写道:
Hello.
I am using usocket 0.5.0 and it has a bug for CLISP.
In the function wait-for-input-internal there is a do* cycle which analyzes the result of the CLISP function socket-status (its docs are here: http://www.clisp.org/impnotes/socket.html#so-status)
Here is how the cycle is written now:
(do* ((x (pop sockets) (pop sockets)) (y (pop status-list) (pop status-list))) ((null x)) (when (eq y :INPUT) (setf (state x) :READ)))
This cycle never recognizes that a server socket is ready to accept a connection.
The fixed cycle
(do* ((x (pop sockets) (pop sockets)) (y (cdr (pop status-list)) (cdr (pop status-list)))) ; <- fixed here ((null x)) (when (member y '(T :INPUT)) ; <- and here (setf (state x) :READ)))
The first mistake was that the code expects socket-status to return a list of statuses, but it actually returns a list of cons cells, according to the doc:
If you want to avoid consing[3] up a fresh list, you can make the elements of socket-stream-or-list to be (socket-stream direction . x) or (socket-server . x). Then SOCKET:SOCKET-STATUS will destructively modify its argument and replace x or NIL with the status and return the modified list.
The second mistake is that socket-status specifies ready SOCKET-SERVER as T (and :INPUTS is for SOCKET-STREAM). As far as I understood usocket intention for the wait-for-input-internal function, we should check both.
With these changes, I have hunchentoot 1.1.1 working with clisp 2.49.
Best regards,
- Anton
usocket-devel mailing list usocket-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/usocket-devel
10.04.2011, 18:39, "Chun Tian (binghe)" binghe.lisp@gmail.com:
believe this also closed another open issue reported by other users on Hunchentoot mailing list, in which they have to disable the use of READY-ONLY argument when calling WAIT-FOR-INPUT.
Dos the form of the argument passed to the CLISP function socket:socket-status depend on the usocket parameter READ-ONLY? (the variable REQUEST-LIST in the WAIT-FOR-INPUT-INTERNAL
(do* ((x (pop sockets) (pop sockets)) (y (cdr (pop status-list)) (cdr (pop status-list)))) ; <- fixed here ((null x)) (when (member y '(T :INPUT)) ; <- and here (setf (state x) :READ)))
10.04.2011, 18:39, "Chun Tian (binghe)" binghe.lisp@gmail.com:
Hi, Anton
Thank you very much for looking into this issue and finally fixed it! I believe this also closed another open issue reported by other users on Hunchentoot mailing list, in which they have to disable the use of READY-ONLY argument when calling WAIT-FOR-INPUT.
Dos the form of the argument passed to the CLISP function socket:socket-status depend on the usocket parameter READ-ONLY? (the variable REQUEST-LIST in the WAIT-FOR-INPUT-INTERNAL code)
I mean, if changing the READ-ONLY argument made the old code working, i.e. (pop status-list) was sufficient, then the new code should take this into account.
What is the value of the REQUEST-LIST variable?
Best regards, - Anton
Hi, Anton
No, the form passed to SOCKET-STATUS *DO NOT* depend on READY-ONLY (note: it's READY-ONLY, not READ-ONLY).
Actually, all your patch does was the status updating "after" CLISP's SOCKET-STATUS returned. This means, if a socket do have some inputs are waiting for read, CLISP's SOCKET-STATUS can definitely normally return, even without your patch.
As far as I know, many USOCKET users (or packages) were using WAIT-FOR-INPUT in a trivial way (including me): they send something to one socket, and call WAIT-FOR-INPUT on it (without READY-ONLY), never care the return value or the STATE slot of usocket object, and the buggy W-F-I just works for many years ... until Hunchentoot users start to run it on CLISP ...
On the other hand, what you patched is more valuable when (:READY-ONLY T) was added when calling W-F-I. Your patch caused the STATE slot from multiple usocket objects were updated correctly, and W-F-I will just return those sockets who can be read (this logic appears in the implementation of W-F-I itself in usocket.lisp, code shared by all backends).
So, I think your patch is just enough. Thanks again!
--binghe
在 2011-4-10,23:16, Anton Vodonosov 写道:
10.04.2011, 18:39, "Chun Tian (binghe)" binghe.lisp@gmail.com:
Hi, Anton
Thank you very much for looking into this issue and finally fixed it! I believe this also closed another open issue reported by other users on Hunchentoot mailing list, in which they have to disable the use of READY-ONLY argument when calling WAIT-FOR-INPUT.
Dos the form of the argument passed to the CLISP function socket:socket-status depend on the usocket parameter READ-ONLY? (the variable REQUEST-LIST in the WAIT-FOR-INPUT-INTERNAL code)
I mean, if changing the READ-ONLY argument made the old code working, i.e. (pop status-list) was sufficient, then the new code should take this into account.
What is the value of the REQUEST-LIST variable?
Best regards,
- Anton