@@ -1,11 +1,19 @@
|
||||
(module webui-wire-ipc racket/base
|
||||
|
||||
(require "webui-wire-download.rkt")
|
||||
(require "webui-wire-download.rkt"
|
||||
racket/string
|
||||
)
|
||||
|
||||
(provide webui-ipc)
|
||||
|
||||
(define re-kind #px"^([^:]+)[:]")
|
||||
|
||||
(define (is-int? str)
|
||||
(let ((re-num #px"^[0-9]+$"))
|
||||
(if (regexp-match re-num str)
|
||||
#t
|
||||
#f)))
|
||||
|
||||
(define (read-eol port)
|
||||
(read-string 1 port))
|
||||
|
||||
@@ -19,25 +27,28 @@
|
||||
(log-processor 'stderr-reader "webui-wire executable exited")
|
||||
'process-ended)
|
||||
(begin
|
||||
(unless (and
|
||||
(string? colon)
|
||||
(string=? colon ":"))
|
||||
(error "Unexpected input from webui-wire standard error"))
|
||||
(let* ((length (string->number str-length))
|
||||
(input (read-string length process-stderr))
|
||||
(m (regexp-match re-kind input))
|
||||
)
|
||||
(read-eol process-stderr)
|
||||
(if (eq? m #f)
|
||||
(log-processor 'stderr-reader
|
||||
(format "Unexpected: no kind: input = ~a" input))
|
||||
(let ((kind (string->symbol (list-ref m 1)))
|
||||
(line (substring input (string-length (car m))))
|
||||
)
|
||||
(if (eq? kind 'EVENT)
|
||||
(event-queuer line)
|
||||
(log-processor kind line))))
|
||||
)
|
||||
(if (and (string? colon) (string=? colon ":") (is-int? str-length))
|
||||
; process line
|
||||
(let* ((length (string->number str-length))
|
||||
(input (read-string length process-stderr))
|
||||
(m (regexp-match re-kind input))
|
||||
)
|
||||
(read-eol process-stderr)
|
||||
(if (eq? m #f)
|
||||
(log-processor 'stderr-reader
|
||||
(format "Unexpected: no kind: input = ~a" input))
|
||||
(let ((kind (string->symbol (list-ref m 1)))
|
||||
(line (substring input (string-length (car m))))
|
||||
)
|
||||
(if (eq? kind 'EVENT)
|
||||
(event-queuer line)
|
||||
(log-processor kind line))))
|
||||
)
|
||||
; otherwise skip line
|
||||
(let* ((line (read-line process-stderr))
|
||||
(msg (string-trim (string-append str-length colon line))))
|
||||
(log-processor 'stderr-reader msg))
|
||||
)
|
||||
(reader)
|
||||
)
|
||||
))
|
||||
@@ -48,12 +59,12 @@
|
||||
)
|
||||
|
||||
(define (webui-ipc event-queuer log-processor)
|
||||
(let ((webui-wire-exe (ww-webui-wire)))
|
||||
(displayln webui-wire-exe)
|
||||
(let* ((webui-wire-exe (ww-webui-wire))
|
||||
(proc-args (append (list #f #f #f) webui-wire-exe))
|
||||
)
|
||||
(call-with-values
|
||||
(λ () (subprocess #f #f #f webui-wire-exe))
|
||||
(λ () (apply subprocess proc-args))
|
||||
(λ (pid process-stdout process-stdin process-stderr)
|
||||
;(displayln (format "~a ~a ~a ~a" pid process-stdout process-stdin process-stderr))
|
||||
(let ((reader-thrd (process-stderr-reader process-stderr event-queuer log-processor)))
|
||||
(λ (cmd)
|
||||
(displayln cmd process-stdin)
|
||||
|
||||
Reference in New Issue
Block a user