Skip to content

Commit

Permalink
feat: add WriteDeadline
Browse files Browse the repository at this point in the history
  • Loading branch information
wdvxdr1123 committed Dec 26, 2021
1 parent 94ec3cc commit ef22238
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions server/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type wsConn struct {
func (c *wsConn) WriteText(b []byte) error {
c.mu.Lock()
defer c.mu.Unlock()
_ = c.conn.SetWriteDeadline(time.Now().Add(time.Second * 15))
return c.conn.WriteMessage(websocket.TextMessage, b)
}

Expand Down Expand Up @@ -460,6 +461,7 @@ func (c *wsConn) handleRequest(_ *coolq.CQBot, payload []byte) {

c.mu.Lock()
defer c.mu.Unlock()
_ = c.conn.SetWriteDeadline(time.Now().Add(time.Second * 15))
writer, _ := c.conn.NextWriter(websocket.TextMessage)
_ = json.NewEncoder(writer).Encode(ret)
_ = writer.Close()
Expand Down

0 comments on commit ef22238

Please sign in to comment.