diff --git a/net/client.go b/net/client.go index df0130e..b4d4181 100644 --- a/net/client.go +++ b/net/client.go @@ -163,8 +163,12 @@ func handleClientRead(c *Client, conn *server.Conn, doneChan chan<- struct{}, st close(doneChan) }() - conn.SetReadLimit(c.MaxMessageSize) - conn.SetReadDeadline(time.Now().Add(c.ReadTimeout)) + if 0 < c.MaxMessageSize { + conn.SetReadLimit(c.MaxMessageSize) + } + if 0 < c.ReadTimeout { + conn.SetReadDeadline(time.Now().Add(c.ReadTimeout)) + } conn.SetPongHandler(func(string) error { conn.SetReadDeadline(time.Now().Add(c.PongTimeout)) return nil @@ -220,7 +224,9 @@ func handleClientWrite(c *Client, conn *server.Conn, doneChan chan<- struct{}, s for { select { case message, ok := <-c.writeChan: - conn.SetWriteDeadline(time.Now().Add(c.WriteTimeout)) + if 0 < c.WriteTimeout { + conn.SetWriteDeadline(time.Now().Add(c.WriteTimeout)) + } if !ok { conn.WriteMessage(server.CloseMessage, []byte{}) return diff --git a/net/server.go b/net/server.go index 545c892..0bc7276 100644 --- a/net/server.go +++ b/net/server.go @@ -236,8 +236,12 @@ func handleRead(s *Server, conn *server.Conn, doneChan chan<- struct{}, stopChan close(doneChan) }() - conn.SetReadLimit(s.ServerHandler.GetMaxMessageSize()) - conn.SetReadDeadline(time.Now().Add(s.ServerHandler.GetReadTimeout())) + if 0 < s.ServerHandler.GetMaxMessageSize() { + conn.SetReadLimit(s.ServerHandler.GetMaxMessageSize()) + } + if 0 < s.ServerHandler.GetReadTimeout() { + conn.SetReadDeadline(time.Now().Add(s.ServerHandler.GetReadTimeout())) + } conn.SetPongHandler(func(string) error { conn.SetReadDeadline(time.Now().Add(s.ServerHandler.GetPongTimeout())) return nil @@ -293,7 +297,9 @@ func handleWrite(s *Server, conn *server.Conn, doneChan chan<- struct{}, stopCha for { select { case message, ok := <-writeChan: - conn.SetWriteDeadline(time.Now().Add(s.ServerHandler.GetWriteTimeout())) + if 0 < s.ServerHandler.GetWriteTimeout() { + conn.SetWriteDeadline(time.Now().Add(s.ServerHandler.GetWriteTimeout())) + } if !ok { conn.WriteMessage(server.CloseMessage, []byte{}) return