pub struct Stream<S: AsFd, C: TlsSession> { /* private fields */ }Expand description
A thin wrapper around a socket with kernel TLS (kTLS) offload configured.
This implements traits Read and
Write, AsyncRead and
AsyncWrite (when feature async-io-tokio is
enabled).
§Behaviours
Once a TLS close_notify alert from the peer is received, all subsequent
read operations will return EOF.
Once the caller explicitly calls (poll_)shutdown on the stream, all
subsequent write operations will return 0 bytes, indicating that the
stream is closed for writing.
Once the stream is being dropped, a close_notify alert would be sent to
the peer automatically before shutting down the inner socket, according to
RFC 8446, section 6.1.
The caller may call (poll_)shutdown on the stream to shutdown explicitly
both sides of the stream. Currently, there’s no way provided by this crate
to shutdown the TLS stream write side only. For TLS 1.2, this is ideal since
once one party sends a close_notify alert, the other party MUST respond
with a close_notify alert of its own and close down the connection
immediately, according to RFC 5246, section 7.2.1; for TLS 1.3, both
parties need not wait to receive a “close_notify” alert before
closing their read side of the connection, according to RFC 8446, section
6.1.
Implementations§
Source§impl<S: AsFd, C: TlsSession> Stream<S, C>
impl<S: AsFd, C: TlsSession> Stream<S, C>
Sourcepub fn as_mut_raw(
&mut self,
) -> Result<StreamRefMutRaw<'_, S, C>, AccessRawStreamError>
pub fn as_mut_raw( &mut self, ) -> Result<StreamRefMutRaw<'_, S, C>, AccessRawStreamError>
Returns a mutable reference to the inner socket if the TLS connection is not closed (unidirectionally or bidirectionally).
This requires a mutable reference to the Stream to ensure a
exclusive access to the inner socket.
§Notes
-
All buffered data MUST be properly consumed (See
AccessRawStreamError::HasBufferedData).The buffered data typically consists of:
- Early data received during handshake.
- Application data received due to improper usage of
StreamRefMutRaw::handle_io_error.
-
The caller MAY handle any
io::Results returned by I/O operations on the inner socket withStreamRefMutRaw::handle_io_error. -
The caller MUST NOT shutdown the inner socket directly, which will lead to undefined behaviours. Instead, the caller MAY call
(poll_)shutdownexplictly on theStreamto gracefully shutdown the TLS stream (withclose_notifybe sent) manually, or just drop the stream to do automatic graceful shutdown.
§Errors
See AccessRawStreamError.
Source§impl<S, Data> Stream<S, KernelConnection<Data>>
impl<S, Data> Stream<S, KernelConnection<Data>>
Sourcepub fn from(
socket: S,
secrets: ExtractedSecrets,
session: KernelConnection<Data>,
buffer: Option<Buffer>,
) -> Result<Self, Error>
pub fn from( socket: S, secrets: ExtractedSecrets, session: KernelConnection<Data>, buffer: Option<Buffer>, ) -> Result<Self, Error>
Constructs a new Stream from a socket, TLS secrets, and TLS session
context.
§Overview
This creates a Stream from the provided socket, extracted TLS
secrets (rustls::ExtractedSecrets), and TLS session context
(rustls::kernel::KernelConnection). An optional buffer may be
provided for early data received during handshake.
The secrets and context must be extracted from a
rustls::client::UnbufferedClientConnection or
rustls::client::UnbufferedClientConnection. See rustls::kernel
module documentation for more details.
§Prerequisites
The socket must have TLS ULP configured with
setup_ulp.
§Errors
Returns an error if prerequisites aren’t met or kernel TLS setup fails.
Source§impl<C> Stream<TcpStream, C>where
C: TlsSession,
impl<C> Stream<TcpStream, C>where
C: TlsSession,
Source§impl<C> Stream<UnixStream, C>where
C: TlsSession,
impl<C> Stream<UnixStream, C>where
C: TlsSession,
Trait Implementations§
Source§impl<S, C> AsyncWrite for Stream<S, C>
Available on crate feature async-io-tokio only.
impl<S, C> AsyncWrite for Stream<S, C>
async-io-tokio only.Source§fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<Result<usize>>
fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize>>
buf into the object. Read moreSource§fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
Source§fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
Source§fn poll_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>],
) -> Poll<Result<usize, Error>>
fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize, Error>>
poll_write, except that it writes from a slice of buffers. Read moreSource§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
poll_write_vectored
implementation. Read moreSource§impl<S, C> Read for Stream<S, C>
impl<S, C> Read for Stream<S, C>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read moreSource§impl<S, C> Write for Stream<S, C>
impl<S, C> Write for Stream<S, C>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)