summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2022-06-30 11:05:41 +0530
committerArun Isaac2022-06-30 11:05:41 +0530
commit595eb2739742b30be21197a3c059eccb08e9926b (patch)
tree2a336a2401d7d94445e535c85925ab024cfd95b7
parentcbf42ddc838a328b89eaf4e02f77039b784850d6 (diff)
downloadtissue-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-xbin/tissue40
1 files changed, 23 insertions, 17 deletions
diff --git a/bin/tissue b/bin/tissue
index fb1656e..bf69100 100755
--- a/bin/tissue
+++ b/bin/tissue
@@ -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)))))))