run consumes incoming dnode messages. Reconnects if necessary.
()
| 386 | |
| 387 | // run consumes incoming dnode messages. Reconnects if necessary. |
| 388 | func (c *Client) run() { |
| 389 | err := c.readLoop() |
| 390 | if err != nil { |
| 391 | c.LocalKite.Log.Debug("readloop err: %s", err) |
| 392 | } |
| 393 | |
| 394 | // falls here when connection disconnects |
| 395 | c.callOnDisconnectHandlers() |
| 396 | |
| 397 | // let others know that the client has disconnected |
| 398 | c.disconnectMu.Lock() |
| 399 | if c.disconnect != nil { |
| 400 | close(c.disconnect) |
| 401 | c.disconnect = nil |
| 402 | } |
| 403 | c.disconnectMu.Unlock() |
| 404 | |
| 405 | if c.reconnect() { |
| 406 | // we override it so it doesn't get selected next time. Because we are |
| 407 | // redialing, so after redial if a new method is called, the disconnect |
| 408 | // channel is being read and the local "disconnect" message will be the |
| 409 | // final response. This shouldn't be happen for redials. |
| 410 | c.disconnectMu.Lock() |
| 411 | c.disconnect = make(chan struct{}, 1) |
| 412 | c.disconnectMu.Unlock() |
| 413 | go c.dialForever(nil) |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | func (c *Client) reconnect() bool { |
| 418 | c.muReconnect.Lock() |
no test coverage detected