aboutsummaryrefslogtreecommitdiffstats
path: root/golib/eows/eows-out.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-08-07 18:08:27 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-08-07 19:30:25 +0200
commit7496dbabaf710a9e0f3b599c83163adddfcb8870 (patch)
treed2ab9f9f89edc0f381a71a967d920cef3e150be5 /golib/eows/eows-out.go
parent62e2996fcbcd704653d3043046c451fbc044918b (diff)
Added eows (Exec Over WebSocket) package.
Diffstat (limited to 'golib/eows/eows-out.go')
-rw-r--r--golib/eows/eows-out.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/golib/eows/eows-out.go b/golib/eows/eows-out.go
new file mode 100644
index 0000000..d624618
--- /dev/null
+++ b/golib/eows/eows-out.go
@@ -0,0 +1,47 @@
+package eows
+
+import (
+ "bufio"
+ "io"
+)
+
+// scanBlocks
+func scanBlocks(data []byte, atEOF bool) (advance int, token []byte, err error) {
+ if atEOF && len(data) == 0 {
+ return 0, nil, nil
+ }
+ return len(data), data, nil
+}
+
+// cmdPumpStdout is in charge to forward stdout in websocket
+func (e *ExecOverWS) cmdPumpStdout(r io.Reader, done chan struct{}) {
+
+ defer func() {
+ }()
+
+ sc := bufio.NewScanner(r)
+ sc.Split(scanBlocks)
+ for sc.Scan() {
+ e.OutputCB(e, sc.Text(), "")
+ }
+ if sc.Err() != nil {
+ e.logError("stdout scan:", sc.Err())
+ }
+
+ close(done)
+}
+
+// cmdPumpStderr is in charge to forward stderr in websocket
+func (e *ExecOverWS) cmdPumpStderr(r io.Reader) {
+
+ defer func() {
+ }()
+ sc := bufio.NewScanner(r)
+ sc.Split(scanBlocks)
+ for sc.Scan() {
+ e.OutputCB(e, "", sc.Text())
+ }
+ if sc.Err() != nil {
+ e.logError("stderr scan:", sc.Err())
+ }
+}