AsyncClient::new reconnects by default, fixes disconnect logic

xmppftw created

Change summary

tokio-xmpp/ChangeLog                  | 2 ++
tokio-xmpp/src/client/async_client.rs | 8 +++++---
2 files changed, 7 insertions(+), 3 deletions(-)

Detailed changes

tokio-xmpp/ChangeLog 🔗

@@ -11,6 +11,8 @@ XXXX-YY-ZZ RELEASER <admin@example.com>
         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,
         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:
 2024-07-26 Maxime “pep” Buquet <pep@bouah.net>

tokio-xmpp/src/client/async_client.rs 🔗

@@ -47,7 +47,7 @@ enum ClientState<S: AsyncReadAndWrite> {
 }
 
 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
     /// and yield events.
@@ -58,7 +58,9 @@ impl Client<ServerConfig> {
             password: password.into(),
             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 => {
                 self.state = ClientState::Disconnected;
-                Poll::Pending
+                Poll::Ready(None)
             }
             ClientState::Connecting(mut connect) => match Pin::new(&mut connect).poll(cx) {
                 Poll::Ready(Ok(Ok(stream))) => {