diff --git a/hkexnet.go b/hkexnet.go index 61943db..b74407e 100644 --- a/hkexnet.go +++ b/hkexnet.go @@ -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() == ": 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 } } + //if err != nil { + // if err.Error() != "EOF" { + // 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 err.Error() != "EOF" { + panic(err) + } // else { + // return 0, err + //} } if payloadLen > 16384 { panic("Insane payloadLen")