use super::*;
impl Transport for DuplexTransport {
fn peer_addr(&self) -> Result<SocketAddr, io::Error> {
self.get_remote()
.ok_or_else(|| io::Error::new(io::ErrorKind::Unsupported, NO_ADDRESS))
}
fn local_addr(&self) -> Result<SocketAddr, io::Error> {
self.get_local()
.ok_or_else(|| io::Error::new(io::ErrorKind::Unsupported, NO_ADDRESS))
}
}
impl AsyncRead for DuplexTransport {
fn poll_read(
self: Pin<&mut Self>,
_context: &mut task::Context<'_>,
buffer: &mut ReadBuf<'_>,
) -> Poll<io::Result<()>> {
buffer.advance(0);
Poll::Ready(Ok(()))
}
}
impl AsyncWrite for DuplexTransport {
fn poll_write(
self: Pin<&mut Self>,
context: &mut task::Context<'_>,
bytes: &[u8],
) -> Poll<io::Result<usize>> {
let this: &mut Self = self.get_mut();
Pin::new(&mut this.get_mut_pipe()).poll_write(context, bytes)
}
fn poll_flush(self: Pin<&mut Self>, context: &mut task::Context<'_>) -> Poll<io::Result<()>> {
let this: &mut Self = self.get_mut();
Pin::new(&mut this.get_mut_pipe()).poll_flush(context)
}
fn poll_shutdown(
self: Pin<&mut Self>,
context: &mut task::Context<'_>,
) -> Poll<io::Result<()>> {
let this: &mut Self = self.get_mut();
Pin::new(&mut this.get_mut_pipe()).poll_shutdown(context)
}
}
impl TlsTransport {
pub(crate) fn new(session: tokio_rustls::server::TlsStream<TcpStream>) -> Self {
Self { session }
}
}
impl TlsTransport {
pub(crate) fn get_session_ref(&self) -> &tokio_rustls::server::TlsStream<TcpStream> {
&self.session
}
}
impl Transport for TlsTransport {
fn peer_addr(&self) -> Result<SocketAddr, io::Error> {
TcpStream::peer_addr(self.get_session_ref().get_ref().0)
}
fn local_addr(&self) -> Result<SocketAddr, io::Error> {
TcpStream::local_addr(self.get_session_ref().get_ref().0)
}
}
impl AsyncRead for TlsTransport {
fn poll_read(
self: Pin<&mut Self>,
context: &mut task::Context<'_>,
buffer: &mut ReadBuf<'_>,
) -> Poll<io::Result<()>> {
let this: &mut Self = self.get_mut();
Pin::new(&mut this.get_mut_session()).poll_read(context, buffer)
}
}
impl AsyncWrite for TlsTransport {
fn poll_write(
self: Pin<&mut Self>,
context: &mut task::Context<'_>,
bytes: &[u8],
) -> Poll<io::Result<usize>> {
let this: &mut Self = self.get_mut();
Pin::new(&mut this.get_mut_session()).poll_write(context, bytes)
}
fn poll_flush(self: Pin<&mut Self>, context: &mut task::Context<'_>) -> Poll<io::Result<()>> {
let this: &mut Self = self.get_mut();
Pin::new(&mut this.get_mut_session()).poll_flush(context)
}
fn poll_shutdown(
self: Pin<&mut Self>,
context: &mut task::Context<'_>,
) -> Poll<io::Result<()>> {
let this: &mut Self = self.get_mut();
Pin::new(&mut this.get_mut_session()).poll_shutdown(context)
}
}