mirror of
https://github.com/appleboy/drone-ssh.git
synced 2025-09-13 20:00:10 +08:00
[easyssh] Scan stdout and stderr in Stream in seperate goroutines. (appleboy/easyssh-proxy#41)
Fixes appleboy/easyssh-proxy#40. Splits stdout and stderr scanning into seperate goroutines, and waits on both to finish through use of a wait group. Also changed `res` chan to use empty structs as they take up less memory. https://github.com/appleboy/drone-ssh/commit/e788e0d12bd
This commit is contained in:
parent
442ce52def
commit
b5fc545ce2
16
vendor/github.com/appleboy/easyssh-proxy/easyssh.go
generated
vendored
16
vendor/github.com/appleboy/easyssh-proxy/easyssh.go
generated
vendored
@ -13,6 +13,7 @@ import (
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
@ -201,17 +202,28 @@ func (ssh_conf *MakeConfig) Stream(command string, timeout time.Duration) (<-cha
|
||||
defer session.Close()
|
||||
|
||||
timeoutChan := time.After(timeout * time.Second)
|
||||
res := make(chan bool, 1)
|
||||
res := make(chan struct{}, 1)
|
||||
var resWg sync.WaitGroup
|
||||
resWg.Add(2)
|
||||
|
||||
go func() {
|
||||
for stdoutScanner.Scan() {
|
||||
stdoutChan <- stdoutScanner.Text()
|
||||
}
|
||||
resWg.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
for stderrScanner.Scan() {
|
||||
stderrChan <- stderrScanner.Text()
|
||||
}
|
||||
resWg.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
resWg.Wait()
|
||||
// close all of our open resources
|
||||
res <- true
|
||||
res <- struct{}{}
|
||||
}()
|
||||
|
||||
select {
|
||||
|
Loading…
Reference in New Issue
Block a user