mirror of
				https://github.com/appleboy/drone-ssh.git
				synced 2025-10-29 00:51:15 +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" | 	"net" | ||||||
| 	"os" | 	"os" | ||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
|  | 	"sync" | ||||||
| 	"time" | 	"time" | ||||||
| 
 | 
 | ||||||
| 	"golang.org/x/crypto/ssh" | 	"golang.org/x/crypto/ssh" | ||||||
| @ -201,17 +202,28 @@ func (ssh_conf *MakeConfig) Stream(command string, timeout time.Duration) (<-cha | |||||||
| 		defer session.Close() | 		defer session.Close() | ||||||
| 
 | 
 | ||||||
| 		timeoutChan := time.After(timeout * time.Second) | 		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() { | 		go func() { | ||||||
| 			for stdoutScanner.Scan() { | 			for stdoutScanner.Scan() { | ||||||
| 				stdoutChan <- stdoutScanner.Text() | 				stdoutChan <- stdoutScanner.Text() | ||||||
| 			} | 			} | ||||||
|  | 			resWg.Done() | ||||||
|  | 		}() | ||||||
|  | 
 | ||||||
|  | 		go func() { | ||||||
| 			for stderrScanner.Scan() { | 			for stderrScanner.Scan() { | ||||||
| 				stderrChan <- stderrScanner.Text() | 				stderrChan <- stderrScanner.Text() | ||||||
| 			} | 			} | ||||||
|  | 			resWg.Done() | ||||||
|  | 		}() | ||||||
|  | 
 | ||||||
|  | 		go func() { | ||||||
|  | 			resWg.Wait() | ||||||
| 			// close all of our open resources
 | 			// close all of our open resources
 | ||||||
| 			res <- true | 			res <- struct{}{} | ||||||
| 		}() | 		}() | ||||||
| 
 | 
 | ||||||
| 		select { | 		select { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Joshua Elliott
						Joshua Elliott