From 67919607f4ee14c3c9294bfce7a8dddf23d830c7 Mon Sep 17 00:00:00 2001 From: David Barksdale Date: Sat, 7 Jan 2017 23:23:43 -0600 Subject: Start on a Cyclades Portmaster driver --- build.boot | 6 ++++++ src/app/portmaster.clj | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/app/portmaster.clj diff --git a/build.boot b/build.boot index 4384fc8..ed1f242 100644 --- a/build.boot +++ b/build.boot @@ -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))) -- cgit v1.2.3-18-g5258