summaryrefslogtreecommitdiffstats
path: root/golib/eows/eows-out.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2018-01-26 17:08:38 +0100
committerSebastien Douheret <sebastien.douheret@iot.bzh>2018-01-26 17:08:45 +0100
commit60e342228ba8017e1cacc71a64280143832e7719 (patch)
treef3f9fa8f742bcdbabdc786b7e4f6d4a59f24dab1 /golib/eows/eows-out.go
parentfafb1d20fe1f67935292823ad6651fff28deefc4 (diff)
Added SplitLineTime and SplitTime support in eowsv0.1.9eel_5.0.1eel/5.0.15.0.1
- Used SplitTime to split command output by line - Used SplitLineTime to split command output by line or until a timeout has passed. Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'golib/eows/eows-out.go')
-rw-r--r--golib/eows/eows-out.go61
1 files changed, 45 insertions, 16 deletions
diff --git a/golib/eows/eows-out.go b/golib/eows/eows-out.go
index 6f6706c..b70e70c 100644
--- a/golib/eows/eows-out.go
+++ b/golib/eows/eows-out.go
@@ -4,16 +4,52 @@ import (
"bufio"
"io"
"strings"
+ "time"
)
-// scanBlocks - gain character by character (or as soon as one or more characters are available)
-func scanBlocks(data []byte, atEOF bool) (advance int, token []byte, err error) {
+// scanChars - gain character by character (or as soon as one or more characters are available)
+func scanChars(data []byte, atEOF bool) (advance int, token []byte, err error) {
if atEOF && len(data) == 0 {
return 0, nil, nil
}
return len(data), data, nil
}
+// _pumper is in charge to collect
+func (e *ExecOverWS) _pumper(sc *bufio.Scanner, fctOut func(s string)) {
+
+ // Select split function (default sc.ScanLines)
+ if e.OutSplit == SplitChar || e.OutSplit == SplitLineTime || e.OutSplit == SplitTime {
+ sc.Split(scanChars)
+ }
+
+ // Scan method according to split type
+ if e.OutSplit == SplitLineTime || e.OutSplit == SplitTime {
+ t0 := time.Now()
+ buf := ""
+ for sc.Scan() {
+ buf += sc.Text()
+ if time.Since(t0).Nanoseconds() > e.LineTimeSpan ||
+ (e.OutSplit == SplitLineTime && strings.Contains(buf, "\n")) {
+ fctOut(buf)
+ buf = ""
+ t0 = time.Now()
+ }
+ }
+ // Send remaining characters
+ if len(buf) > 0 {
+ e.OutputCB(e, "", buf)
+ }
+
+ } else {
+
+ for sc.Scan() {
+ e.OutputCB(e, sc.Text(), "")
+ }
+ }
+
+}
+
// cmdPumpStdout is in charge to forward stdout in websocket
func (e *ExecOverWS) cmdPumpStdout(r io.Reader, done chan struct{}) {
@@ -22,14 +58,10 @@ func (e *ExecOverWS) cmdPumpStdout(r io.Reader, done chan struct{}) {
sc := bufio.NewScanner(r)
- // else use default sc.ScanLines
- if e.OutSplit == SplitChar {
- sc.Split(scanBlocks)
- }
+ e._pumper(sc, func(bufOut string) {
+ e.OutputCB(e, bufOut, "")
+ })
- for sc.Scan() {
- e.OutputCB(e, sc.Text(), "")
- }
if sc.Err() != nil && !strings.Contains(sc.Err().Error(), "file already closed") {
e.logError("stdout scan: %v", sc.Err())
}
@@ -42,16 +74,13 @@ func (e *ExecOverWS) cmdPumpStderr(r io.Reader) {
defer func() {
}()
+
sc := bufio.NewScanner(r)
- // else use default sc.ScanLines
- if e.OutSplit == SplitChar {
- sc.Split(scanBlocks)
- }
+ e._pumper(sc, func(bufErr string) {
+ e.OutputCB(e, "", bufErr)
+ })
- for sc.Scan() {
- e.OutputCB(e, "", sc.Text())
- }
if sc.Err() != nil && !strings.Contains(sc.Err().Error(), "file already closed") {
e.logError("stderr scan: %v", sc.Err())
}
hlight">
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
  <remote fetch="https://gerrit.automotivelinux.org/gerrit/" name="agl" pushurl="ssh://gerrit.automotivelinux.org:29418" review="https://gerrit.automotivelinux.org/gerrit/"/>
  <remote fetch="https://github.com/" name="github"/>
  <remote fetch="git://git.openembedded.org/" name="openembedded"/>
  <remote fetch="git://code.qt.io/" name="qt.io"/>
  <remote fetch="git://git.yoctoproject.org/" name="yocto"/>
  
  <default remote="agl" revision="refs/tags/dab/3.99.2" sync-j="4"/>
  
  <project name="01org/meta-intel-iot-security" path="meta-intel-iot-security" remote="github" revision="20bbb97f6d5400b126ae96ef446c3e60c7e16285"/>
  <project name="01org/meta-security-isafw" path="meta-security-isafw" remote="github" revision="0fa0aff75ee21edd758a1baddc4522371a746f99" upstream="morty"/>
  <project name="AGL/meta-agl" path="meta-agl"/>
  <project name="AGL/meta-agl-demo" path="meta-agl-demo"/>
  <project name="AGL/meta-agl-devel" path="meta-agl-devel"/>
  <project name="AGL/meta-agl-extra" path="meta-agl-extra"/>
  <project name="AGL/meta-renesas" path="meta-renesas"/>
  <project name="AGL/meta-renesas-rcar-gen3" path="meta-renesas-rcar-gen3" revision="4fa88fc2e452dd1ca5992cb605b3cd1823ee5316" upstream="morty_bsp_2.19"/>
  <project name="Freescale/meta-freescale" path="meta-freescale" remote="github" revision="fa774ad7fb797957601a8c9fee45af453fea34b7" upstream="morty"/>
  <project name="Freescale/meta-freescale-3rdparty" path="meta-freescale-3rdparty" remote="github" revision="1879485e63ce369292c89b5902ff6df13509090b" upstream="morty"/>
  <project name="Freescale/meta-freescale-distro" path="meta-freescale-distro" remote="github" revision="cd5c7a2539f40004f74126e9fdf08254fd9a6390" upstream="morty"/>
  <project name="advancedtelematic/meta-updater" path="meta-updater" remote="github" revision="45c155a67d3532ad32342fc512e8bf6341ab9e5d"/>
  <project name="boundarydevices/meta-boundary" path="meta-boundary" remote="github" revision="d44ee8f58d841cf13fbe63dab271344e2b9ba6db" upstream="morty"/>
  <project name="kraj/meta-altera" path="meta-altera" remote="github" revision="4364dbfcb600da82ecdfc4797f112d187e40f1c3"/>
  <project name="meta-intel" remote="yocto" revision="6add41510412ca196efb3e4f949d403a8b6f35d7" upstream="morty"/>
  <project name="meta-oic" remote="yocto" revision="028a5c234fb9fe51b39db339f7d4250fba978198" upstream="1.2.0"/>
  <project name="meta-openembedded" remote="openembedded" revision="fe5c83312de11e80b85680ef237f8acb04b4b26e" upstream="morty"/>
  <project name="meta-qcom" remote="yocto" revision="26380970fbe5e8a04efe8c1098ad45acae0d87e4" upstream="morty"/>
  <project name="meta-qt5/meta-qt5" path="meta-qt5" remote="github" revision="5f837b47f5c3e462f24cd5abf58ff6ef1dd04932"/>
  <project name="meta-raspberrypi" remote="yocto" revision="28d4404f89eb59d406b4976c0e3f5ca19137ba74"/>
  <project name="meta-rust/meta-rust" path="meta-rust" remote="github" revision="a506df4ba4b186e311117d5bdc6a54844583a4fd"/>
  <project name="meta-ti" remote="yocto" revision="460ce7d0473b88d20fcb3fed3aa0f3acc37c78c9" upstream="master"/>
  <project name="poky" remote="yocto" revision="fd7f2d644a94bbb951c0bed11af7deb35f1cfb22" upstream="morty"/>
</manifest>