diff options
-rw-r--r-- | build.boot | 6 | ||||
-rw-r--r-- | src/app/portmaster.clj | 23 |
2 files changed, 29 insertions, 0 deletions
@@ -6,6 +6,7 @@ [compojure "1.5.1"] [hoplon/castra "3.0.0-alpha5"] [hoplon "6.0.0-alpha17.amatus0"] + [net.sf.expectit/expectit-core "0.8.2"] [org.clojure/clojure "1.7.0"] [org.clojure/clojurescript "1.7.170"] [org.clojure/tools.nrepl "0.2.12" :scope "test"] @@ -37,6 +38,11 @@ :reload true :port 8000))) +(deftask dev-repl + "Run clojure repl." + [] + (repl)) + (deftask prod "Build tankputer for production deployment." [] diff --git a/src/app/portmaster.clj b/src/app/portmaster.clj new file mode 100644 index 0000000..0d88270 --- /dev/null +++ b/src/app/portmaster.clj @@ -0,0 +1,23 @@ +(ns app.portmaster + (:import (java.io File) + (java.util.concurrent TimeUnit) + (net.sf.expectit ExpectBuilder))) + +(def pm (agent nil)) + +(defn init + [port-name] + (let [socat (.. (new ProcessBuilder + (into-array ["socat" + "-v" + (str "OPEN:" port-name ",b9600,raw") + "-"])) + (redirectError (new File "/tmp/portmaster.log")) + (start)) + expect (.. (new ExpectBuilder) + (withInputs (into-array [(.getInputStream socat)])) + (withOutput (.getOutputStream socat)) + (withTimeout 1 TimeUnit/SECONDS) + (withExceptionOnFailure) + (build))] + (send pm assoc :socat socat :expect expect))) |