mirror of https://gogs.blitter.com/RLabs/xs
Minor cleanup prior to tackling os.Exit() in doShellMode() and server-side tun hangs
This commit is contained in:
parent
6f1fcbbf7a
commit
0943797300
|
@ -96,19 +96,17 @@ func (hc *Conn) StartClientTunnel(lport, rport uint16) {
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
weAreListening := false
|
|
||||||
|
|
||||||
for cmd := range (*hc.tuns)[rport].Ctl {
|
for cmd := range (*hc.tuns)[rport].Ctl {
|
||||||
if cmd == 'a' && !weAreListening {
|
if cmd == 'a' {
|
||||||
l, e := net.Listen("tcp4", fmt.Sprintf(":%d", lport))
|
l, e := net.Listen("tcp4", fmt.Sprintf(":%d", lport))
|
||||||
if e != nil {
|
if e != nil {
|
||||||
logger.LogDebug(fmt.Sprintf("[ClientTun] Could not get lport %d! (%s)", lport, e))
|
logger.LogDebug(fmt.Sprintf("[ClientTun] Could not get lport %d! (%s)", lport, e))
|
||||||
} else {
|
} else {
|
||||||
weAreListening = true
|
|
||||||
logger.LogDebug(fmt.Sprintf("[ClientTun] Listening for client tunnel port %d", lport))
|
logger.LogDebug(fmt.Sprintf("[ClientTun] Listening for client tunnel port %d", lport))
|
||||||
|
|
||||||
for {
|
for {
|
||||||
c, e := l.Accept()
|
c, e := l.Accept() // blocks until new conn
|
||||||
// If tunnel is being re-used, re-init it
|
// If tunnel is being re-used, re-init it
|
||||||
if (*hc.tuns)[rport] == nil {
|
if (*hc.tuns)[rport] == nil {
|
||||||
hc.InitTunEndpoint(lport, "", rport)
|
hc.InitTunEndpoint(lport, "", rport)
|
||||||
|
@ -226,6 +224,9 @@ func (hc *Conn) StartClientTunnel(lport, rport uint16) {
|
||||||
|
|
||||||
} // end Accept() worker block
|
} // end Accept() worker block
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
|
// When both workers have exited due to a disconnect or other
|
||||||
|
// condition, it's safe to remove the tunnel descriptor.
|
||||||
logger.LogDebug("[ClientTun] workers exited")
|
logger.LogDebug("[ClientTun] workers exited")
|
||||||
delete((*hc.tuns), rport)
|
delete((*hc.tuns), rport)
|
||||||
} // end for-accept
|
} // end for-accept
|
||||||
|
|
|
@ -256,6 +256,7 @@ func doCopyMode(conn *hkexnet.Conn, remoteDest bool, files string, rec *hkexsh.S
|
||||||
func doShellMode(isInteractive bool, conn *hkexnet.Conn, oldState *hkexsh.State, rec *hkexsh.Session) {
|
func doShellMode(isInteractive bool, conn *hkexnet.Conn, oldState *hkexsh.State, rec *hkexsh.Session) {
|
||||||
//client reader (from server) goroutine
|
//client reader (from server) goroutine
|
||||||
//Read remote end's stdout
|
//Read remote end's stdout
|
||||||
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
@ -318,6 +319,7 @@ func doShellMode(isInteractive bool, conn *hkexnet.Conn, oldState *hkexsh.State,
|
||||||
// Wait until both stdin and stdout goroutines finish before returning
|
// Wait until both stdin and stdout goroutines finish before returning
|
||||||
// (ensure client gets all data from server before closing)
|
// (ensure client gets all data from server before closing)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func UsageShell() {
|
func UsageShell() {
|
||||||
|
|
Loading…
Reference in New Issue