From 4f534972195b4aa9160c86f97f4035c4f52b1b36 Mon Sep 17 00:00:00 2001 From: Tim Williams Date: Thu, 26 Jul 2018 17:18:42 -0400 Subject: [PATCH] add some error handling for closed connections --- shyftRingWalletConn/app.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/shyftRingWalletConn/app.go b/shyftRingWalletConn/app.go index dcb6297daf..7fcff91f51 100644 --- a/shyftRingWalletConn/app.go +++ b/shyftRingWalletConn/app.go @@ -9,6 +9,7 @@ import ( "github.com/ShyftNetwork/go-empyrean/crypto" "bytes" "github.com/ShyftNetwork/go-empyrean/common/hexutil" + "io" ) const ( @@ -62,10 +63,18 @@ func handleRequest(conn net.Conn) { for { msg, err := conn.Read(buf) - - if err == nil { - msgBuf = append(msgBuf, buf[:msg]...) + if err == io.EOF { + fmt.Println("END OF FILE, CLOSING CONNECTION") + conn.Close() + conn = nil + break } + if err != nil { + fmt.Println("Connection error: ", err) + break + } + + msgBuf = append(msgBuf, buf[:msg]...) index := bytes.IndexByte(msgBuf, 0x0a) for index != -1 { newMsg := msgBuf[:index]