From 2fc8e1c1dd19743ad101f67d8284af9f5992f24a Mon Sep 17 00:00:00 2001 From: xmppftw Date: Thu, 8 Aug 2024 14:57:05 +0200 Subject: [PATCH] AsyncClient::new reconnects by default, fixes disconnect logic --- tokio-xmpp/ChangeLog | 2 ++ tokio-xmpp/src/client/async_client.rs | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tokio-xmpp/ChangeLog b/tokio-xmpp/ChangeLog index 756fb223..db1eeefb 100644 --- a/tokio-xmpp/ChangeLog +++ b/tokio-xmpp/ChangeLog @@ -11,6 +11,8 @@ XXXX-YY-ZZ RELEASER 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 diff --git a/tokio-xmpp/src/client/async_client.rs b/tokio-xmpp/src/client/async_client.rs index 10119bfe..38c6ca44 100644 --- a/tokio-xmpp/src/client/async_client.rs +++ b/tokio-xmpp/src/client/async_client.rs @@ -47,7 +47,7 @@ enum ClientState { } impl Client { - /// 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 { 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 Stream for Client { } 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))) => {