diff options
author | Arun Isaac | 2022-06-30 11:05:41 +0530 |
---|---|---|
committer | Arun Isaac | 2022-06-30 11:05:41 +0530 |
commit | 595eb2739742b30be21197a3c059eccb08e9926b (patch) | |
tree | 2a336a2401d7d94445e535c85925ab024cfd95b7 | |
parent | cbf42ddc838a328b89eaf4e02f77039b784850d6 (diff) | |
download | tissue-595eb2739742b30be21197a3c059eccb08e9926b.tar.gz tissue-595eb2739742b30be21197a3c059eccb08e9926b.tar.lz tissue-595eb2739742b30be21197a3c059eccb08e9926b.zip |
bin: Introduce listen specification for web service.
The new listen specification unifies unix sockets, IP addresses and
ports, all into one string.
* bin/tissue (address->socket-address): Delete function.
(listen->socket-address): New function.
(tissue-run-web): Use listen->socket-address instead of
address->socket-address. Specify default listen instead of default
address and port.
-rwxr-xr-x | bin/tissue | 40 |
1 files changed, 23 insertions, 17 deletions
@@ -190,22 +190,30 @@ Export the repository as a website to OUTPUT-DIRECTORY. (tissue-configuration-web-css (load-config)) (tissue-configuration-web-files (load-config))))))) -(define (address->socket-address address port) - "Convert ADDRESS and PORT to a socket address." +(define (listen->socket-address listen) + "Convert LISTEN specification to a socket address." (cond + ;; Unix socket + ((string-prefix? "unix:" listen) + (make-socket-address AF_UNIX + (string-remove-prefix "unix:" listen))) ;; IPv4 - ((string-contains address ".") - (make-socket-address AF_INET - (inet-pton AF_INET address) - port)) + ((guard (_ (else #f)) + (inet-pton AF_INET + (substring listen 0 (string-index-right listen #\:)))) + => (lambda (ip) + (make-socket-address + AF_INET ip (string->number + (substring listen (1+ (string-index-right listen #\:))))))) ;; IPv6 - ((string-contains address ":") - (make-socket-address AF_INET6 - (inet-pton AF_INET6 address) - port)) - ;; Unix socket (else - (make-socket-address AF_UNIX address)))) + (make-socket-address AF_INET6 + (inet-pton AF_INET6 + (string-trim-both + (substring listen 0 (string-index-right listen #\:)) + (char-set #\[ #\]))) + (string->number + (substring listen (1+ (string-index-right listen #\:)))))))) (define tissue-run-web (match-lambda* @@ -227,9 +235,8 @@ Run a web search service reading configuration from CONFIG-FILE. (append (call-with-input-file config-file read) result)) - ;; Default address and port - '((address . "127.0.0.1") - (port . 8080))))) + ;; Default listen + '((listen . "127.0.0.1:8080"))))) (let ((listen-repl (assq-ref args 'listen-repl))) (when listen-repl (spawn-server (cond @@ -243,8 +250,7 @@ Run a web search service reading configuration from CONFIG-FILE. "REPL server listening on ~a~%" listen-repl) (make-unix-domain-server-socket #:path listen-repl)))))) - (start-web-server (address->socket-address (assq-ref args 'address) - (assq-ref args 'port)) + (start-web-server (listen->socket-address (assq-ref args 'listen)) %xapian-index (tissue-configuration-web-css (load-config))))))) |