Skip to content

Commit

Permalink
Remove logic code for reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
zoujiaqing committed Sep 10, 2024
1 parent ea92ce2 commit 002741f
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions Client.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,32 +219,19 @@ func (c *Client) handleMessage(conn *RpcConnection, data []byte) []byte {
}

func (c *Client) handleConnectionClosed(conn *RpcConnection) {
// 连接关闭时触发重连
for {
select {
case <-c.reconnectCh:
c.connectMu.Lock()
c.connected = false
c.connectMu.Unlock()
return // 收到断开连接信号,停止重连
default:
c.connectMu.Lock()
c.connected = false
c.connectMu.Unlock()

// 停止定时器
c.stopPing()

time.Sleep(c.RetryDelay)

err := c.Connect()
if err == nil {
// 重连成功
return
}
select {
case <-c.reconnectCh:
c.connectMu.Lock()
c.connected = false
c.connectMu.Unlock()
return // 收到断开连接信号,停止重连
default:
c.connectMu.Lock()
c.connected = false
c.connectMu.Unlock()

// 重连失败,继续尝试
}
// 停止定时器
c.stopPing()
}
}

Expand Down

0 comments on commit 002741f

Please sign in to comment.