Dumbest possible echo server.

This commit is contained in:
Tony Garnock-Jones 2012-07-03 15:50:39 -04:00
parent 7838272680
commit ab5b1850d0
1 changed files with 23 additions and 9 deletions

View File

@ -81,12 +81,28 @@
(define (repl-instance cname)
(define inbound-stream (channel-stream-name #t cname))
(define outbound-stream (channel-stream-name #f cname))
(define (ch-do action-ctor stream body)
(at-meta-level (action-ctor (channel-message stream body))))
(define (handle-channel-message state body)
(match body
[(channel-stream-request #"pty-req" _)
(transition state (ch-do send-feedback inbound-stream (channel-stream-ok)))]
[(channel-stream-notify #"env" _)
;; Don't care
state]
[(channel-stream-request #"shell" _)
(transition state
(at-meta-level (send-message (channel-message inbound-stream (channel-stream-ok))
'subscriber)))]
(ch-do send-feedback inbound-stream (channel-stream-ok))
(ch-do send-message outbound-stream (channel-stream-data #"Welcome!\r\n")))]
[(or (channel-stream-data #"\4") ;; C-d a.k.a EOT
(channel-stream-eof))
(transition state
(ch-do send-message outbound-stream (channel-stream-data #"Goodbye!\r\n"))
(kill))]
[(channel-stream-data bs)
(transition state
(ch-do send-feedback inbound-stream (channel-stream-credit (bytes-length bs)))
(ch-do send-message outbound-stream (channel-stream-data bs)))]
[m
(write `(channel inbound ,m)) (newline)
state]))
@ -96,13 +112,11 @@
(at-meta-level
(role 'input (topic-subscriber (channel-message inbound-stream (wild)))
#:state state
#:on-presence (transition state (at-meta-level
(send-message
(channel-message inbound-stream
(channel-stream-config
(default-packet-limit)
#""))
'subscriber)))
#:on-presence (transition state
(ch-do send-feedback inbound-stream (channel-stream-config
(default-packet-limit)
#""))
(ch-do send-feedback inbound-stream (channel-stream-credit 64)))
[(channel-message _ body)
(handle-channel-message state body)]))
(at-meta-level