summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Barksdale <amatus@amatus.name>2017-01-07 23:23:43 -0600
committerDavid Barksdale <amatus@amatus.name>2017-01-07 23:25:48 -0600
commit67919607f4ee14c3c9294bfce7a8dddf23d830c7 (patch)
tree25d96fb1b714eec0cf095865a55fb6e2a890f8a1
parentb31224a0a2c3145cf97de47b4f5616b27fe2b843 (diff)
Start on a Cyclades Portmaster driver
-rw-r--r--build.boot6
-rw-r--r--src/app/portmaster.clj23
2 files changed, 29 insertions, 0 deletions
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)))