diff --git a/socket/readwrite.go b/socket/readwrite.go index e324e90..b7e2308 100644 --- a/socket/readwrite.go +++ b/socket/readwrite.go @@ -4,8 +4,6 @@ import ( "fmt" "io" "time" - - logging "git.loafle.net/commons/logging-go" ) func connReadHandler(readWriteHandler ReadWriteHandler, conn Conn, stopChan <-chan struct{}, doneChan chan<- error, readChan chan<- []byte) { @@ -18,11 +16,21 @@ func connReadHandler(readWriteHandler ReadWriteHandler, conn Conn, stopChan <-ch doneChan <- err }() - conn.SetReadLimit(readWriteHandler.GetMaxMessageSize()) - conn.SetReadDeadline(time.Now().Add(readWriteHandler.GetReadTimeout())) + if 0 < readWriteHandler.GetMaxMessageSize() { + conn.SetReadLimit(readWriteHandler.GetMaxMessageSize()) + } + if 0 < readWriteHandler.GetReadTimeout() { + conn.SetReadDeadline(time.Now().Add(readWriteHandler.GetReadTimeout())) + } else { + conn.SetReadDeadline(time.Time{}) + } conn.SetPongHandler(func(string) error { - conn.SetReadDeadline(time.Now().Add(readWriteHandler.GetPongTimeout())) + if 0 < readWriteHandler.GetPongTimeout() { + conn.SetReadDeadline(time.Now().Add(readWriteHandler.GetPongTimeout())) + } else { + conn.SetReadDeadline(time.Time{}) + } return nil }) @@ -71,7 +79,11 @@ func connWriteHandler(readWriteHandler ReadWriteHandler, conn Conn, stopChan <-c for { select { case message, ok = <-writeChan: - conn.SetWriteDeadline(time.Now().Add(readWriteHandler.GetWriteTimeout())) + if 0 < readWriteHandler.GetWriteTimeout() { + conn.SetWriteDeadline(time.Now().Add(readWriteHandler.GetWriteTimeout())) + } else { + conn.SetWriteDeadline(time.Time{}) + } if !ok { conn.WriteMessage(CloseMessage, []byte{}) return @@ -79,17 +91,19 @@ func connWriteHandler(readWriteHandler ReadWriteHandler, conn Conn, stopChan <-c wc, err = conn.NextWriter(TextMessage) if err != nil { - logging.Logger().Debug(err) return } wc.Write(message) if err = wc.Close(); nil != err { - logging.Logger().Debug(err) return } case <-ticker.C: - conn.SetWriteDeadline(time.Now().Add(readWriteHandler.GetPingTimeout())) + if 0 < readWriteHandler.GetPingTimeout() { + conn.SetWriteDeadline(time.Now().Add(readWriteHandler.GetPingTimeout())) + } else { + conn.SetWriteDeadline(time.Time{}) + } if err = conn.WriteMessage(PingMessage, nil); nil != err { return }