utils/conn: fix a socket error in windows

This commit is contained in:
fatedier
2016-06-06 11:43:41 +08:00
parent 04014bb78f
commit 2640c0b570
4 changed files with 15 additions and 7 deletions

View File

@@ -19,6 +19,7 @@ import (
"fmt"
"io"
"net"
"strings"
"sync"
"time"
@@ -129,10 +130,13 @@ func (c *Conn) GetLocalAddr() (addr string) {
func (c *Conn) ReadLine() (buff string, err error) {
buff, err = c.Reader.ReadString('\n')
if err == io.EOF {
c.mutex.Lock()
c.closeFlag = true
c.mutex.Unlock()
if err != nil {
// wsarecv error in windows means connection closed
if err == io.EOF || strings.Contains(err.Error(), "wsarecv: An existing connection was forcibly closed") {
c.mutex.Lock()
c.closeFlag = true
c.mutex.Unlock()
}
}
return buff, err
}