(module rpc-io mzscheme
(provide write*
read*
newline*
io-ok?
io-error?
rpc-notify?
wrong-input?
)
(define (read* port)
(with-handlers ((exn:fail? (lambda (exn)
(cons '%rpc-wrong-input% (exn-message exn)))))
(read port)))
(define (write* any port)
(with-handlers ((exn:fail? (lambda (exn)
(cons '%rpc-io-error% (exn-message exn)))))
(begin
(write any port)
(flush-output port)
'%rpc-ok%)))
(define (newline* port)
(with-handlers ((exn:fail? (lambda (exn)
(cons '%rpc-io-error% (exn-message exn)))))
(begin
(display "\r\n" port)
(flush-output port))))
(define (io-error? r)
(if (pair? r)
(eq? (car r) '%rpc-io-error%)
#f))
(define (wrong-input? r)
(if (pair? r)
(eq? (car r) '%rpc-wrong-input%)
#f))
(define (io-ok? r)
(eq? r '%rpc-io-ok%))
(define (rpc-notify? r)
(if (pair? r)
(eq? (car r) '%rpc-notify%)
#f))
)