The entrypoint of Client
(
&mut self,
mut command_rx: mpsc::Receiver<Message>,
result_tx: mpsc::Sender<Message>,
)
| 75 | |
| 76 | // The entrypoint of Client |
| 77 | async fn run( |
| 78 | &mut self, |
| 79 | mut command_rx: mpsc::Receiver<Message>, |
| 80 | result_tx: mpsc::Sender<Message>, |
| 81 | ) -> Result<()> { |
| 82 | let transport = self.transport.clone(); |
| 83 | |
| 84 | let mut retry_backoff = run_control_chan_backoff(DEFAULT_CLIENT_RETRY_INTERVAL_SECS); |
| 85 | |
| 86 | let mut start = Instant::now(); |
| 87 | result_tx |
| 88 | .send(Message::ConnectState(ConnectState::Connecting.into())) |
| 89 | .await |
| 90 | .context("Can't send Connecting event")?; |
| 91 | while let Err(err) = self |
| 92 | .run_control_channel(transport.clone(), &mut command_rx, &result_tx) |
| 93 | .boxed() |
| 94 | .await |
| 95 | { |
| 96 | if result_tx.is_closed() { |
| 97 | // The client is shutting down |
| 98 | break; |
| 99 | } |
| 100 | |
| 101 | if self.connected { |
| 102 | result_tx |
| 103 | .send(Message::Error(ErrorInfo { |
| 104 | kind: ErrorKind::HandshakeFailed.into(), |
| 105 | message: crate::t!("error-network"), |
| 106 | guid: String::new(), |
| 107 | })) |
| 108 | .await |
| 109 | .context("Can't send Error event")?; |
| 110 | result_tx |
| 111 | .send(Message::ConnectState(ConnectState::Disconnected.into())) |
| 112 | .await |
| 113 | .context("Can't send Disconnected event")?; |
| 114 | result_tx |
| 115 | .send(Message::ConnectState(ConnectState::Connecting.into())) |
| 116 | .await |
| 117 | .context("Can't send Connecting event")?; |
| 118 | self.connected = false; |
| 119 | } |
| 120 | |
| 121 | self.services.clear(); |
| 122 | #[cfg(feature = "plugins")] |
| 123 | self.plugin_processes.clear(); |
| 124 | self.data_channels.clear(); |
| 125 | |
| 126 | if start.elapsed() > Duration::from_secs(3) { |
| 127 | // The client runs for at least 3 secs and then disconnects |
| 128 | retry_backoff.reset(); |
| 129 | } |
| 130 | |
| 131 | if let Some(duration) = retry_backoff.next_backoff() { |
| 132 | warn!("{:#}. Retry in {:?}...", err, duration); |
| 133 | time::sleep(duration).await; |
| 134 | } |
no test coverage detected