ing
This commit is contained in:
parent
e84aea5d11
commit
bbbdae8dcd
|
@ -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
|
||||
}()
|
||||
|
||||
if 0 < readWriteHandler.GetMaxMessageSize() {
|
||||
conn.SetReadLimit(readWriteHandler.GetMaxMessageSize())
|
||||
conn.SetReadDeadline(time.Now().Add(readWriteHandler.GetReadTimeout()))
|
||||
}
|
||||
|
||||
if 0 < readWriteHandler.GetReadTimeout() {
|
||||
conn.SetReadDeadline(time.Now().Add(readWriteHandler.GetReadTimeout()))
|
||||
} else {
|
||||
conn.SetReadDeadline(time.Time{})
|
||||
}
|
||||
conn.SetPongHandler(func(string) error {
|
||||
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:
|
||||
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:
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user