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