mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-11-04 03:13:15 +08:00
update writePingMsg logic
This commit is contained in:
parent
32457ab8b5
commit
b454aacd36
@ -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
|
||||
}
|
||||
@ -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() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user