feat: add read timeout for server messages
This commit is contained in:
parent
b494c2782e
commit
d25ce3eead
1 changed files with 2 additions and 0 deletions
|
@ -19,6 +19,7 @@ func (c *Client) ProcessServerMessages(channel chan<- GoTomato.ServerMessage) {
|
||||||
defer close(Done)
|
defer close(Done)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
c.Conn.SetReadDeadline(time.Now().Add(10 * time.Second))
|
||||||
_, message, err := c.Conn.ReadMessage()
|
_, message, err := c.Conn.ReadMessage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// On normal closure exit gracefully
|
// On normal closure exit gracefully
|
||||||
|
@ -26,6 +27,7 @@ func (c *Client) ProcessServerMessages(channel chan<- GoTomato.ServerMessage) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.LastErr = err
|
||||||
// Try to reconnect on unexpected disconnect
|
// Try to reconnect on unexpected disconnect
|
||||||
for {
|
for {
|
||||||
channel <- prevMessage // send previous ServerMessage to update view
|
channel <- prevMessage // send previous ServerMessage to update view
|
||||||
|
|
Loading…
Reference in a new issue