tokio_socks/io/
tokio.rs

1//! AsyncSocket trait implementation for tokio's AsyncRead + AsyncWrite
2//! traits.
3use std::{
4    io::Result as IoResult,
5    pin::Pin,
6    task::{Context, Poll},
7};
8
9use futures_util::ready;
10use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
11
12use super::AsyncSocket;
13
14impl<S> AsyncSocket for S
15where S: AsyncRead + AsyncWrite
16{
17    fn poll_read(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<IoResult<usize>> {
18        let mut buf = ReadBuf::new(buf);
19        ready!(AsyncRead::poll_read(self, cx, &mut buf))?;
20        Poll::Ready(Ok(buf.filled().len()))
21    }
22
23    fn poll_write(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll<IoResult<usize>> {
24        AsyncWrite::poll_write(self, cx, buf)
25    }
26}