|
|
|
@ -15,6 +15,7 @@ import (
|
|
|
|
|
"net"
|
|
|
|
|
"os"
|
|
|
|
|
"os/signal"
|
|
|
|
|
"runtime"
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
@ -466,17 +467,20 @@ func main() {
|
|
|
|
|
signal.Notify(c, os.Interrupt)
|
|
|
|
|
go func() {
|
|
|
|
|
for range c {
|
|
|
|
|
cancel()
|
|
|
|
|
client.Close()
|
|
|
|
|
os.Exit(0)
|
|
|
|
|
closeAndExit(client, cancel, nil)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
for {
|
|
|
|
|
message, err = reader.ReadString('\n')
|
|
|
|
|
message = strings.TrimSuffix(message, "\n")
|
|
|
|
|
select {
|
|
|
|
|
case <-ctx.Done():
|
|
|
|
|
return
|
|
|
|
|
default:
|
|
|
|
|
if err != nil {
|
|
|
|
|
closeAndExit(client, cancel, errors.New("failed to read from stdin"))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
message = strings.TrimSuffix(message, "\n")
|
|
|
|
|
|
|
|
|
|
// Remove invalid code points.
|
|
|
|
|
message = validUTF8(message)
|
|
|
|
|