#232 socket:socket-status modifies stream

lisp error
closed-fixed
clisp (525)
5
2004-10-30
2004-10-29
Jonas
No

[1]> (setf socket (socket:socket-connect 6667
"localhost"))
#<IO UNBUFFERED SOCKET-STREAM CHARACTER localhost:6667>
[2]> (read-line socket)
"NOTICE AUTH :*** Looking up your hostname..." ;
NIL

I connect and read the first line, and it works as it
should.

[3]> (socket:socket-status socket)
:IO ;
1
[4]> (read-char socket)
#\Newline

A newline character is to be found in the beginning.

[5]> (read-line socket)
"NOTICE AUTH :*** Found your hostname, welcome back" ;
NIL
[6]> (read-char socket)
#\N
[7]> (read-line socket)
"OTICE AUTH :*** Checking ident" ;
NIL
[8]> (socket:socket-status socket)
:IO ;
1
[9]> (peek-char t socket)
#\N
[10]> (read-char socket)
#\N

Here no newline character is found, and this is how it
should been in command [4].

[11]> (read-line socket)
"OTICE AUTH :*** Got ident response" ;
NIL
[12]> (read-char socket)
#\P

If I don't run (socket:socket-status socket) before
reading from the stream there is no #\Newline character
in the beginning.

[13]> (read-line socket)
"ING :localhost." ;
NIL
[14]>

It seems like (socket:status socket) modifies the
stream in some way, but not when running (peek-char t
socket). Another strange behavior I discoverd was when
calling:
(socket:socket-status socket)
(read-line socket)
the read-line function returns "" NIL half of the
times, but when calling:
(read-line socket)
it returns the supposed line.

I've tried clisp-2.33, clisp-2.33.2 and the
sourceforge-cvs co:ed 29 Oct 2004 and it's the same
with all versions.

Discussion

  • Sam Steingold

    Sam Steingold - 2004-10-29

    Logged In: YES
    user_id=5735

    thanks for your bug report.
    unfortunately, it is not quite clear to me how to reproduce
    the bug.
    could you please present 2 lisp functions
    (each to be called in a separate CLISP process
    which will talk to each other over a socket)
    together with the actual and expect output from each.
    your help is appreciated.

     
  • Sam Steingold

    Sam Steingold - 2004-10-29

    Logged In: YES
    user_id=5735

    E.g., in 1s CLISP:
    (let* ((server (print (socket-server 4325)))
    (s (print (socket-accept server :element-type
    'character))))
    (print (socket-status (cons s :input)))
    (print (socket-status s))
    (print (read-line s))
    (close s) (socket:socket-server-close server))
    prints
    #<SOCKET-SERVER 0.0.0.0:4325>
    #<IO UNBUFFERED SOCKET-STREAM CHARACTER 0.0.0.0:4325>
    :INPUT
    :IO
    "foo"
    NIL
    while in 2nd CLISP
    (let ((s (socket-connect 4325))) (format s "foo~%") (close s))
    pints
    T
    (as expected)

     
  • Jonas

    Jonas - 2004-10-30

    Logged In: YES
    user_id=162311

    Here are some example functions in two files.

    I get these results:
    [1]> (load "cl.lisp")
    [2]> (read-a-couple-of-lines)
    received:Test line1
    received:Test line2
    NIL
    [3]> (read-a-couple-of-lines-but-check-first)
    received:Test line1
    received:
    NIL
    [4]> (read-a-couple-of-lines-but-check-first-and-then-peek)
    received:Test line1
    received:Test line2
    NIL

    sv.lisp:
    ; lisp stream server
    (defun run-server ()
    (let ((socket (socket:socket-server 44775)))
    (dotimes (* 3)
    (let ((cl-socket (socket:socket-accept socket)))
    ; i use 13,10 as newline instead of 10.
    (write-sequence (format nil "Test line1~a~a"
    (code-char 13) (code-char 1
    0)) cl-socket)
    (write-sequence (format nil "Test line2~a~a"
    (code-char 13) (code-char 1
    0)) cl-socket)
    (close cl-socket)))
    (socket:socket-server-close socket)))

    cl.lisp:
    ; lisp stream client
    (defun read-a-couple-of-lines ()
    (let ((socket (socket:socket-connect 44775 "localhost")))
    (dotimes (* 2)
    (format t "received:~a~%" (read-line socket)))))

    (defun read-a-couple-of-lines-but-check-first ()
    (let ((socket (socket:socket-connect 44775 "localhost")))
    (dotimes (* 2)
    (socket:socket-status socket)
    (format t "received:~a~%" (read-line socket)))))

    (defun read-a-couple-of-lines-but-check-first-and-then-peek ()
    (let ((socket (socket:socket-connect 44775 "localhost")))
    (dotimes (* 2)
    (socket:socket-status socket)
    (peek-char t socket)
    (format t "received:~a~%" (read-line socket)))))

     
  • Sam Steingold

    Sam Steingold - 2004-10-30

    Logged In: YES
    user_id=5735

    Thanks for the code.
    instead of the CR-LF trick, you should use
    :external-format :dos
    see <http://clisp.cons.org/impnotes/stream-dict.html#extfmt>
    <http://clisp.cons.org/impnotes/encoding.html#newline>
    <http://clisp.cons.org/impnotes/clhs-newline.html>

     
  • Sam Steingold

    Sam Steingold - 2004-10-30
    • status: open --> closed-fixed
     
  • Sam Steingold

    Sam Steingold - 2004-10-30

    Logged In: YES
    user_id=5735

    thank you for your bug report.
    the bug has been fixed in the CVS tree.
    you can either wait for the next release (recommended)
    or check out the current CVS tree (see http://clisp.cons.org\)
    and build CLISP from the sources (be advised that between
    releases the CVS tree is very unstable and may not even build
    on your platform).

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks