Server-side client hangup working; TODO - client-side handling of post-exit EOF (broken pipe)

This commit is contained in:
Russ Magee 2018-03-25 23:00:37 -07:00
parent 65b7af8063
commit cb0ce956b9
1 changed files with 21 additions and 9 deletions

View File

@ -300,6 +300,7 @@ func (hl HKExListener) Accept() (hc Conn, err error) {
func (c Conn) Read(b []byte) (n int, err error) {
//log.Printf("[Decrypting...]\r\n")
log.Printf("Read() requests %d bytes\n", len(b))
for {
//log.Printf("c.dBuf.Len(): %d\n", c.dBuf.Len())
if c.dBuf.Len() > 0 /* len(b) */ {
@ -311,21 +312,32 @@ func (c Conn) Read(b []byte) (n int, err error) {
// Read the hmac LSB and payload len first
err = binary.Read(c.c, binary.BigEndian, &hmacIn)
if err != nil {
if err.Error() != "EOF" {
log.Println("Error was:", err.Error())
// Normal client 'exit' from interactive session will cause
// (on server side) err.Error() == "<iface/addr info ...>: use of closed network connection"
if err != nil && err.Error() != "EOF" {
if !strings.HasSuffix(err.Error(), "use of closed network connection") {
log.Println("unexpected Read() err:", err)
} else {
return 0, err
log.Println("[Client hung up]")
return 0, io.EOF
}
}
err = binary.Read(c.c, binary.BigEndian, &payloadLen)
if err != nil {
//if err != nil {
// if err.Error() != "EOF" {
panic(err)
// log.Println("Error was:", err.Error())
// } else {
// return 0, err
// }
//}
err = binary.Read(c.c, binary.BigEndian, &payloadLen)
if err != nil {
if err.Error() != "EOF" {
panic(err)
} // else {
// return 0, err
//}
}
if payloadLen > 16384 {
panic("Insane payloadLen")