2014-06-02 20:36:55 +00:00
|
|
|
#lang minimart
|
|
|
|
|
|
|
|
(require (only-in racket/port read-bytes-line-evt))
|
|
|
|
(require "../drivers/tcp.rkt")
|
|
|
|
(require "../userland.rkt")
|
|
|
|
|
|
|
|
(define local-handle (tcp-handle 'chat))
|
|
|
|
(define remote-handle (tcp-address "localhost" 5999))
|
|
|
|
|
|
|
|
(spawn-tcp-driver)
|
|
|
|
|
|
|
|
(userland-thread
|
2014-06-06 22:07:58 +00:00
|
|
|
#:gestalt
|
|
|
|
(gestalt-union (sub (event (read-bytes-line-evt (current-input-port) 'any) ?) #:meta-level 1)
|
|
|
|
(sub (tcp-channel remote-handle local-handle ?))
|
|
|
|
(sub (tcp-channel remote-handle local-handle ?) #:level 1)
|
|
|
|
(pub (tcp-channel local-handle remote-handle ?)))
|
|
|
|
(wait-for-gestalt (sub (tcp-channel remote-handle local-handle ?) #:level 1))
|
2014-06-02 20:36:55 +00:00
|
|
|
(let loop ()
|
|
|
|
(match (next-event)
|
2014-06-06 22:07:58 +00:00
|
|
|
[(message (event _ (list (? eof-object?))) 1 #f)
|
|
|
|
(do (quit))]
|
|
|
|
[(message (event _ (list line)) 1 #f)
|
|
|
|
(do (send (tcp-channel local-handle remote-handle line)))]
|
|
|
|
[(message (tcp-channel _ _ bs) 0 #f)
|
|
|
|
(write-bytes bs)
|
|
|
|
(flush-output)]
|
|
|
|
[(routing-update g)
|
|
|
|
(when (gestalt-empty? g) (do (quit)))])
|
2014-06-02 20:36:55 +00:00
|
|
|
(loop)))
|