Skip to content

Commit

Permalink
update writePingMsg logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mo3et committed Jul 10, 2024
1 parent 32457ab commit b454aac
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion internal/msggateway/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func (c *Client) activeHeartbeat(ctx context.Context) {
for {
select {
case <-ticker.C:
if err := c.conn.WriteMessage(PingMessage, nil); err != nil {
if err := c.writePingMsg(); err != nil {
log.ZError(c.ctx, "send Ping Message error.", err)
return
}
Expand All @@ -358,6 +358,21 @@ func (c *Client) activeHeartbeat(ctx context.Context) {
}()
}
}
func (c *Client) writePingMsg() error {
if c.closed.Load() {
return nil
}

c.w.Lock()
defer c.w.Unlock()

err := c.conn.SetWriteDeadline(writeWait)
if err != nil {
return err
}

return c.conn.WriteMessage(PingMessage, nil)
}

func (c *Client) writePongMsg() error {
if c.closed.Load() {
Expand Down

0 comments on commit b454aac

Please sign in to comment.