mirror of
https://github.com/fumiama/WireGold.git
synced 2026-06-19 09:40:23 +08:00
fix(tcp): close handing
This commit is contained in:
@@ -478,16 +478,18 @@ func (conn *Conn) WriteToPeer(b []byte, ep p2p.EndPoint) (n int, err error) {
|
|||||||
return 0, errors.New("data size " + strconv.Itoa(len(b)) + " is too large")
|
return 0, errors.New("data size " + strconv.Itoa(len(b)) + " is too large")
|
||||||
}
|
}
|
||||||
locked := conn.cplk.TryLock()
|
locked := conn.cplk.TryLock()
|
||||||
if !locked && (!conn.suberr || len(conn.subs) > 0) {
|
if !locked {
|
||||||
if config.ShowDebugLog {
|
if !conn.suberr || len(conn.subs) > 0 {
|
||||||
logrus.Debug("[tcp] try sub write to", tcpep)
|
if config.ShowDebugLog {
|
||||||
|
logrus.Debug("[tcp] try sub write to", tcpep)
|
||||||
|
}
|
||||||
|
n, err = conn.writeToPeer(b, tcpep, true) // try sub write
|
||||||
|
if err == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
conn.suberr = true // fast fail
|
||||||
}
|
}
|
||||||
n, err = conn.writeToPeer(b, tcpep, true) // try sub write
|
conn.cplk.Lock() // add to main queue
|
||||||
if err == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
conn.suberr = true // fast fail
|
|
||||||
conn.cplk.Lock() // add to main queue
|
|
||||||
}
|
}
|
||||||
defer conn.cplk.Unlock()
|
defer conn.cplk.Unlock()
|
||||||
return conn.writeToPeer(b, tcpep, false)
|
return conn.writeToPeer(b, tcpep, false)
|
||||||
|
|||||||
Reference in New Issue
Block a user