修改server的timeout

This commit is contained in:
lwch
2021-08-24 17:03:29 +08:00
parent 41b42b87fd
commit be846216e1
2 changed files with 12 additions and 3 deletions
+8
View File
@@ -0,0 +1,8 @@
package global
import "time"
const (
ReadTimeout = 5 * time.Second
WriteTimeout = 5 * time.Second
)
+4 -3
View File
@@ -1,6 +1,7 @@
package handler
import (
"natpass/code/client/global"
"natpass/code/network"
"strings"
"sync"
@@ -43,7 +44,7 @@ func (c *client) run() {
c.parent.closeAll(c)
return
}
msg, err := c.c.ReadMessage(time.Second)
msg, err := c.c.ReadMessage(global.ReadTimeout)
if err != nil {
if strings.Contains(err.Error(), "i/o timeout") {
continue
@@ -57,7 +58,7 @@ func (c *client) run() {
}
func (c *client) writeMessage(msg *network.Msg) error {
return c.c.WriteMessage(msg, time.Second)
return c.c.WriteMessage(msg, global.WriteTimeout)
}
func (c *client) addLink(id string) {
@@ -92,7 +93,7 @@ func (c *client) close(id string) {
Id: id,
},
}
c.c.WriteMessage(&msg, time.Second)
c.c.WriteMessage(&msg, global.WriteTimeout)
c.Lock()
delete(c.links, id)
c.Unlock()