From: Florian
Subject: unable to catch simple-error, debugger is not nice in server
Date: 
Message-ID: <1148317736.587505.215400@i39g2000cwa.googlegroups.com>
Hello.

I'm in the course of learning Lisp. As a first project I decided
to write a (naive) webserver. All goes quite well, only I can't
make it catch aborts correctly. The problem is, every time
I stop this I hit the debugger. And interactivity isn't exaxtly
the thing for a server process.

There is an unwind-protect for arbitrary interruptions, and
there is a handler-case for simple-error conditions. It looks
silly right now, because they do the same thing, but a) this
might change, and b) other special-case error handlers will
probably follow. Both mechanisms do work, apparently.
When I :abort from the debugger, the socket gets released
properly and I can rebind afterwards. When I bind a socket
to the same port (with netcat), then create-inet-listener
raises a simple-error, and this gets handled properly by the
handler-case.

I use slime (cvs HEAD). What does not work is an interrupt
from slime (C-c C-c). This invokes the debugger, no matter
what. Still, it's an simple-error, which should impact in my
handler, to my understanding. Am I wrong? Or, is this, perhaps
a slime ideosyncrasy? Here is my code.

(defun serve ()
  (format t "HTTP server started (Port: ~A)~%" *port*)
  (let ((socket))
    (unwind-protect
	 (handler-case
	     (progn
	       (setf socket (create-inet-listener *port*
						  :stream
						  :reuse-address t))
	       (format t "create-inet-listener (port ~A) ok (Socket: ~A)~%"
*port* socket)
	       (do ((file-desc (accept-tcp-connection socket)
			       (accept-tcp-connection socket)))
		   (nil)
		 (format t "Connection accepted OK~%")
		 (handle-req file-desc)))
	   (simple-error (e)
	     (format t "In error handler ~A~%" e)
	     (release-socket socket)))
      (release-socket socket))))

I'm aware that this code will not react properly to OS
signals. That's still another topic.


Florian

(This is toy code only. Any further bug indications or style
critiques are highly welcome.)

From: Pascal Bourguignon
Subject: Re: unable to catch simple-error, debugger is not nice in server
Date: 
Message-ID: <87bqtq7ygq.fsf@thalassa.informatimago.com>
"Florian" <···············@gmail.com> writes:
> I use slime (cvs HEAD). What does not work is an interrupt
> from slime (C-c C-c). This invokes the debugger, no matter
> what. Still, it's an simple-error, which should impact in my
> handler, to my understanding. Am I wrong? Or, is this, perhaps
> a slime ideosyncrasy? Here is my code.

You could ask the debugger what condition invoked it, and try to
handle it instead.  There's some measure of implementation dependance
here, user interrupts are not specified by the HyperSpec AFAIK.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
        Un chat errant
se soulage
        dans le jardin d'hiver
                                        Shiki
From: Florian
Subject: Re: unable to catch simple-error, debugger is not nice in server
Date: 
Message-ID: <1148319735.395612.63920@i39g2000cwa.googlegroups.com>
It is a simple-error condition. (I use CMU CL, btw.)

Florian