Skip to content

Commit

Permalink
skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Dec 20, 2019
1 parent 13db45e commit a48acb8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
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

0 comments on commit a48acb8

Please sign in to comment.