async_std_openssl/
tls_stream_wrapper.rs1use async_dup::{Arc, Mutex};
4use async_std::io::{Read, Result, Write};
5use async_std::net::TcpStream;
6use std::pin::Pin;
7use std::task::{Context, Poll};
8
9use crate::SslStream;
10
11#[derive(Clone)]
19pub struct SslStreamWrapper(Arc<Mutex<SslStream<TcpStream>>>);
20
21impl SslStreamWrapper {
22 pub fn new(stream: SslStream<TcpStream>) -> Self {
24 Self(Arc::new(Mutex::new(stream)))
25 }
26}
27
28impl Read for SslStreamWrapper {
29 fn poll_read(
30 self: Pin<&mut Self>,
31 cx: &mut Context<'_>,
32 buf: &mut [u8],
33 ) -> Poll<Result<usize>> {
34 Pin::new(&mut &*self.0).poll_read(cx, buf)
35 }
36}
37
38impl Write for SslStreamWrapper {
39 fn poll_write(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll<Result<usize>> {
40 Pin::new(&mut &*self.0).poll_write(cx, buf)
41 }
42
43 fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>> {
44 Pin::new(&mut &*self.0).poll_flush(cx)
45 }
46
47 fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>> {
48 Pin::new(&mut &*self.0).poll_close(cx)
49 }
50}