update heartbeat logic.

pull/2404/head
Monet Lee 1 year ago
parent afd3421773
commit a91a8b9c8b

@ -90,7 +90,7 @@ func (c *Client) ResetClient(ctx *UserConnContext, conn LongConn, longConnServer
c.closed.Store(false)
c.closedErr = nil
c.token = ctx.GetToken()
c.hbCtx, _ = context.WithTimeout(c.ctx, pongWait*2)
c.hbCtx, _ = context.WithCancel(c.ctx)
}
func (c *Client) pingHandler(_ string) error {
@ -114,10 +114,7 @@ func (c *Client) readMessage() {
c.conn.SetReadLimit(maxMessageSize)
_ = c.conn.SetReadDeadline(pongWait)
c.conn.SetPingHandler(c.pingHandler)
if c.PlatformID == constant.WebPlatformID {
go c.heartbeat(c.hbCtx)
}
for {
log.ZDebug(c.ctx, "readMessage")
@ -331,6 +328,7 @@ func (c *Client) writeBinaryMsg(resp Resp) error {
}
func (c *Client) heartbeat(ctx context.Context) {
if c.PlatformID == constant.WebPlatformID {
log.ZDebug(ctx, "server initiative send heartbeat start.")
ticker := time.NewTicker(pingPeriod)
defer ticker.Stop()
@ -347,6 +345,7 @@ func (c *Client) heartbeat(ctx context.Context) {
}
}
}
}
func (c *Client) writePongMsg() error {
if c.closed.Load() {

Loading…
Cancel
Save