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

@@ -46,7 +46,7 @@ Options:
-L log_file set output log file, including console
--log-level=<log_level> set log level: debug, info, warn, error
--addr=<bind_addr> listen addr for client, example: 0.0.0.0:7000
--reload reload ini file and configures in common section won't be changed
--reload reload ini file and configures in common section won't be changed
-h --help show this screen
-v --version show version
`

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
}