rpc: fix errcheck warnings in websocket code
This commit is contained in:
parent
e9cefc4bfc
commit
a44376903a
2 changed files with 24 additions and 11 deletions
|
@ -114,12 +114,15 @@ func (c *WSClient) Close() {
|
|||
|
||||
func (c *WSClient) wsReader() {
|
||||
c.ws.SetReadLimit(wsReadLimit)
|
||||
c.ws.SetPongHandler(func(string) error { c.ws.SetReadDeadline(time.Now().Add(wsPongLimit)); return nil })
|
||||
c.ws.SetPongHandler(func(string) error { return c.ws.SetReadDeadline(time.Now().Add(wsPongLimit)) })
|
||||
readloop:
|
||||
for {
|
||||
rr := new(requestResponse)
|
||||
c.ws.SetReadDeadline(time.Now().Add(wsPongLimit))
|
||||
err := c.ws.ReadJSON(rr)
|
||||
err := c.ws.SetReadDeadline(time.Now().Add(wsPongLimit))
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
err = c.ws.ReadJSON(rr)
|
||||
if err != nil {
|
||||
// Timeout/connection loss/malformed response.
|
||||
break
|
||||
|
@ -191,12 +194,16 @@ func (c *WSClient) wsWriter() {
|
|||
if !ok {
|
||||
return
|
||||
}
|
||||
c.ws.SetWriteDeadline(time.Now().Add(c.opts.RequestTimeout))
|
||||
if err := c.ws.SetWriteDeadline(time.Now().Add(c.opts.RequestTimeout)); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.ws.WriteJSON(req); err != nil {
|
||||
return
|
||||
}
|
||||
case <-pingTicker.C:
|
||||
c.ws.SetWriteDeadline(time.Now().Add(wsWriteLimit))
|
||||
if err := c.ws.SetWriteDeadline(time.Now().Add(wsWriteLimit)); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.ws.WriteMessage(websocket.PingMessage, []byte{}); err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -359,7 +359,9 @@ eventloop:
|
|||
if !ok {
|
||||
break eventloop
|
||||
}
|
||||
ws.SetWriteDeadline(time.Now().Add(wsWriteLimit))
|
||||
if err := ws.SetWriteDeadline(time.Now().Add(wsWriteLimit)); err != nil {
|
||||
break eventloop
|
||||
}
|
||||
if err := ws.WritePreparedMessage(event); err != nil {
|
||||
break eventloop
|
||||
}
|
||||
|
@ -367,12 +369,16 @@ eventloop:
|
|||
if !ok {
|
||||
break eventloop
|
||||
}
|
||||
ws.SetWriteDeadline(time.Now().Add(wsWriteLimit))
|
||||
if err := ws.SetWriteDeadline(time.Now().Add(wsWriteLimit)); err != nil {
|
||||
break eventloop
|
||||
}
|
||||
if err := ws.WriteJSON(res); err != nil {
|
||||
break eventloop
|
||||
}
|
||||
case <-pingTicker.C:
|
||||
ws.SetWriteDeadline(time.Now().Add(wsWriteLimit))
|
||||
if err := ws.SetWriteDeadline(time.Now().Add(wsWriteLimit)); err != nil {
|
||||
break eventloop
|
||||
}
|
||||
if err := ws.WriteMessage(websocket.PingMessage, []byte{}); err != nil {
|
||||
break eventloop
|
||||
}
|
||||
|
@ -397,10 +403,10 @@ drainloop:
|
|||
|
||||
func (s *Server) handleWsReads(ws *websocket.Conn, resChan chan<- response.AbstractResult, subscr *subscriber) {
|
||||
ws.SetReadLimit(wsReadLimit)
|
||||
ws.SetReadDeadline(time.Now().Add(wsPongLimit))
|
||||
ws.SetPongHandler(func(string) error { ws.SetReadDeadline(time.Now().Add(wsPongLimit)); return nil })
|
||||
err := ws.SetReadDeadline(time.Now().Add(wsPongLimit))
|
||||
ws.SetPongHandler(func(string) error { return ws.SetReadDeadline(time.Now().Add(wsPongLimit)) })
|
||||
requestloop:
|
||||
for {
|
||||
for err == nil {
|
||||
req := request.NewRequest()
|
||||
err := ws.ReadJSON(req)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue