summaryrefslogtreecommitdiff
path: root/ebus-racket/net-repl.rkt
blob: 1d538072115f5abd53bc6274984a92c197a7caed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#lang racket
(require mzlib/thread)
(require "db.rkt")

(define-namespace-anchor a)
(define ns (namespace-anchor->namespace a))

(define (my-eval expr)
  (eval expr ns))  


(define (run-tcp-repl namespace port)
    (thread
     (lambda ()
       (run-server port
                   net-repl-connection
                   #f
		  (lambda (port-k max-allow-wait reuse?)
		    (tcp-listen port-k max-allow-wait reuse? "127.0.0.1"))
		))))
              
  (define (net-repl-connection i o)
    (let/ec exit
    (parameterize ([current-input-port   i]
                   [current-output-port  o]
                   [current-error-port   o]
		   [current-namespace ns])
        (read-eval-print-loop))
      (fprintf o "\nBye...\n")
      (close-output-port o)))


(define-namespace-anchor ns-anchor)
(thread-wait (run-tcp-repl (namespace-anchor->namespace ns-anchor) 8890))