mirror of
https://github.com/lwch/natpass.git
synced 2026-10-21 04:51:27 +00:00
修改重试逻辑
This commit is contained in:
@@ -2,6 +2,7 @@ package pool
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"natpass/code/network"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -126,6 +127,20 @@ func (conn *Conn) loopRead(cancel context.CancelFunc) {
|
||||
}
|
||||
}
|
||||
|
||||
func loopWrite(conn *network.Conn, msg *network.Msg, timeout time.Duration) error {
|
||||
var err error
|
||||
for i := 0; i < 10; i++ {
|
||||
err = conn.WriteMessage(msg, timeout)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "i/o timeout") {
|
||||
continue
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
return errors.New("too many retry")
|
||||
}
|
||||
|
||||
func (conn *Conn) loopWrite(cancel context.CancelFunc) {
|
||||
defer conn.Close()
|
||||
defer cancel()
|
||||
@@ -135,12 +150,11 @@ func (conn *Conn) loopWrite(cancel context.CancelFunc) {
|
||||
return
|
||||
}
|
||||
msg.From = conn.ID
|
||||
err := conn.conn.WriteMessage(msg, conn.parent.cfg.WriteTimeout)
|
||||
if err == nil {
|
||||
continue
|
||||
err := loopWrite(conn.conn, msg, conn.parent.cfg.WriteTimeout)
|
||||
if err != nil {
|
||||
logging.Error("write message error on %s: %v", conn.ID, err)
|
||||
return
|
||||
}
|
||||
logging.Error("write message error on %s: %v", conn.ID, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"natpass/code/network"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -57,7 +58,16 @@ func (c *client) run() {
|
||||
}
|
||||
|
||||
func (c *client) writeMessage(msg *network.Msg) error {
|
||||
return c.c.WriteMessage(msg, c.parent.cfg.WriteTimeout)
|
||||
for i := 0; i < 10; i++ {
|
||||
err := c.c.WriteMessage(msg, c.parent.cfg.WriteTimeout)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "i/o timeout") {
|
||||
continue
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
return errors.New("too many retry")
|
||||
}
|
||||
|
||||
func (c *client) addLink(id string) {
|
||||
|
||||
Reference in New Issue
Block a user