Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: AsyncBufRead #7

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/std_adapter.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::io::{self, Read, Write};
use std::io::{self, BufRead, Read, Write};
use std::marker::Unpin;
use std::pin::Pin;
use std::task::{Context, Poll};

use futures_io::{AsyncRead, AsyncWrite};
use futures_io::{AsyncBufRead, AsyncRead, AsyncWrite};

#[derive(Debug)]
pub(crate) struct StdAdapter<S> {
Expand Down Expand Up @@ -43,6 +43,24 @@ where
}
}

impl<S> BufRead for StdAdapter<S>
where
S: AsyncBufRead + Unpin,
{
fn fill_buf(&mut self) -> io::Result<&[u8]> {
unimplemented!()
// TODO: make it compile
// match self.with_context(|ctx, stream| stream.poll_fill_buf(ctx)) {
// Poll::Ready(buf) => buf,
// Poll::Pending => Err(io::Error::from(io::ErrorKind::WouldBlock)),
// }
}

fn consume(&mut self, amt: usize) {
self.consume(amt)
}
}

impl<S> Write for StdAdapter<S>
where
S: AsyncWrite + Unpin,
Expand Down
17 changes: 15 additions & 2 deletions src/tls_stream.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::io::{self, Read, Write};
use std::io::{self, BufRead, Read, Write};
use std::marker::Unpin;
use std::pin::Pin;
use std::ptr::null_mut;
use std::task::{Context, Poll};

use futures_io::{AsyncRead, AsyncWrite};
use futures_io::{AsyncBufRead, AsyncRead, AsyncWrite};

use crate::std_adapter::StdAdapter;

Expand Down Expand Up @@ -64,6 +64,19 @@ where
}
}

impl<S> AsyncBufRead for TlsStream<S>
where
S: AsyncBufRead + AsyncWrite + Unpin,
{
fn poll_fill_buf(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<&[u8]>> {
self.with_context(cx, |s| cvt(s.fill_buf()))
}

fn consume(self: Pin<&mut Self>, amt: usize) {
self.consume(amt)
}
}

impl<S> AsyncWrite for TlsStream<S>
where
S: AsyncRead + AsyncWrite + Unpin,
Expand Down