Set a reasonable value for the read deadline
This commit is contained in:
parent
91cd88b101
commit
17704469cc
|
@ -60,6 +60,7 @@ type TwitchPubSub struct {
|
|||
responseCh chan *twitchMessage
|
||||
|
||||
SubscribedTopics []string
|
||||
LastPing time.Time
|
||||
}
|
||||
|
||||
func NewTwitchPubSub() *TwitchPubSub {
|
||||
|
@ -91,8 +92,6 @@ func (t *TwitchPubSub) Open() error {
|
|||
return err
|
||||
}
|
||||
|
||||
c.SetReadDeadline(45 * time.Second)
|
||||
|
||||
t.wsConn = c
|
||||
|
||||
t.listening = make(chan interface{})
|
||||
|
@ -235,6 +234,8 @@ func (t *TwitchPubSub) Unlisten(topics []string) error {
|
|||
|
||||
func (t *TwitchPubSub) reader(wsConn *websocket.Conn, listening <-chan interface{}) {
|
||||
for {
|
||||
t.wsConn.SetReadDeadline(t.LastPing.Add(45 * time.Second))
|
||||
|
||||
var message twitchMessage
|
||||
err := t.wsConn.ReadJSON(&message)
|
||||
|
||||
|
@ -299,6 +300,7 @@ func (t *TwitchPubSub) pinger(wsConn *websocket.Conn, listening <-chan interface
|
|||
if t.debug {
|
||||
log.Println("Sending ping")
|
||||
}
|
||||
t.LastPing = time.Now()
|
||||
t.wsMutex.Lock()
|
||||
err := wsConn.WriteJSON(&twitchMessage{Type: Ping})
|
||||
t.wsMutex.Unlock()
|
||||
|
|
Loading…
Reference in New Issue