mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
add some error handling for closed connections
This commit is contained in:
parent
7641245387
commit
4f53497219
1 changed files with 12 additions and 3 deletions
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/ShyftNetwork/go-empyrean/crypto"
|
"github.com/ShyftNetwork/go-empyrean/crypto"
|
||||||
"bytes"
|
"bytes"
|
||||||
"github.com/ShyftNetwork/go-empyrean/common/hexutil"
|
"github.com/ShyftNetwork/go-empyrean/common/hexutil"
|
||||||
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -62,10 +63,18 @@ func handleRequest(conn net.Conn) {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
msg, err := conn.Read(buf)
|
msg, err := conn.Read(buf)
|
||||||
|
if err == io.EOF {
|
||||||
if err == nil {
|
fmt.Println("END OF FILE, CLOSING CONNECTION")
|
||||||
msgBuf = append(msgBuf, buf[:msg]...)
|
conn.Close()
|
||||||
|
conn = nil
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Connection error: ", err)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
msgBuf = append(msgBuf, buf[:msg]...)
|
||||||
index := bytes.IndexByte(msgBuf, 0x0a)
|
index := bytes.IndexByte(msgBuf, 0x0a)
|
||||||
for index != -1 {
|
for index != -1 {
|
||||||
newMsg := msgBuf[:index]
|
newMsg := msgBuf[:index]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue