use super::{H2Error, acceptor::H2Driver};
use futures_lite::io::{AsyncRead, AsyncWrite};
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
};
#[must_use = "futures do nothing unless awaited"]
#[derive(Debug)]
pub struct H2Initiator<T> {
driver: H2Driver<T>,
}
impl<T> H2Initiator<T>
where
T: AsyncRead + AsyncWrite + Unpin + Send,
{
pub(super) fn new(driver: H2Driver<T>) -> Self {
Self { driver }
}
}
impl<T> Future for H2Initiator<T>
where
T: AsyncRead + AsyncWrite + Unpin + Send,
{
type Output = Result<(), H2Error>;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
loop {
match self.driver.drive(cx) {
Poll::Ready(None) => return Poll::Ready(Ok(())),
Poll::Ready(Some(Err(e))) => return Poll::Ready(Err(e)),
Poll::Ready(Some(Ok(_conn))) => {
log::error!(
"h2 client driver: unexpected peer-initiated stream — dropping conn"
);
}
Poll::Pending => return Poll::Pending,
}
}
}
}