Additional PREPARE argument for with-inspecting-handler

This commit is contained in:
Martin Gasbichler 2003-02-26 15:38:36 +00:00
parent 29b1d1b0a9
commit 234d1cc70a
2 changed files with 27 additions and 17 deletions

View File

@ -19,7 +19,7 @@ Same as above but communication is done via a socket on port PORT.
The structure SOCKET2STDPORTS offers a very simple facility to map the The structure SOCKET2STDPORTS offers a very simple facility to map the
current input and output ports to the ports of a socket. current input and output ports to the ports of a socket.
(socket<->std-ports host port) (socket<->stdports host port)
This procedure first establishes a TCP socket to port PORT on host This procedure first establishes a TCP socket to port PORT on host
HOST. Afterwards is reads all data from (current-input-port) and HOST. Afterwards is reads all data from (current-input-port) and
@ -28,27 +28,32 @@ from the socket's output port and prints it to
(current-output-port). (current-output-port).
(with-inspecting-handler port thunk) (with-inspecting-handler port prepare thunk)
This procedure installs a exception handler which captures all This procedure installs a exception handler which captures all
conditions which satisfy the predicate ERROR?. It will then fire up a conditions which satisfy the predicate ERROR?. In case of an exception
remote REPL on port PORT with the continuation of the condition as PREPARE is applied to the condition. If it returns #t,
focus value. Currently, the continuation of the REPL is the WITH-INSPECTING-HANDLER will fire up a remote REPL on port PORT with
continuation of the call to WITH-INSPECTING-HANDLER. the continuation of the condition as focus value. Currently, the
continuation of the REPL is the continuation of the call to
WITH-INSPECTING-HANDLER. If PREPARE returns #f the surrounding handler
is called.
As an example for the usage of the remote inspecting utility, consider As an example for the usage of the remote inspecting utility, consider
a program using WITH-INSPECTING-HANDLER with an obviously bogus body: a program using WITH-INSPECTING-HANDLER with an obviously bogus body:
(with-inspecting-handler 8080 (lambda () (/ 1 0))) >(with-inspecting-handler 8080
(lambda (cond) (display "Help me on port 8080") #t)
(lambda () (/ 1 0)))
Help me on port 8080
Now start a second scsh: Now start a second scsh:
[0 gasbichl@ventoux interaction] scsh -lm interfaces.scm -lm packages.scm -o 'socket2stdports' [0 gasbichl@ventoux interaction] scsh -lm interfaces.scm -lm packages.scm -o 'socket2stdports'
Welcome to scsh 0.6.3 Welcome to scsh 0.6.3
Type ,? for help. Type ,? for help.
> (socket<->std-ports "ventoux" 8080) > (socket<->stdports "ventoux" 8080)
Welcome to the command processor of the remote scsh Welcome to the command processor of the remote scsh
#{Exception-continuation (pc 69) (integer/ in ratnums)} #{Exception-continuation (pc 69) (integer/ in ratnums)}
> ,debug > ,debug

View File

@ -22,13 +22,18 @@
(more)))) ; Keep looking for a handler. (more)))) ; Keep looking for a handler.
(lambda () (call-with-values thunk accept))))))))) (lambda () (call-with-values thunk accept)))))))))
(define (with-inspecting-handler port thunk) (define (with-inspecting-handler port prepare thunk)
(with-fatal-and-capturing-error-handler* (with-fatal-and-capturing-error-handler*
(lambda (condition condition-continuation more) (lambda (condition condition-continuation more)
(with-handler
(lambda (c2 m2)
(more))
(if (prepare condition)
(let ((res (let ((res
(remote-repl "Welcome to the command processor of the remote scsh" (remote-repl "Welcome to the command processor of the remote scsh"
condition-continuation condition-continuation
port))) port)))
;; TODO: option to return to continuation of handler (by leaving out the with-continuation) ;; TODO: option to return to continuation of handler (by leaving out the with-continuation)
(with-continuation condition-continuation (lambda () res)))) (with-continuation condition-continuation (lambda () res)))
(more))))
thunk)) thunk))