From: Daniel Barlow <dan@telent.net>
On a buffered socket stream, READ-LINE seems not to
ever return
To replicate:
(let* ((server (socket:socket-server 4322))
(s (socket:socket-accept server :element-type
'character :buffered t)))
(prog1
(read-line s)
(close s) (socket:socket-server-close server)))
:; telnet localhost 4322
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
hello
hello?
... continue typing at random to no immediate effect ...
Possibly relevant version numbers, configuration details:
:; uname -a
Linux no-rom-basic 2.6.6-2-686 #1 Wed Jun 16 01:25:38
PDT 2004 i686 GNU/Linux
:; ldd `type -p clisp`
libc.so.6 => /lib/tls/libc.so.6
(0x40026000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2
(0x40000000)
:; ls -l /lib/tls/libc.so.6
lrwxrwxrwx 1 root root 13 2004-10-26 11:39
/lib/tls/libc.so.6 -> libc-2.3.2.so
:; dpkg -s clisp | grep Version
Version: 1:2.33.2-7
:; clisp --version
WARNING: *FOREIGN-ENCODING*: reset to ASCII
GNU CLISP 2.33.2 (2004-06-02) (built 3304881526)
(memory 3308043966)
Software: GNU C 3.3.4 (Debian 1:3.3.4-12) ANSI C program
Features:
(ASDF SYSCALLS CLX-ANSI-COMMON-LISP CLX REGEXP CLOS
LOOP COMPILER CLISP ANSI-CL
COMMON-LISP LISP=CL INTERPRETER SOCKETS
GENERIC-STREAMS LOGICAL-PATHNAMES
SCREEN FFI GETTEXT UNICODE BASE-CHAR=CHARACTER PC386 UNIX)
Installation directory: /usr/lib/clisp/
User language: ENGLISH
Machine: I686 (I686) no-rom-basic [192.168.71.53]
[17]> (lisp-implementation-version)
"2.33.2 (2004-06-02) (built 3304881526) (memory
3308043966)"
:; gcc -v
Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.5/specs
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f77,pascal,objc,ada,treelang
--prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info
--with-gxx-include-dir=/usr/include/c++/3.3
--enable-shared --with-system-zlib --enable-nls
--without-included-gettext --enable-__cxa_atexit
--enable-clocale=gnu --enable-debug
--enable-java-gc=boehm --enable-java-awt=xlib
--enable-objc-gc i486-linux
Thread model: posix
gcc version 3.3.5 (Debian 1:3.3.5-2)
:; set | grep '^L'
LANG=en_GB.UTF-8
LESSOPEN='|gzip -cdf --stdout %s'
LINES=24
LOGNAME=dan
LS_COLOURS=':ex=1;34:*README=30;46:*.o=33:*.gz=31:*.zip=31'
stracing clisp while this is happening, I get
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 4
setsockopt(4, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(4, {sa_family=AF_INET, sin_port=htons(4322),
sin_addr=inet_addr("0.0.0.0")}, 16) = 0
listen(4, 1) = 0
getsockname(4, {sa_family=AF_INET,
sin_port=htons(4322), sin_addr=inet_addr("0.0.0.0")},
[16]) = 0
accept(4, {sa_family=AF_INET, sin_port=htons(35570),
sin_addr=inet_addr("127.0.0.1")}, [16]) = 5
mmap2(0x203d2000, 4096, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x203d2000
mmap2(0x203d3000, 4096, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x203d3000
fcntl64(5, F_GETFL) = 0x2 (flags
O_RDWR)
read(5, "hello\r\n", 4096) = 7
read(5, "hello?\r\n", 4089) = 8
read(5, <unfinished ...>
Process 15826 detached
Logged In: YES
user_id=5735
WFM on windows.
confirmed on amd64.
Logged In: YES
user_id=5923
This is the expected behaviour on buffered socket stream.
If you want the data to be returned immediately, use an unbuffered socket.
Logged In: YES
user_id=5923
This can be reformulated as a wish: the implementation of :BUFFERED
:INTERACTIVE.
Logged In: YES
user_id=5735
note that CMUCL offers 3 levels of buffering:
full, line and none.
I think what you call :INTERACTIVE
is (similar to) what CMUCL calls :LINE buffering.
I think it offers a good trade off between performance
and responsiveness and should be the default on all streams
(especially since it should be identical to :FULL buffering
on file streams)
Logged In: YES
user_id=5923
After all, the proposed :BUFFERED :INTERACTIVE buffering
scheme makes more sense on all kinds of streams than the
current :BUFFERED T scheme. It will replace the existing
:BUFFERED T mechanism.
WIll be committed in CVS in ca. 1 week.