Skip to content

Commit a3f6457

Browse files
committed
acceptor: add accessor methods on TlsStream
1 parent 554de0b commit a3f6457

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/acceptor.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use hyper::server::{
99
accept::Accept,
1010
conn::{AddrIncoming, AddrStream},
1111
};
12-
use rustls::ServerConfig;
12+
use rustls::{ServerConfig, ServerConnection};
1313
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
1414

1515
mod builder;
@@ -77,6 +77,26 @@ impl TlsStream {
7777
state: State::Handshaking(accept),
7878
}
7979
}
80+
81+
/// Returns a reference to the underlying IO stream.
82+
///
83+
/// This should always return `Some`, except if an error has already been yielded.
84+
pub fn io(&self) -> Option<&AddrStream> {
85+
match &self.state {
86+
State::Handshaking(accept) => accept.get_ref(),
87+
State::Streaming(stream) => Some(stream.get_ref().0),
88+
}
89+
}
90+
91+
/// Returns a reference to the underlying [`rustls::ServerConnection'].
92+
///
93+
/// This will start yielding `Some` only after the handshake has completed.
94+
pub fn connection(&self) -> Option<&ServerConnection> {
95+
match &self.state {
96+
State::Handshaking(_) => None,
97+
State::Streaming(stream) => Some(stream.get_ref().1),
98+
}
99+
}
80100
}
81101

82102
impl AsyncRead for TlsStream {

0 commit comments

Comments
 (0)