Subject: [clisp-list] socket streams

From: Rafal Strzalinski <[email-masked]>
Date: 09 Jun 2000 10:30:15 +0200

I have a problem with stream sockets in CLISP. 
The following session shows the problem.

$ cat test.lsp
(setq s (socket-server 5555))
(setq x (socket-accept s))
(format x "Hello!~%")
(setq y (read-line x))
(format x "y = ~A~%" y)
(format x "BYE~%")
(force-output x)
(finish-output x)
;(sleep 1)
(close x)
(socket-server-close s)

$ clisp test.lsp &
[1] 13402
$ telnet nabla 5555
Trying 10.0.4.2...
Connected to nabla.ustronet.
Escape character is '^]'.
Hello!
hello
hello
[1]  + done       clisp test.lsp
Connection closed by foreign host.

Flushing output doesn't work correct. Where is "BYE".

-- 
Rafal Strzalinski
mailto:[email-masked]            
http://home.elka.pw.edu.pl/~rstrzali

---

From: [email-masked] (Don Cohen)
Date: Fri, 9 Jun 2000 09:33:35 -0700 (PDT)

Rafal Strzalinski

  $ cat test.lsp
  
  $ clisp test.lsp &
  [1] 13402
  $ telnet nabla 5555
  Trying 10.0.4.2...

I guess this depends on such things as the clisp version and the OS.
In clisp-2000-03-06 on linux I don't see this problem.  In fact, the
output appears without any force-output.

However, I see a related problem.  
If I close the shell window in which the telnet is done,
the lisp process does not see that the stream is closed.

In a clisp built from source about a week ago:
  [1]> (setq s (socket-server 5555)) 
  #<SOCKET-SERVER 24.130.53.144:5555>
  [2]>  (setq x (socket-accept s)) 

[now I telnet]

  #<UNBUFFERED SOCKET-STREAM CHARACTER 24.130.53.144:5555>

[now I close the telnet window]

  [3]> x
  #<UNBUFFERED SOCKET-STREAM CHARACTER 24.130.53.144:5555>
  [4]> (open-stream-p x)
  T
  [5]> (lisp:socket-status x)
  :OUTPUT
  [6]> (print 1 x)
  1

The next time I try to print to x I get
*** - UNIX error 32 (EPIPE): Broken pipe, child process terminated or
socket closed

Now the Really weird part - I run xemacs, start a shell 
from there, run clisp in that shell, do the first two
lines above (socket-server, socket-accept), and then
from another shell, telnet to the server and then close the 
shell window.  My xemacs process disappears !  
This is reproducible.  Multiple machines.  
Any ideas?

---

From: [email-masked] (Don Cohen)
Date: Fri, 9 Jun 2000 10:11:09 -0700 (PDT)

One problem solved - exiting xemacs is only in the case where I close
the window from which I started xemacs.  I started it with &.
Weird.  If I exit from that shell by typing exit the xemacs survives, 
but if I close the shell window it does not.
Well, now we're getting away from clisp into unix (linux?) questions.
The rest of my previous message remains valid.

---

From: Rafal Strzalinski <[email-masked]>
Date: 12 Jun 2000 14:24:20 +0200

> output appears without any force-output.

I've swiched to cmu-lisp with net library from clocc.sourceforge.net
and I'm very happy :-)). Everything works OK.

> socket close

Under cmu-lisp you can catch SIGPIPE.

---

From: Rafal Strzalinski <[email-masked]>
Date: 12 Jun 2000 15:01:37 +0200

[email-masked] (Don Cohen) writes:

> Weird.

You kill shell, and shell kills started jobs.
try 
disown %1
where %1 is a xemacs's job number.

---

From: Sam Steingold <[email-masked]>
Date: Mon, 12 Jun 2000 10:22:09 -0400

> Under cmu-lisp you can catch SIGPIPE.

you can use ignore-errors or handler-case or ... in CLISP too.