mirror of
https://github.com/fumiama/WireGold.git
synced 2026-06-23 20:16:27 +08:00
fix(tcp): early quit of recv
This commit is contained in:
@@ -116,10 +116,11 @@ func (conn *Conn) accept() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (conn *Conn) receive(ep *EndPoint) {
|
func (conn *Conn) receive(ep *EndPoint) {
|
||||||
dialtimeout := conn.addr.dialtimeout
|
peerstimeout := ep.peerstimeout
|
||||||
if dialtimeout < time.Second {
|
if peerstimeout < time.Second {
|
||||||
dialtimeout = time.Second
|
peerstimeout = time.Second * 5
|
||||||
}
|
}
|
||||||
|
peerstimeout *= 2
|
||||||
for {
|
for {
|
||||||
r := &connrecv{addr: ep}
|
r := &connrecv{addr: ep}
|
||||||
if conn.addr == nil || conn.lstn == nil || conn.peers == nil || conn.recv == nil {
|
if conn.addr == nil || conn.lstn == nil || conn.peers == nil || conn.recv == nil {
|
||||||
@@ -132,7 +133,7 @@ func (conn *Conn) receive(ep *EndPoint) {
|
|||||||
r.conn = tcpconn
|
r.conn = tcpconn
|
||||||
|
|
||||||
stopch := make(chan struct{})
|
stopch := make(chan struct{})
|
||||||
t := time.AfterFunc(dialtimeout, func() {
|
t := time.AfterFunc(peerstimeout, func() {
|
||||||
stopch <- struct{}{}
|
stopch <- struct{}{}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -146,7 +147,7 @@ func (conn *Conn) receive(ep *EndPoint) {
|
|||||||
select {
|
select {
|
||||||
case <-stopch:
|
case <-stopch:
|
||||||
logrus.Debugln("[tcp] recv from", ep, "timeout")
|
logrus.Debugln("[tcp] recv from", ep, "timeout")
|
||||||
return
|
continue
|
||||||
case <-copych:
|
case <-copych:
|
||||||
t.Stop()
|
t.Stop()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user