xmlstream: split initiation reset in two phases
This commit is contained in:
parent
c723897326
commit
2931df22db
3 changed files with 34 additions and 24 deletions
|
|
@ -8,6 +8,8 @@ use core::pin::Pin;
|
|||
use std::borrow::Cow;
|
||||
use std::io;
|
||||
|
||||
use futures::SinkExt;
|
||||
|
||||
use tokio::io::{AsyncBufRead, AsyncWrite};
|
||||
|
||||
use xmpp_parsers::stream_features::StreamFeatures;
|
||||
|
|
@ -19,6 +21,27 @@ use super::{
|
|||
XmlStream,
|
||||
};
|
||||
|
||||
/// Type state for an initiator stream which has not yet sent its stream
|
||||
/// header.
|
||||
///
|
||||
/// To continue stream setup, call [`send_header`][`Self::send_header`].
|
||||
pub struct InitiatingStream<Io>(pub(super) RawXmlStream<Io>);
|
||||
|
||||
impl<Io: AsyncBufRead + AsyncWrite + Unpin> InitiatingStream<Io> {
|
||||
/// Send the stream header.
|
||||
pub async fn send_header(
|
||||
self,
|
||||
header: StreamHeader<'_>,
|
||||
) -> io::Result<PendingFeaturesRecv<Io>> {
|
||||
let Self(mut stream) = self;
|
||||
|
||||
header.send(Pin::new(&mut stream)).await?;
|
||||
stream.flush().await?;
|
||||
let header = StreamHeader::recv(Pin::new(&mut stream)).await?;
|
||||
Ok(PendingFeaturesRecv { stream, header })
|
||||
}
|
||||
}
|
||||
|
||||
/// Type state for an initiator stream which has sent and received the stream
|
||||
/// header.
|
||||
///
|
||||
|
|
|
|||
Loading…
Reference in a new issue