From 1dfa615d5fd41151050e98b07e95c87fb3827045 Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Fri, 5 Apr 2013 14:10:15 -0600 Subject: [PATCH] in the middle of sandboxing the compiler. --- whalesong/repl-prototype/sandboxed-server.rkt | 36 +++++++++++++++++++ whalesong/repl-prototype/server.rkt | 30 +++++++++------- 2 files changed, 53 insertions(+), 13 deletions(-) create mode 100644 whalesong/repl-prototype/sandboxed-server.rkt diff --git a/whalesong/repl-prototype/sandboxed-server.rkt b/whalesong/repl-prototype/sandboxed-server.rkt new file mode 100644 index 0000000..329e1d4 --- /dev/null +++ b/whalesong/repl-prototype/sandboxed-server.rkt @@ -0,0 +1,36 @@ +#lang racket + +(require racket/sandbox + racket/runtime-path + setup/dirs + racket/cmdline + (for-syntax racket/base)) + + +(define current-port (make-parameter 8080)) +(void (command-line + #:once-each + [("-p" "--port") p "Port (default 8080)" + (current-port (string->number p))])) + + + +(define-runtime-path server-path (build-path "server.rkt")) + +(define (my-network-guard name str port role) + (printf "I see: ~s ~s ~s ~s\n" name str port role) + #t) + + +(define eval + (parameterize ([sandbox-memory-limit 256] + [sandbox-output (current-output-port)] + [sandbox-network-guard my-network-guard]) + (printf "memory limit: ~s mb\n" (sandbox-memory-limit)) + (make-module-evaluator server-path + #:allow-read (list (build-path "/"))))) +(printf "starting server thread\n") +(define server-thread (eval `(start-server #:port ,(current-port)))) +(printf "thread started\n") + +(sync server-thread) \ No newline at end of file diff --git a/whalesong/repl-prototype/server.rkt b/whalesong/repl-prototype/server.rkt index 2cb8e42..dcd5417 100644 --- a/whalesong/repl-prototype/server.rkt +++ b/whalesong/repl-prototype/server.rkt @@ -7,7 +7,6 @@ racket/port racket/match racket/pretty - racket/cmdline web-server/servlet-env web-server/servlet "../make/make-structs.rkt" @@ -15,7 +14,6 @@ "../parser/parse-bytecode.rkt" "../compiler/compiler.rkt" "../js-assembler/assemble.rkt" - "write-runtime.rkt" (for-syntax racket/base)) (define-runtime-path htdocs (build-path "htdocs")) @@ -120,16 +118,22 @@ -(define current-port (make-parameter 8080)) -(void (command-line - #:once-each - [("-p" "--port") p "Port (default 8080)" - (current-port (string->number p))])) +(define (start-server #:port [port 8000]) + (thread (lambda () + (printf "starting web server on port ~s\n" port) + (serve/servlet start + #:servlet-path "/compile" + #:extra-files-paths (list htdocs) + #:launch-browser? #f + #:port port)))) -(write-repl-runtime-files) -(serve/servlet start - #:servlet-path "/compile" - #:extra-files-paths (list htdocs) - #:launch-browser? #f - #:port (current-port)) +(module+ main + (define current-port (make-parameter 8080)) + (require racket/cmdline) + (void (command-line + #:once-each + [("-p" "--port") p "Port (default 8080)" + (current-port (string->number p))])) + (start-server #:port (current-port))) + \ No newline at end of file