Experiment - moved sigwinch goroutine out of main client

This commit is contained in:
Russ Magee 2018-05-20 14:48:24 -07:00
parent 8f087e9ca1
commit 89dd225910
3 changed files with 47 additions and 25 deletions

View file

@ -15,12 +15,10 @@ import (
"log" "log"
"os" "os"
"os/exec" "os/exec"
"os/signal"
"os/user" "os/user"
"runtime" "runtime"
"strings" "strings"
"sync" "sync"
"syscall"
hkexsh "blitter.com/go/hkexsh" hkexsh "blitter.com/go/hkexsh"
isatty "github.com/mattn/go-isatty" isatty "github.com/mattn/go-isatty"
@ -113,9 +111,6 @@ func main() {
defer conn.Close() defer conn.Close()
// From this point on, conn is a secure encrypted channel // From this point on, conn is a secure encrypted channel
rows := 0
cols := 0
// Set stdin in raw mode if it's an interactive session // Set stdin in raw mode if it's an interactive session
// TODO: send flag to server side indicating this // TODO: send flag to server side indicating this
// affects shell command used // affects shell command used
@ -223,26 +218,7 @@ func main() {
}() }()
if isInteractive { if isInteractive {
// Handle pty resizes (notify server side) handleTermResizes()
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGWINCH)
wg.Add(1)
go func() {
defer wg.Done()
for range ch {
// Query client's term size so we can communicate it to server
// pty after interactive session starts
rows, cols, err = getTermSize()
log.Printf("[rows %v cols %v]\n", rows, cols)
if err != nil {
panic(err)
}
termSzPacket := fmt.Sprintf("%d %d", rows, cols)
conn.WritePacket([]byte(termSzPacket), hkexsh.CSOTermSize)
}
}()
ch <- syscall.SIGWINCH // Initial resize.
// client writer (to server) goroutine // client writer (to server) goroutine
wg.Add(1) wg.Add(1)

38
hkexsh/termsize_linux.go Normal file
View file

@ -0,0 +1,38 @@
// +build linux
package main
import (
"fmt"
"log"
"os"
"os/signal"
"syscall"
hkexsh "blitter.com/go/hkexsh"
)
// Handle pty resizes (notify server side)
func handleTermResizes() {
rows := 0
cols := 0
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGWINCH)
wg.Add(1)
go func() {
defer wg.Done()
for range ch {
// Query client's term size so we can communicate it to server
// pty after interactive session starts
rows, cols, err = getTermSize()
log.Printf("[rows %v cols %v]\n", rows, cols)
if err != nil {
panic(err)
}
termSzPacket := fmt.Sprintf("%d %d", rows, cols)
conn.WritePacket([]byte(termSzPacket), hkexsh.CSOTermSize)
}
}()
ch <- syscall.SIGWINCH // Initial resize.
}

8
hkexsh/termsize_win.go Normal file
View file

@ -0,0 +1,8 @@
// +build windows
package main
// Handle pty resizes (notify server side)
func handleTermResizes() {
}