aboutsummaryrefslogtreecommitdiffstats
path: root/golib/eows/eows-out.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2018-03-09 15:57:36 +0100
committerSebastien Douheret <sebastien.douheret@iot.bzh>2018-03-09 16:08:53 +0100
commitf1e97cdbcc13318cb3de39d9e67bc0241614dfcc (patch)
tree04188e8d91e6b1b6a77d21614237f96f2bbbed1f /golib/eows/eows-out.go
parentabbf89a5589f2c92f786bb45c5cd613a318a9e24 (diff)
Improved PtyMode (eows lib).
- renamed PtsMode to PtyMode - used byte array instead of string - allowed terminal echo on/off (PtyMode only) - fixed support escaped and control characters (PtyMode only) Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'golib/eows/eows-out.go')
-rw-r--r--golib/eows/eows-out.go49
1 files changed, 37 insertions, 12 deletions
diff --git a/golib/eows/eows-out.go b/golib/eows/eows-out.go
index 2d9bdb0..3163b2f 100644
--- a/golib/eows/eows-out.go
+++ b/golib/eows/eows-out.go
@@ -56,16 +56,15 @@ func (e *ExecOverWS) _pumper(sc *bufio.Scanner, fctCB func(s string)) {
}
-// cmdPumpStdout is in charge to forward stdout in websocket
-func (e *ExecOverWS) cmdPumpStdout(r io.Reader, done chan struct{}) {
-
- defer func() {
- }()
+// pipePumpStdout is in charge to forward stdout in websocket
+func (e *ExecOverWS) pipePumpStdout(r io.Reader, done chan struct{}) {
sc := bufio.NewScanner(r)
e._pumper(sc, func(b string) {
- e.OutputCB(e, b, "")
+ if e.OutputCB != nil {
+ e.OutputCB(e, []byte(b), []byte{})
+ }
})
e.logDebug("STDOUT pump exit")
@@ -77,16 +76,15 @@ func (e *ExecOverWS) cmdPumpStdout(r io.Reader, done chan struct{}) {
close(done)
}
-// cmdPumpStderr is in charge to forward stderr in websocket
-func (e *ExecOverWS) cmdPumpStderr(r io.Reader) {
-
- defer func() {
- }()
+// pipePumpStderr is in charge to forward stderr in websocket
+func (e *ExecOverWS) pipePumpStderr(r io.Reader) {
sc := bufio.NewScanner(r)
e._pumper(sc, func(b string) {
- e.OutputCB(e, "", b)
+ if e.OutputCB != nil {
+ e.OutputCB(e, []byte{}, []byte(b))
+ }
})
e.logDebug("STDERR pump exit")
@@ -95,3 +93,30 @@ func (e *ExecOverWS) cmdPumpStderr(r io.Reader) {
e.logError("stderr scan: %v", sc.Err())
}
}
+
+// ptsPumpStdout is in charge to forward stdout in websocket
+// (only used when PtyMode is set)
+func (e *ExecOverWS) ptsPumpStdout(r io.Reader, done chan struct{}) {
+
+ buffer := make([]byte, 1024)
+ for {
+ n, err := r.Read(buffer)
+ if err != nil {
+ if err != io.EOF &&
+ !strings.Contains(err.Error(), "file already closed") {
+ e.logError("Error stdout read: %v", err)
+ }
+ break
+ }
+ if n == 0 {
+ continue
+ }
+ if e.OutputCB != nil {
+ e.OutputCB(e, buffer[:n], []byte{})
+ }
+ }
+
+ close(done)
+
+ e.logDebug("Eows stdout pump exited")
+}