diff options
author | Thomas White <taw@physics.org> | 2022-11-13 22:00:21 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2022-11-13 22:00:42 +0100 |
commit | bb380e62a3ec5e4649848c2407b63870394b0353 (patch) | |
tree | de52e81c739eec4b658139a2000b311ef2a9d9f8 | |
parent | c8e6e432eb1201d0bd1fc8740e8192a16c2e6211 (diff) |
New scanout part 2: Broadcast combined state via UDP
-rw-r--r-- | guile/starlet/scanout.scm | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/guile/starlet/scanout.scm b/guile/starlet/scanout.scm index 133b973..3d049ed 100644 --- a/guile/starlet/scanout.scm +++ b/guile/starlet/scanout.scm @@ -29,6 +29,7 @@ #:use-module (ice-9 threads) #:use-module (ice-9 atomic) #:use-module (ice-9 exceptions) + #:use-module (ice-9 binary-ports) #:use-module (srfi srfi-1) #:export (patch-fixture! patch-many! @@ -171,8 +172,20 @@ (eq? attr intensity)) +(define broadcast-socket + (socket PF_INET SOCK_DGRAM 0)) + + +(define (serialize-state st) + (call-with-output-bytevector + (lambda (port) + (write st port)))) + (define (broadcast-state st) - (atomic-box-swap! current-values st)) + (atomic-box-swap! current-values st) + (sendto broadcast-socket + (serialize-state st) + (make-socket-address AF_INET INADDR_BROADCAST 5749))) (define (output-loop start-time count) @@ -212,6 +225,8 @@ (define (start-output) + (setsockopt broadcast-socket SOL_SOCKET SO_BROADCAST 1) + (bind broadcast-socket AF_INET INADDR_LOOPBACK 0) (if output-thread (format #t "Output thread is already running\n") (let ((start-time (hirestime))) |