42 lines
1.6 KiB
Racket
42 lines
1.6 KiB
Racket
|
#lang syndicate
|
||
|
;;; SPDX-License-Identifier: LGPL-3.0-or-later
|
||
|
;;; SPDX-FileCopyrightText: Copyright © 2022 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
||
|
|
||
|
(require syndicate/distributed/ports)
|
||
|
(require syndicate/driver-support)
|
||
|
|
||
|
(require (only-in racket/system system))
|
||
|
|
||
|
(message-struct log (timestamp details))
|
||
|
|
||
|
(module+ main
|
||
|
(standard-actor-system/no-services (ds)
|
||
|
(spawn #:name 'main
|
||
|
(spawn/link #:name 'subprocess
|
||
|
(define-values (stdout-in stdout-out) (make-pipe))
|
||
|
(define-values (stdin-in stdin-out) (make-pipe))
|
||
|
(linked-thread
|
||
|
#:name 'subprocess-io
|
||
|
(lambda (facet)
|
||
|
(parameterize ((current-input-port stdin-in)
|
||
|
(current-output-port stdout-out))
|
||
|
(system "racket dummy-port-relay.rkt"))))
|
||
|
(define (cleanup!)
|
||
|
(close-input-port stdout-in)
|
||
|
(close-output-port stdout-out)
|
||
|
(close-input-port stdin-in)
|
||
|
(close-output-port stdin-out))
|
||
|
(actor-add-exit-hook! this-actor cleanup!)
|
||
|
(run-port-relay
|
||
|
#:input-port stdout-in
|
||
|
#:output-port stdin-out
|
||
|
#:name 'loader-relay
|
||
|
#:import (lambda (c)
|
||
|
(at (embedded-value c)
|
||
|
(assert (hash 'hello-from 'loader
|
||
|
'log (embedded
|
||
|
(object
|
||
|
[#:message v
|
||
|
(writeln `(got log ,v))])))))
|
||
|
))))))
|