Skip to content

Commit

Permalink
feat: add split for blocking tls stream
Browse files Browse the repository at this point in the history
  • Loading branch information
PrivateRookie committed Nov 22, 2023
1 parent fcf2258 commit f1ffef8
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ mod blocking {
sync::{Arc, Mutex},
};

use crate::codec::Split;

/// reader part of a stream
pub struct ReadHalf<T> {
/// inner stream
Expand Down Expand Up @@ -66,6 +68,32 @@ mod blocking {
try_lock!(self.inner).flush()
}
}

#[cfg(feature = "sync_tls_rustls")]
impl<S: Read + Write> Split for rustls_connector::TlsStream<S> {
type R = ReadHalf<rustls_connector::TlsStream<S>>;

type W = WriteHalf<rustls_connector::TlsStream<S>>;

fn split(self) -> (Self::R, Self::W) {
let inner = Arc::new(Mutex::new(self));
let inner_c = inner.clone();
(ReadHalf { inner }, WriteHalf { inner: inner_c })
}
}

#[cfg(feature = "sync_tls_native")]
impl<S: Read + Write> Split for native_tls::TlsStream<S> {
type R = ReadHalf<native_tls::TlsStream<S>>;

type W = WriteHalf<native_tls::TlsStream<S>>;

fn split(self) -> (Self::R, Self::W) {
let inner = Arc::new(Mutex::new(self));
let inner_c = inner.clone();
(ReadHalf { inner }, WriteHalf { inner: inner_c })
}
}
}

macro_rules! def {
Expand Down

0 comments on commit f1ffef8

Please sign in to comment.