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) close(doneChan)
}() }()
if 0 < c.MaxMessageSize {
conn.SetReadLimit(c.MaxMessageSize) conn.SetReadLimit(c.MaxMessageSize)
}
if 0 < c.ReadTimeout {
conn.SetReadDeadline(time.Now().Add(c.ReadTimeout)) conn.SetReadDeadline(time.Now().Add(c.ReadTimeout))
}
conn.SetPongHandler(func(string) error { conn.SetPongHandler(func(string) error {
conn.SetReadDeadline(time.Now().Add(c.PongTimeout)) conn.SetReadDeadline(time.Now().Add(c.PongTimeout))
return nil return nil
@ -220,7 +224,9 @@ func handleClientWrite(c *Client, conn *server.Conn, doneChan chan<- struct{}, s
for { for {
select { select {
case message, ok := <-c.writeChan: case message, ok := <-c.writeChan:
if 0 < c.WriteTimeout {
conn.SetWriteDeadline(time.Now().Add(c.WriteTimeout)) conn.SetWriteDeadline(time.Now().Add(c.WriteTimeout))
}
if !ok { if !ok {
conn.WriteMessage(server.CloseMessage, []byte{}) conn.WriteMessage(server.CloseMessage, []byte{})
return return

View File

@ -236,8 +236,12 @@ func handleRead(s *Server, conn *server.Conn, doneChan chan<- struct{}, stopChan
close(doneChan) close(doneChan)
}() }()
if 0 < s.ServerHandler.GetMaxMessageSize() {
conn.SetReadLimit(s.ServerHandler.GetMaxMessageSize()) conn.SetReadLimit(s.ServerHandler.GetMaxMessageSize())
}
if 0 < s.ServerHandler.GetReadTimeout() {
conn.SetReadDeadline(time.Now().Add(s.ServerHandler.GetReadTimeout())) conn.SetReadDeadline(time.Now().Add(s.ServerHandler.GetReadTimeout()))
}
conn.SetPongHandler(func(string) error { conn.SetPongHandler(func(string) error {
conn.SetReadDeadline(time.Now().Add(s.ServerHandler.GetPongTimeout())) conn.SetReadDeadline(time.Now().Add(s.ServerHandler.GetPongTimeout()))
return nil return nil
@ -293,7 +297,9 @@ func handleWrite(s *Server, conn *server.Conn, doneChan chan<- struct{}, stopCha
for { for {
select { select {
case message, ok := <-writeChan: case message, ok := <-writeChan:
if 0 < s.ServerHandler.GetWriteTimeout() {
conn.SetWriteDeadline(time.Now().Add(s.ServerHandler.GetWriteTimeout())) conn.SetWriteDeadline(time.Now().Add(s.ServerHandler.GetWriteTimeout()))
}
if !ok { if !ok {
conn.WriteMessage(server.CloseMessage, []byte{}) conn.WriteMessage(server.CloseMessage, []byte{})
return return