From: ilya
Subject: clisp sockets
Date: 
Message-ID: <newscache$dih98h$wx$1@lnews.actcom.co.il>
Hi.
When socket port is already in use (socket-server used_port) causes 
fatal error (i mean that the execution aborts).
I tried to (catch t (socket-server)) without success.
Tried (unwind-protect (socket-server) (format t "after")) -
the second part is never reached.
What do I miss/doing wrong ?

Add. info:
platforms - linux,netbsd
on windows it doesn't seem to cause an error (why?)

From: Greg Menke
Subject: Re: clisp sockets
Date: 
Message-ID: <m3vg1318m3.fsf@europa.pienet>
ilya <············@example.com> writes:

> Hi.
> When socket port is already in use (socket-server used_port) causes
> fatal error (i mean that the execution aborts).
> I tried to (catch t (socket-server)) without success.
> Tried (unwind-protect (socket-server) (format t "after")) -
> the second part is never reached.
> What do I miss/doing wrong ?
> 
> Add. info:
> platforms - linux,netbsd
> on windows it doesn't seem to cause an error (why?)

handler-bind or handler-case, whichever suits you better, are probably
what you want.  I imagine Doze isn't causing the error because the
tcp/ip api isn't returning one.

Gregm
From: Henrik Motakef
Subject: Re: clisp sockets
Date: 
Message-ID: <87n0mfxkdd.fsf@interim.henrik-motakef.de>
ilya <············@example.com> writes:

> When socket port is already in use (socket-server used_port) causes
> fatal error (i mean that the execution aborts).

It doesn't just abort, you end up in the debugger. Try typing "help"
for a list of debugger commands.

> I tried to (catch t (socket-server)) without success.

CATCH is not usually used for error handling in Lisp, unlike Java or
C++. catch/throw are more general control structures here. For more
about the Common Lisp condition system, see for example
<http://world.std.com/~pitman/Papers/Condition-Handling-2001.html> and
<http://www.lispworks.com/reference/HyperSpec/Body/09_.htm>.

> Tried (unwind-protect (socket-server) (format t "after")) -
> the second part is never reached.

Not until you exit the debugger:

  [1]> (socket-server 9876)
  #<SOCKET-SERVER 0.0.0.0:9876>
  [2]> (unwind-protect (socket-server 9876) (format t "So there."))
  
  *** - UNIX error 48 (EADDRINUSE): Address already in use
  1. Break [3]> :q ; exit the debugger
  So there.
  [4]> 

UNWIND-PROTECT "guarantees that cleanup-forms are executed before
unwind-protect exits" - but in your case, it didn't exit yet. There is
a problem, but it could after all be solvable without all forms
protected by UNWIND-PROTECT having to fail. For example, if you'd try
to open a file, you could simply try it again with another file name
(look for "restarts" in the hyperspec. This is one of the most amazing
features of CL, IMHO.) The form that failed for you isn't done yet,
you are supposed to either fix it or say that you can't.

By the way:

  [1]> (socket-server 9876)
  #<SOCKET-SERVER 0.0.0.0:9876>
  [2]> (ignore-errors (socket-server 9876))
  NIL ;
  #<SYSTEM::SIMPLE-OS-ERROR #x203086A9>
  [3]> (handler-case (socket-server 9876)
         (system::simple-os-error (err) 
           (format *error-output* "Oh my: ~A" err)))
  Oh my: UNIX error 48 (EADDRINUSE): Address already in use
  NIL
  [4]>


