ing
This commit is contained in:
parent
e84aea5d11
commit
bbbdae8dcd
|
@ -4,8 +4,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
logging "git.loafle.net/commons/logging-go"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func connReadHandler(readWriteHandler ReadWriteHandler, conn Conn, stopChan <-chan struct{}, doneChan chan<- error, readChan chan<- []byte) {
|
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
|
doneChan <- err
|
||||||
}()
|
}()
|
||||||
|
|
||||||
conn.SetReadLimit(readWriteHandler.GetMaxMessageSize())
|
if 0 < readWriteHandler.GetMaxMessageSize() {
|
||||||
conn.SetReadDeadline(time.Now().Add(readWriteHandler.GetReadTimeout()))
|
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.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
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -71,7 +79,11 @@ func connWriteHandler(readWriteHandler ReadWriteHandler, conn Conn, stopChan <-c
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case message, ok = <-writeChan:
|
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 {
|
if !ok {
|
||||||
conn.WriteMessage(CloseMessage, []byte{})
|
conn.WriteMessage(CloseMessage, []byte{})
|
||||||
return
|
return
|
||||||
|
@ -79,17 +91,19 @@ func connWriteHandler(readWriteHandler ReadWriteHandler, conn Conn, stopChan <-c
|
||||||
|
|
||||||
wc, err = conn.NextWriter(TextMessage)
|
wc, err = conn.NextWriter(TextMessage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.Logger().Debug(err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
wc.Write(message)
|
wc.Write(message)
|
||||||
|
|
||||||
if err = wc.Close(); nil != err {
|
if err = wc.Close(); nil != err {
|
||||||
logging.Logger().Debug(err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case <-ticker.C:
|
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 {
|
if err = conn.WriteMessage(PingMessage, nil); nil != err {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user