diff options
Diffstat (limited to 'module/calp')
-rw-r--r-- | module/calp/main.scm | 2 | ||||
-rw-r--r-- | module/calp/repl.scm | 34 |
2 files changed, 35 insertions, 1 deletions
diff --git a/module/calp/main.scm b/module/calp/main.scm index 040a7c00..2a7944a9 100644 --- a/module/calp/main.scm +++ b/module/calp/main.scm @@ -17,7 +17,7 @@ :use-module ((ice-9 popen) :select (open-input-pipe)) :use-module (statprof) - :use-module (repl) + :use-module (calp repl) ) diff --git a/module/calp/repl.scm b/module/calp/repl.scm new file mode 100644 index 00000000..f43b8fce --- /dev/null +++ b/module/calp/repl.scm @@ -0,0 +1,34 @@ +;;; Commentary: +;;; Starts a repl server on some form of address. +;;; Code: + +(define-module (calp repl) + :use-module (system repl server) + :use-module (ice-9 regex) + :use-module ((util hooks) :select (shutdown-hook)) + :use-module (util exceptions) + ) + +(define-public (repl-start address) + (define lst (string->list address)) + (format (current-error-port) + "Starting REPL server at ~a~%" address) + (spawn-server + (case (cond [(memv (car lst) '(#\. #\/)) 'UNIX] + [(string-match "(\\d{1,3}\\.){3}\\d{1,3}(:\\d+)?" address) 'IPv4] + ;; IPv6 is as of Gulie 2.2 not supported by make-tcp-server-socket. + ;; This might be the same problem as I encountered in my html server. + [else 'UNIX]) + [(UNIX) + (add-hook! shutdown-hook (lambda () (catch 'system-error (lambda () (delete-file address)) + (lambda (err proc fmt . args) + (warning "Failed to unlink ~a" address args) + err)))) + (make-unix-domain-server-socket path: address)] + [(IPv4) (apply (case-lambda + [() (error "Empty address?")] + [(address) (make-tcp-server-socket host: address)] + [(address port) (make-tcp-server-socket host: address port: port)]) + (string-split address #\:))] + ;; currently impossible + [(IPv6) (error "How did you get here?")]))) |