hth
Henrik
From: ilya
Subject: Re: clisp sockets
Date: 
Message-ID: <newscache$jd4a8h$iw1$1@lnews.actcom.co.il>
Henrik Motakef wrote:
> ilya <············@example.com> writes:
> 
> 
>>When socket port is already in use (socket-server used_port) causes
>>fatal error (i mean that the execution aborts).
> 
> 
> It doesn't just abort, you end up in the debugger. Try typing "help"
> for a list of debugger commands.
Ok. I guess i would if i was running this script from r.e.p. loop.
I'll try this.
> 
> 
>>I tried to (catch t (socket-server)) without success.
> 
> 
> CATCH is not usually used for error handling in Lisp, unlike Java or
> C++. catch/throw are more general control structures here. For more
> about the Common Lisp condition system, see for example
> <http://world.std.com/~pitman/Papers/Condition-Handling-2001.html> and
> <http://www.lispworks.com/reference/HyperSpec/Body/09_.htm>.
I've RTFMed (catch ..) and though that os error shoult (throw ..).
I should read this more carefully. Thanks.
> 
> 
>>Tried (unwind-protect (socket-server) (format t "after")) -
>>the second part is never reached.
> 
> 
> Not until you exit the debugger:
> 
>   [1]> (socket-server 9876)
>   #<SOCKET-SERVER 0.0.0.0:9876>
>   [2]> (unwind-protect (socket-server 9876) (format t "So there."))
>   
>   *** - UNIX error 48 (EADDRINUSE): Address already in use
>   1. Break [3]> :q ; exit the debugger
>   So there.
>   [4]> 
Running the script not from rep loop just gives the unix error.
Strange, i think, it should continue to (format ...).
> 
> UNWIND-PROTECT "guarantees that cleanup-forms are executed before
> unwind-protect exits" - but in your case, it didn't exit yet. There is
> a problem, but it could after all be solvable without all forms
> protected by UNWIND-PROTECT having to fail. For example, if you'd try
> to open a file, you could simply try it again with another file name
> (look for "restarts" in the hyperspec. This is one of the most amazing
> features of CL, IMHO.) The form that failed for you isn't done yet,
> you are supposed to either fix it or say that you can't.
> 
> By the way:
> 
>   [1]> (socket-server 9876)
>   #<SOCKET-SERVER 0.0.0.0:9876>
>   [2]> (ignore-errors (socket-server 9876))
>   NIL ;
>   #<SYSTEM::SIMPLE-OS-ERROR #x203086A9>
This one is probably what i'm looking for.
Thanks a lot.
>   [3]> (handler-case (socket-server 9876)
>          (system::simple-os-error (err) 
>            (format *error-output* "Oh my: ~A" err)))
>   Oh my: UNIX error 48 (EADDRINUSE): Address already in use
>   NIL
This one seems to be usefull too. Thanks.
>   [4]>
> 
> 
> hth
> Henrik
From: Sam Steingold
Subject: Re: clisp sockets
Date: 
Message-ID: <m3hecms4n5.fsf@loiso.podval.org>
> * In message <······················@lnews.actcom.co.il>
> * On the subject of "Re: clisp sockets"
> * Sent on Mon, 06 Jan 2003 08:22:54 +0200
> * Honorable ilya <············@example.com> writes:
>
> >   [1]> (socket-server 9876)
> >   #<SOCKET-SERVER 0.0.0.0:9876>
> >   [2]> (unwind-protect (socket-server 9876) (format t "So there."))
> >     *** - UNIX error 48 (EADDRINUSE): Address already in use
> >   1. Break [3]> :q ; exit the debugger
> >   So there.
> >   [4]>
> Running the script not from rep loop just gives the unix error.

when you run this from a script, CLISP exits on errors.
see <http://clisp.cons.org/impnotes.html#quickstart>:

        Continuable errors will be turned to warnings. Non-continuable
        errors and Control-C interrupts will terminate the execution of
        the Lisp script with an error status.

See <http://clisp.cons.org/impnotes.html#conditions>
(EXT:EXIT-ON-ERROR and EXT:APPEASE-CERRORS).

> Strange, i think, it should continue to (format ...).

$ ./foo

*** - UNIX error 98 (EADDRINUSE): Address already in use
 -- So there --

$ cat foo
#!/usr/local/bin/clisp

(socket-server 9876)
(unwind-protect (socket-server 9876) (format t "~% -- So there --~%"))
$

-- 
Sam Steingold (http://www.podval.org/~sds) running RedHat8 GNU/Linux
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.palestine-central.com/links.html>
Don't ascribe to malice what can be adequately explained by stupidity.
From: Scott Schwartz
Subject: Re: clisp sockets
Date: 
Message-ID: <8gfzs4p8nh.fsf@galapagos.cse.psu.edu>
Henrik Motakef <··············@web.de> writes:
> It doesn't just abort, you end up in the debugger. Try typing "help"
> for a list of debugger commands.

What's the right idiom for telling Common Lisp that standard input and
output are connected to a network socket an we don't want to give the
bad guys a root shell, and standard error is connected to a log file
with no possibility of any human interaction?
From: Tim Bradshaw
Subject: Re: clisp sockets
Date: 
Message-ID: <ey3adibnc89.fsf@cley.com>
* Scott Schwartz wrote:

> What's the right idiom for telling Common Lisp that standard input and
> output are connected to a network socket an we don't want to give the
> bad guys a root shell, and standard error is connected to a log file
> with no possibility of any human interaction?

Use the error system to handle the errors.

--tim
From: Daniel Barlow
Subject: Re: clisp sockets
Date: 
Message-ID: <87k7hencnz.fsf@noetbook.telent.net>
Scott Schwartz <··········@usenet ·@bio.cse.psu.edu> writes:

> Henrik Motakef <··············@web.de> writes:
>> It doesn't just abort, you end up in the debugger. Try typing "help"
>> for a list of debugger commands.
>
> What's the right idiom for telling Common Lisp that standard input and
> output are connected to a network socket an we don't want to give the
> bad guys a root shell, and standard error is connected to a log file
> with no possibility of any human interaction?

Who mentioned standard input/output?  I thought it was pretty clear
from the OP's use of a 'socket-server' variable that this was in fact
a socket he'd opened.

It's probably quite rare that the right idiom is to restart Lisp for
every incoming connection, which your approach would seem to require.


-dan

-- 

   http://www.cliki.net/ - Link farm for free CL-on-Unix resources