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

@ -6,7 +6,7 @@
>frp 是一个高性能的反向代理应用,可以帮助你轻松的进行内网穿透,对外网提供服务,对于 http 服务还支持虚拟主机功能访问80端口可以根据域名路由到后端不同的 http 服务。
## frp 的作用?
## frp 的作用
* 利用处于内网或防火墙后的机器,对外网环境提供 http 服务。
* 对于 http 服务支持基于域名的虚拟主机支持自定义域名绑定使多个域名可以共用一个80端口。

View File

@ -19,6 +19,7 @@ import (
"fmt"
"io"
"net"
"strings"
"sync"
"time"
@ -129,11 +130,14 @@ func (c *Conn) GetLocalAddr() (addr string) {
func (c *Conn) ReadLine() (buff string, err error) {
buff, err = c.Reader.ReadString('\n')
if err == io.EOF {
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
}

View File

@ -2,6 +2,7 @@ package main
import (
"fmt"
"io"
"frp/utils/conn"
)
@ -31,6 +32,9 @@ func main() {
func echoWorker(c *conn.Conn) {
for {
buff, err := c.ReadLine()
if err == io.EOF {
break
}
if err != nil {
fmt.Printf("echo server read error: %v\n", err)
return