Port crates to use new XSO-based xmlstream
This commit is contained in:
parent
7cfda820a6
commit
ab10e30ac0
26 changed files with 623 additions and 973 deletions
|
|
@ -1,46 +1,53 @@
|
|||
use futures::stream::StreamExt;
|
||||
use tokio::io::{AsyncRead, AsyncWrite};
|
||||
use std::io;
|
||||
|
||||
use futures::{SinkExt, StreamExt};
|
||||
use tokio::io::{AsyncBufRead, AsyncWrite};
|
||||
use xmpp_parsers::bind::{BindQuery, BindResponse};
|
||||
use xmpp_parsers::iq::{Iq, IqType};
|
||||
use xmpp_parsers::stream_features::StreamFeatures;
|
||||
|
||||
use crate::error::{Error, ProtocolError};
|
||||
use crate::proto::{Packet, XmppStream};
|
||||
use crate::jid::{FullJid, Jid};
|
||||
use crate::xmlstream::{ReadError, XmppStream, XmppStreamElement};
|
||||
|
||||
const BIND_REQ_ID: &str = "resource-bind";
|
||||
|
||||
pub async fn bind<S: AsyncRead + AsyncWrite + Unpin>(
|
||||
mut stream: XmppStream<S>,
|
||||
) -> Result<XmppStream<S>, Error> {
|
||||
if stream.stream_features.can_bind() {
|
||||
let resource = stream
|
||||
.jid
|
||||
pub async fn bind<S: AsyncBufRead + AsyncWrite + Unpin>(
|
||||
stream: &mut XmppStream<S>,
|
||||
features: &StreamFeatures,
|
||||
jid: &Jid,
|
||||
) -> Result<Option<FullJid>, Error> {
|
||||
if features.can_bind() {
|
||||
let resource = jid
|
||||
.resource()
|
||||
.and_then(|resource| Some(resource.to_string()));
|
||||
let iq = Iq::from_set(BIND_REQ_ID, BindQuery::new(resource));
|
||||
stream.send_stanza(iq).await?;
|
||||
stream.send(&XmppStreamElement::Iq(iq)).await?;
|
||||
|
||||
loop {
|
||||
match stream.next().await {
|
||||
Some(Ok(Packet::Stanza(stanza))) => match Iq::try_from(stanza) {
|
||||
Ok(iq) if iq.id == BIND_REQ_ID => match iq.payload {
|
||||
IqType::Result(payload) => {
|
||||
payload
|
||||
.and_then(|payload| BindResponse::try_from(payload).ok())
|
||||
.map(|bind| stream.jid = bind.into());
|
||||
return Ok(stream);
|
||||
Some(Ok(XmppStreamElement::Iq(iq))) if iq.id == BIND_REQ_ID => match iq.payload {
|
||||
IqType::Result(Some(payload)) => match BindResponse::try_from(payload) {
|
||||
Ok(v) => {
|
||||
return Ok(Some(v.into()));
|
||||
}
|
||||
_ => return Err(ProtocolError::InvalidBindResponse.into()),
|
||||
Err(_) => return Err(ProtocolError::InvalidBindResponse.into()),
|
||||
},
|
||||
_ => {}
|
||||
_ => return Err(ProtocolError::InvalidBindResponse.into()),
|
||||
},
|
||||
Some(Ok(_)) => {}
|
||||
Some(Err(e)) => return Err(e),
|
||||
None => return Err(Error::Disconnected),
|
||||
Some(Err(ReadError::SoftTimeout)) => {}
|
||||
Some(Err(ReadError::HardError(e))) => return Err(e.into()),
|
||||
Some(Err(ReadError::ParseError(e))) => {
|
||||
return Err(io::Error::new(io::ErrorKind::InvalidData, e).into())
|
||||
}
|
||||
Some(Err(ReadError::StreamFooterReceived)) | None => {
|
||||
return Err(Error::Disconnected)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// No resource binding available,
|
||||
// return the (probably // usable) stream immediately
|
||||
return Ok(stream);
|
||||
// No resource binding available, do nothing.
|
||||
return Ok(None);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,32 @@
|
|||
use futures::stream::StreamExt;
|
||||
use futures::{SinkExt, StreamExt};
|
||||
use sasl::client::mechanisms::{Anonymous, Plain, Scram};
|
||||
use sasl::client::Mechanism;
|
||||
use sasl::common::scram::{Sha1, Sha256};
|
||||
use sasl::common::Credentials;
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashSet;
|
||||
use std::io;
|
||||
use std::str::FromStr;
|
||||
use tokio::io::{AsyncRead, AsyncWrite};
|
||||
use xmpp_parsers::sasl::{Auth, Challenge, Failure, Mechanism as XMPPMechanism, Response, Success};
|
||||
use xmpp_parsers::{jid::Jid, ns};
|
||||
use tokio::io::{AsyncBufRead, AsyncWrite};
|
||||
use xmpp_parsers::{
|
||||
jid::{FullJid, Jid},
|
||||
ns,
|
||||
sasl::{Auth, Mechanism as XMPPMechanism, Nonza, Response},
|
||||
stream_features::{SaslMechanisms, StreamFeatures},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
client::bind::bind,
|
||||
connect::ServerConnector,
|
||||
error::{AuthError, Error, ProtocolError},
|
||||
proto::{Packet, XmppStream},
|
||||
xmlstream::{xmpp::XmppStreamElement, InitiatingStream, ReadError, StreamHeader, XmppStream},
|
||||
};
|
||||
|
||||
pub async fn auth<S: AsyncRead + AsyncWrite + Unpin>(
|
||||
pub async fn auth<S: AsyncBufRead + AsyncWrite + Unpin>(
|
||||
mut stream: XmppStream<S>,
|
||||
sasl_mechanisms: &SaslMechanisms,
|
||||
creds: Credentials,
|
||||
) -> Result<S, Error> {
|
||||
) -> Result<InitiatingStream<S>, Error> {
|
||||
let local_mechs: Vec<Box<dyn Fn() -> Box<dyn Mechanism + Send + Sync> + Send>> = vec![
|
||||
Box::new(|| Box::new(Scram::<Sha256>::from_credentials(creds.clone()).unwrap())),
|
||||
Box::new(|| Box::new(Scram::<Sha1>::from_credentials(creds.clone()).unwrap())),
|
||||
|
|
@ -27,13 +34,7 @@ pub async fn auth<S: AsyncRead + AsyncWrite + Unpin>(
|
|||
Box::new(|| Box::new(Anonymous::new())),
|
||||
];
|
||||
|
||||
let remote_mechs: HashSet<String> = stream
|
||||
.stream_features
|
||||
.sasl_mechanisms
|
||||
.mechanisms
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect();
|
||||
let remote_mechs: HashSet<String> = sasl_mechanisms.mechanisms.iter().cloned().collect();
|
||||
|
||||
for local_mech in local_mechs {
|
||||
let mut mechanism = local_mech();
|
||||
|
|
@ -43,43 +44,55 @@ pub async fn auth<S: AsyncRead + AsyncWrite + Unpin>(
|
|||
XMPPMechanism::from_str(mechanism.name()).map_err(ProtocolError::Parsers)?;
|
||||
|
||||
stream
|
||||
.send_stanza(Auth {
|
||||
.send(&XmppStreamElement::Sasl(Nonza::Auth(Auth {
|
||||
mechanism: mechanism_name,
|
||||
data: initial,
|
||||
})
|
||||
})))
|
||||
.await?;
|
||||
|
||||
loop {
|
||||
match stream.next().await {
|
||||
Some(Ok(Packet::Stanza(stanza))) => {
|
||||
if let Ok(challenge) = Challenge::try_from(stanza.clone()) {
|
||||
Some(Ok(XmppStreamElement::Sasl(sasl))) => match sasl {
|
||||
Nonza::Challenge(challenge) => {
|
||||
let response = mechanism
|
||||
.response(&challenge.data)
|
||||
.map_err(|e| AuthError::Sasl(e))?;
|
||||
|
||||
// Send response and loop
|
||||
stream.send_stanza(Response { data: response }).await?;
|
||||
} else if let Ok(_) = Success::try_from(stanza.clone()) {
|
||||
return Ok(stream.into_inner());
|
||||
} else if let Ok(failure) = Failure::try_from(stanza.clone()) {
|
||||
return Err(Error::Auth(AuthError::Fail(failure.defined_condition)));
|
||||
// TODO: This code was needed for compatibility with some broken server,
|
||||
// but it’s been forgotten which. It is currently commented out so that we
|
||||
// can find it and fix the server software instead.
|
||||
/*
|
||||
} else if stanza.name() == "failure" {
|
||||
// Workaround for https://gitlab.com/xmpp-rs/xmpp-parsers/merge_requests/1
|
||||
return Err(Error::Auth(AuthError::Sasl("failure".to_string())));
|
||||
*/
|
||||
} else {
|
||||
// ignore and loop
|
||||
stream
|
||||
.send(&XmppStreamElement::Sasl(Nonza::Response(Response {
|
||||
data: response,
|
||||
})))
|
||||
.await?;
|
||||
}
|
||||
Nonza::Success(_) => return Ok(stream.initiate_reset()),
|
||||
Nonza::Failure(failure) => {
|
||||
return Err(Error::Auth(AuthError::Fail(failure.defined_condition)));
|
||||
}
|
||||
_ => {
|
||||
// Ignore?!
|
||||
}
|
||||
},
|
||||
Some(Ok(el)) => {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::InvalidData,
|
||||
format!(
|
||||
"unexpected stream element during SASL negotiation: {:?}",
|
||||
el
|
||||
),
|
||||
)
|
||||
.into())
|
||||
}
|
||||
Some(Ok(_)) => {
|
||||
// ignore and loop
|
||||
Some(Err(ReadError::HardError(e))) => return Err(e.into()),
|
||||
Some(Err(ReadError::ParseError(e))) => {
|
||||
return Err(io::Error::new(io::ErrorKind::InvalidData, e).into())
|
||||
}
|
||||
Some(Err(ReadError::SoftTimeout)) => {
|
||||
// We cannot do anything about soft timeouts here...
|
||||
}
|
||||
Some(Err(ReadError::StreamFooterReceived)) | None => {
|
||||
return Err(Error::Disconnected)
|
||||
}
|
||||
Some(Err(e)) => return Err(e),
|
||||
None => return Err(Error::Disconnected),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -94,24 +107,31 @@ pub async fn client_login<C: ServerConnector>(
|
|||
server: C,
|
||||
jid: Jid,
|
||||
password: String,
|
||||
) -> Result<XmppStream<C::Stream>, Error> {
|
||||
) -> Result<(Option<FullJid>, StreamFeatures, XmppStream<C::Stream>), Error> {
|
||||
let username = jid.node().unwrap().as_str();
|
||||
let password = password;
|
||||
|
||||
let xmpp_stream = server.connect(&jid, ns::JABBER_CLIENT).await?;
|
||||
let (features, xmpp_stream) = xmpp_stream.recv_features().await?;
|
||||
|
||||
let channel_binding = C::channel_binding(xmpp_stream.stream.get_ref())?;
|
||||
let channel_binding = C::channel_binding(xmpp_stream.get_stream())?;
|
||||
|
||||
let creds = Credentials::default()
|
||||
.with_username(username)
|
||||
.with_password(password)
|
||||
.with_channel_binding(channel_binding);
|
||||
// Authenticated (unspecified) stream
|
||||
let stream = auth(xmpp_stream, creds).await?;
|
||||
// Authenticated XmppStream
|
||||
let xmpp_stream = XmppStream::start(stream, jid, ns::JABBER_CLIENT.to_owned()).await?;
|
||||
let stream = auth(xmpp_stream, &features.sasl_mechanisms, creds).await?;
|
||||
let stream = stream
|
||||
.send_header(StreamHeader {
|
||||
to: Some(Cow::Borrowed(jid.domain().as_str())),
|
||||
from: None,
|
||||
id: None,
|
||||
})
|
||||
.await?;
|
||||
let (features, mut stream) = stream.recv_features().await?;
|
||||
|
||||
// XmppStream bound to user session
|
||||
let xmpp_stream = bind(xmpp_stream).await?;
|
||||
Ok(xmpp_stream)
|
||||
let full_jid = bind(&mut stream, &features, &jid).await?;
|
||||
Ok((full_jid, features, stream))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
use futures::sink::SinkExt;
|
||||
use minidom::Element;
|
||||
use xmpp_parsers::{jid::Jid, ns, stream_features::StreamFeatures};
|
||||
use xmpp_parsers::{jid::Jid, stream_features::StreamFeatures};
|
||||
|
||||
use crate::{
|
||||
client::{login::client_login, stream::ClientState},
|
||||
connect::ServerConnector,
|
||||
error::Error,
|
||||
proto::{add_stanza_id, Packet},
|
||||
Stanza,
|
||||
};
|
||||
|
||||
#[cfg(any(feature = "starttls", feature = "insecure-tcp"))]
|
||||
|
|
@ -47,21 +46,21 @@ impl<C: ServerConnector> Client<C> {
|
|||
/// server).
|
||||
pub fn bound_jid(&self) -> Option<&Jid> {
|
||||
match self.state {
|
||||
ClientState::Connected(ref stream) => Some(&stream.jid),
|
||||
ClientState::Connected { ref bound_jid, .. } => Some(bound_jid),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Send stanza
|
||||
pub async fn send_stanza(&mut self, stanza: Element) -> Result<(), Error> {
|
||||
self.send(Packet::Stanza(add_stanza_id(stanza, ns::JABBER_CLIENT)))
|
||||
.await
|
||||
pub async fn send_stanza(&mut self, mut stanza: Stanza) -> Result<(), Error> {
|
||||
stanza.ensure_id();
|
||||
self.send(stanza).await
|
||||
}
|
||||
|
||||
/// Get the stream features (`<stream:features/>`) of the underlying stream
|
||||
pub fn get_stream_features(&self) -> Option<&StreamFeatures> {
|
||||
match self.state {
|
||||
ClientState::Connected(ref stream) => Some(&stream.stream_features),
|
||||
ClientState::Connected { ref features, .. } => Some(features),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
@ -73,7 +72,14 @@ impl<C: ServerConnector> Client<C> {
|
|||
///
|
||||
/// Make sure to disable reconnect.
|
||||
pub async fn send_end(&mut self) -> Result<(), Error> {
|
||||
self.send(Packet::StreamEnd).await
|
||||
match self.state {
|
||||
ClientState::Connected { ref mut stream, .. } => Ok(stream.close().await?),
|
||||
ClientState::Connecting { .. } => {
|
||||
self.state = ClientState::Disconnected;
|
||||
Ok(())
|
||||
}
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +1,31 @@
|
|||
use futures::{task::Poll, Future, Sink, Stream};
|
||||
use std::io;
|
||||
use std::mem::replace;
|
||||
use std::pin::Pin;
|
||||
use std::task::Context;
|
||||
use tokio::task::JoinHandle;
|
||||
use xmpp_parsers::{
|
||||
jid::{FullJid, Jid},
|
||||
stream_features::StreamFeatures,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
client::login::client_login,
|
||||
client::{login::client_login, Client},
|
||||
connect::{AsyncReadAndWrite, ServerConnector},
|
||||
error::{Error, ProtocolError},
|
||||
proto::{Packet, XmppStream},
|
||||
Client, Event,
|
||||
error::Error,
|
||||
xmlstream::{xmpp::XmppStreamElement, ReadError, XmppStream},
|
||||
Event, Stanza,
|
||||
};
|
||||
|
||||
pub(crate) enum ClientState<S: AsyncReadAndWrite> {
|
||||
Invalid,
|
||||
Disconnected,
|
||||
Connecting(JoinHandle<Result<XmppStream<S>, Error>>),
|
||||
Connected(XmppStream<S>),
|
||||
Connecting(JoinHandle<Result<(Option<FullJid>, StreamFeatures, XmppStream<S>), Error>>),
|
||||
Connected {
|
||||
stream: XmppStream<S>,
|
||||
features: StreamFeatures,
|
||||
bound_jid: Jid,
|
||||
},
|
||||
}
|
||||
|
||||
/// Incoming XMPP events
|
||||
|
|
@ -56,9 +65,13 @@ impl<C: ServerConnector> Stream for Client<C> {
|
|||
Poll::Ready(None)
|
||||
}
|
||||
ClientState::Connecting(mut connect) => match Pin::new(&mut connect).poll(cx) {
|
||||
Poll::Ready(Ok(Ok(stream))) => {
|
||||
let bound_jid = stream.jid.clone();
|
||||
self.state = ClientState::Connected(stream);
|
||||
Poll::Ready(Ok(Ok((bound_jid, features, stream)))) => {
|
||||
let bound_jid = bound_jid.map(Jid::from).unwrap_or_else(|| self.jid.clone());
|
||||
self.state = ClientState::Connected {
|
||||
stream,
|
||||
bound_jid: bound_jid.clone(),
|
||||
features,
|
||||
};
|
||||
Poll::Ready(Some(Event::Online {
|
||||
bound_jid,
|
||||
resumed: false,
|
||||
|
|
@ -77,7 +90,11 @@ impl<C: ServerConnector> Stream for Client<C> {
|
|||
Poll::Pending
|
||||
}
|
||||
},
|
||||
ClientState::Connected(mut stream) => {
|
||||
ClientState::Connected {
|
||||
mut stream,
|
||||
features,
|
||||
bound_jid,
|
||||
} => {
|
||||
// Poll sink
|
||||
match Pin::new(&mut stream).poll_ready(cx) {
|
||||
Poll::Pending => (),
|
||||
|
|
@ -99,40 +116,69 @@ impl<C: ServerConnector> Stream for Client<C> {
|
|||
// return.
|
||||
loop {
|
||||
match Pin::new(&mut stream).poll_next(cx) {
|
||||
Poll::Ready(None) => {
|
||||
Poll::Ready(None)
|
||||
| Poll::Ready(Some(Err(ReadError::StreamFooterReceived))) => {
|
||||
// EOF
|
||||
self.state = ClientState::Disconnected;
|
||||
return Poll::Ready(Some(Event::Disconnected(Error::Disconnected)));
|
||||
}
|
||||
Poll::Ready(Some(Ok(Packet::Stanza(stanza)))) => {
|
||||
// Receive stanza
|
||||
self.state = ClientState::Connected(stream);
|
||||
return Poll::Ready(Some(Event::Stanza(stanza)));
|
||||
Poll::Ready(Some(Err(ReadError::HardError(e)))) => {
|
||||
// Treat stream as dead on I/O errors
|
||||
self.state = ClientState::Disconnected;
|
||||
return Poll::Ready(Some(Event::Disconnected(e.into())));
|
||||
}
|
||||
Poll::Ready(Some(Ok(Packet::Text(_)))) => {
|
||||
// Ignore text between stanzas
|
||||
}
|
||||
Poll::Ready(Some(Ok(Packet::StreamStart(_)))) => {
|
||||
// <stream:stream>
|
||||
Poll::Ready(Some(Err(ReadError::ParseError(e)))) => {
|
||||
// Treat stream as dead on parse errors, too (for now...)
|
||||
self.state = ClientState::Disconnected;
|
||||
return Poll::Ready(Some(Event::Disconnected(
|
||||
ProtocolError::InvalidStreamStart.into(),
|
||||
io::Error::new(io::ErrorKind::InvalidData, e).into(),
|
||||
)));
|
||||
}
|
||||
Poll::Ready(Some(Ok(Packet::StreamEnd))) => {
|
||||
// End of stream: </stream:stream>
|
||||
self.state = ClientState::Disconnected;
|
||||
return Poll::Ready(Some(Event::Disconnected(Error::Disconnected)));
|
||||
Poll::Ready(Some(Err(ReadError::SoftTimeout))) => {
|
||||
// TODO: do something smart about this.
|
||||
}
|
||||
Poll::Ready(Some(Ok(XmppStreamElement::Iq(stanza)))) => {
|
||||
// Receive stanza
|
||||
self.state = ClientState::Connected {
|
||||
stream,
|
||||
features,
|
||||
bound_jid,
|
||||
};
|
||||
// TODO: use specific stanza types instead of going back to elements...
|
||||
return Poll::Ready(Some(Event::Stanza(stanza.into())));
|
||||
}
|
||||
Poll::Ready(Some(Ok(XmppStreamElement::Message(stanza)))) => {
|
||||
// Receive stanza
|
||||
self.state = ClientState::Connected {
|
||||
stream,
|
||||
features,
|
||||
bound_jid,
|
||||
};
|
||||
// TODO: use specific stanza types instead of going back to elements...
|
||||
return Poll::Ready(Some(Event::Stanza(stanza.into())));
|
||||
}
|
||||
Poll::Ready(Some(Ok(XmppStreamElement::Presence(stanza)))) => {
|
||||
// Receive stanza
|
||||
self.state = ClientState::Connected {
|
||||
stream,
|
||||
features,
|
||||
bound_jid,
|
||||
};
|
||||
// TODO: use specific stanza types instead of going back to elements...
|
||||
return Poll::Ready(Some(Event::Stanza(stanza.into())));
|
||||
}
|
||||
Poll::Ready(Some(Ok(_))) => {
|
||||
// We ignore these for now.
|
||||
}
|
||||
Poll::Pending => {
|
||||
// Try again later
|
||||
self.state = ClientState::Connected(stream);
|
||||
self.state = ClientState::Connected {
|
||||
stream,
|
||||
features,
|
||||
bound_jid,
|
||||
};
|
||||
return Poll::Pending;
|
||||
}
|
||||
Poll::Ready(Some(Err(e))) => {
|
||||
self.state = ClientState::Disconnected;
|
||||
return Poll::Ready(Some(Event::Disconnected(e.into())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -143,21 +189,21 @@ impl<C: ServerConnector> Stream for Client<C> {
|
|||
/// Outgoing XMPP packets
|
||||
///
|
||||
/// See `send_stanza()` for an `async fn`
|
||||
impl<C: ServerConnector> Sink<Packet> for Client<C> {
|
||||
impl<C: ServerConnector> Sink<Stanza> for Client<C> {
|
||||
type Error = Error;
|
||||
|
||||
fn start_send(mut self: Pin<&mut Self>, item: Packet) -> Result<(), Self::Error> {
|
||||
fn start_send(mut self: Pin<&mut Self>, item: Stanza) -> Result<(), Self::Error> {
|
||||
match self.state {
|
||||
ClientState::Connected(ref mut stream) => {
|
||||
Pin::new(stream).start_send(item).map_err(|e| e.into())
|
||||
}
|
||||
ClientState::Connected { ref mut stream, .. } => Pin::new(stream)
|
||||
.start_send(&item.into())
|
||||
.map_err(|e| e.into()),
|
||||
_ => Err(Error::InvalidState),
|
||||
}
|
||||
}
|
||||
|
||||
fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
|
||||
match self.state {
|
||||
ClientState::Connected(ref mut stream) => {
|
||||
ClientState::Connected { ref mut stream, .. } => {
|
||||
Pin::new(stream).poll_ready(cx).map_err(|e| e.into())
|
||||
}
|
||||
_ => Poll::Pending,
|
||||
|
|
@ -166,7 +212,7 @@ impl<C: ServerConnector> Sink<Packet> for Client<C> {
|
|||
|
||||
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
|
||||
match self.state {
|
||||
ClientState::Connected(ref mut stream) => {
|
||||
ClientState::Connected { ref mut stream, .. } => {
|
||||
Pin::new(stream).poll_flush(cx).map_err(|e| e.into())
|
||||
}
|
||||
_ => Poll::Pending,
|
||||
|
|
@ -175,7 +221,7 @@ impl<C: ServerConnector> Sink<Packet> for Client<C> {
|
|||
|
||||
fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
|
||||
match self.state {
|
||||
ClientState::Connected(ref mut stream) => {
|
||||
ClientState::Connected { ref mut stream, .. } => {
|
||||
Pin::new(stream).poll_close(cx).map_err(|e| e.into())
|
||||
}
|
||||
_ => Poll::Pending,
|
||||
|
|
|
|||
Loading…
Reference in a new issue