Problems reading from socket
I'm not sure if this is a bug in SBCL, or in CLISP, or neither, but I'm hoping someone here can shed light on the matter. (I'm using SBCL 1.0.29.11.debian 64bit but I have the same problem with 1.0.43 64bit.)
I'm reading a series of lists from a socket served by a C# process outside of my control. The lists are not terminated with a newline. CLISP reads all the lists just fine; SBCL hangs on the last one; but despite any buffering issues in my sample server/client below, I believe that is not the issue here.
Here are some snippets to get us in the ball-park of what I'm encountering:
=======
;; make server socket
(setf myss
(let ((sock (make-instance 'sb-bsd-
:type :stream
:protocol :tcp)))
(setf (sb-bsd-
(sb-bsd-
(sb-bsd-
sock))
;; accept-connection from client
(setf myserv
(progn
(setf (sb-bsd-
(let ((s (sb-bsd-
(if s
s :input t :output t
:buffering :line
)
(sleep nil)))))
=======
;; make simple socket to server
(setf myclient
(let ((socket (make-instance 'sb-bsd-
:type :stream :protocol :tcp)))
(sb-bsd-
(sb-
9876)
(sb-bsd-
socket :input t :output t :buffering :line
:element-type 'character)))
=======
Here is the difference between CLISP and SBCL (note, I'm consistently using SBCL for the server whether CLISP or SBCL for the client; this should be irrelevant since I just trying to model a C# server that I cannot change):
From the server, if I evaluate:
* (format myserv "(this)~%")
NIL
And then on the SBCL client evaluate:
* (read myclient)
(THIS)
* (listen myclient)
NIL
But with CLISP and a corresponding client, I get:
[9]> (read myclient)
(THIS)
[10]> (listen myclient)
T
[11]> (read-char myclient)
#\Newline
[12]> (listen myclient)
NIL
So CLISP reads the list up to the closing paren and leaves the newline in the stream, whereas SBCL consumes the newline.
By reading the C#-served stream char by char, I know there is no newline (or any other character) at the end of the list following the closing paren. Yet CLISP reads the list while SBCL hangs. If using my primitive server, I evaluate:
* (format myserv "(this)") ;; no newline
NIL
* (force-output myserv)
then both clients (SBCL and CLISP) report something ready to be read, but only CLISP will read the list with SBCL hanging.
So, is this a bug in SBCL? It seems clear that in general, the reader must NOT consume input following a closing paren. But in this case, I'm not sure it is technically wrong. Thanks for reading.
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- SBCL Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- Nikodemus Siivola
- Solved:
- Last query:
- Last reply: