diff --git a/new-server.rkt b/new-server.rkt index 8992207..86290f8 100644 --- a/new-server.rkt +++ b/new-server.rkt @@ -133,6 +133,14 @@ (flush-output) state])) +(define-syntax-rule (wait-for topic-of-interest #:state state action ...) + (let ((role-name (gensym 'wait-for))) + (role role-name topic-of-interest + #:state state + #:on-presence (sequence-actions state + (delete-role role-name) + action ...)))) + (define (session-vm local-addr remote-addr) (define local-identification #"SSH-2.0-RacketSSH_0.0") @@ -160,12 +168,13 @@ (spawn (ssh-writer local-addr remote-addr) #:exit-signal? #t #:debug-name 'ssh-writer) - ;; (Wait for a cycle to let the reader and writer get - ;; started, then tell the reader we are ready for a single - ;; packet and spawn the session manager.) - ;; TODO: try using presence instead of the yield. - (yield #:state state - (transition state + ;; Wait for the reader and writer get started, then tell + ;; the reader we are ready for a single packet and spawn + ;; the session manager. + (wait-for (topic-subscriber (inbound-packet (wild) (wild) (wild) (wild)) #:monitor? #t) + #:state state + (wait-for (topic-publisher (outbound-packet (wild)) #:monitor? #t) + #:state state (send-message (inbound-credit 1)) (spawn (ssh-session local-identification remote-identification