优化disconnect的错误

This commit is contained in:
lwch
2021-08-25 00:07:31 +08:00
parent 9506a679d1
commit 1de4d412eb
+12 -8
View File
@@ -11,12 +11,13 @@ import (
)
type Link struct {
parent *Tunnel
id string // link id
target string // target id
local net.Conn
remote *pool.Conn
OnWork chan struct{}
parent *Tunnel
id string // link id
target string // target id
local net.Conn
remote *pool.Conn
OnWork chan struct{}
closeFromRemote bool
}
func NewLink(parent *Tunnel, id, target string, local net.Conn, remote *pool.Conn) *Link {
@@ -67,6 +68,7 @@ func (link *Link) remoteRead() {
case network.Msg_disconnect:
logging.Info("disconnect link %s on tunnel %s from remote",
link.id, link.parent.Name)
link.closeFromRemote = true
return
}
}
@@ -79,8 +81,10 @@ func (link *Link) localRead() {
for {
n, err := link.local.Read(buf)
if err != nil {
link.remote.SendDisconnect(link.target, link.id)
logging.Error("read data on tunnel %s link %s failed, err=%v", link.parent.Name, link.id, err)
if !link.closeFromRemote {
link.remote.SendDisconnect(link.target, link.id)
}
// logging.Error("read data on tunnel %s link %s failed, err=%v", link.parent.Name, link.id, err)
return
}
if n == 0 {