AsyncClient::new reconnects by default, fixes disconnect logic

This commit is contained in:
xmppftw xmppftw 2024-08-08 14:57:05 +02:00
commit 2fc8e1c1dd
2 changed files with 7 additions and 3 deletions

View file

@ -11,6 +11,8 @@ XXXX-YY-ZZ RELEASER <admin@example.com>
where Connection variant contains any error type that implements connect::ServerConnectorError (!421) where Connection variant contains any error type that implements connect::ServerConnectorError (!421)
- `starttls::Error` no longer has `TokioXMPP` variant ; only tokio_xmpp::Error can contain starttls::Error, - `starttls::Error` no longer has `TokioXMPP` variant ; only tokio_xmpp::Error can contain starttls::Error,
not the other way around (!421) not the other way around (!421)
- `AsyncClient::new` automatically reconnects by default (!436)
- `AsyncClient::poll_next` properly closes stream with `Poll::Ready(None)` when disconnecting without auto reconnect (!436)
Version 4.0.0: Version 4.0.0:
2024-07-26 Maxime “pep” Buquet <pep@bouah.net> 2024-07-26 Maxime “pep” Buquet <pep@bouah.net>

View file

@ -47,7 +47,7 @@ enum ClientState<S: AsyncReadAndWrite> {
} }
impl Client<ServerConfig> { impl Client<ServerConfig> {
/// Start a new XMPP client using StartTLS transport /// Start a new XMPP client using StartTLS transport and autoreconnect
/// ///
/// Start polling the returned instance so that it will connect /// Start polling the returned instance so that it will connect
/// and yield events. /// and yield events.
@ -58,7 +58,9 @@ impl Client<ServerConfig> {
password: password.into(), password: password.into(),
server: ServerConfig::UseSrv, server: ServerConfig::UseSrv,
}; };
Self::new_with_config(config) let mut client = Self::new_with_config(config);
client.set_reconnect(true);
client
} }
} }
@ -153,7 +155,7 @@ impl<C: ServerConnector> Stream for Client<C> {
} }
ClientState::Disconnected => { ClientState::Disconnected => {
self.state = ClientState::Disconnected; self.state = ClientState::Disconnected;
Poll::Pending Poll::Ready(None)
} }
ClientState::Connecting(mut connect) => match Pin::new(&mut connect).poll(cx) { ClientState::Connecting(mut connect) => match Pin::new(&mut connect).poll(cx) {
Poll::Ready(Ok(Ok(stream))) => { Poll::Ready(Ok(Ok(stream))) => {