This commit is contained in:
crusader 2018-04-04 16:31:01 +09:00
parent 8a218a0806
commit e12a800dd3
2 changed files with 18 additions and 6 deletions

View File

@ -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

View File

@ -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