one more i/o fix in door handler - prompt doesn't always have a newline

This commit is contained in:
Sundog Jones 2021-04-16 14:48:56 -07:00
parent f371c01596
commit 97cc113329
1 changed files with 5 additions and 8 deletions

13
main.go
View File

@ -266,12 +266,6 @@ func doorHandler(ctx context.Context, c net.Conn, w *gaio.Watcher, menuwg *sync.
defer menuwg.Done()
var wg sync.WaitGroup
const bannerText = "\r\nCOLOSSAL CAVE\r\n\r\n"
err := w.Write(ctx, c, []byte(bannerText))
if err != nil {
log.Printf("error writing to connection: %v\n", err)
}
var inChan, _ chan gaio.OpResult
var ok bool
@ -354,10 +348,13 @@ func doorHandler(ctx context.Context, c net.Conn, w *gaio.Watcher, menuwg *sync.
if l > 0 {
w.Write(ctx, c, outBuf[:l])
log.Printf("wrote %d bytes to watcher: %v\n", l, string(outBuf[:l]))
waitingForInput = true
if strings.Contains(string(outBuf[:l]), ">") {
// a prompt appeared!
waitingForInput = true
}
} else {
// zero output? let's get some input?
waitingForInput = true
// waitingForInput = true
w.Read(ctx, c, nil)
}
}