pub struct Stream<S: AsFd, C: TlsSession> { /* private fields */ }Expand description
A thin wrapper around a kTLS offloaded socket.
This implements Read and Write,
AsyncRead and
AsyncWrite (when feature async-io-tokio is
enabled).
§Behaviours
Once receives a close_notify alert from the peer, all subsequent read
operations will return EOF (unless the inner buffer contains unread data);
once the caller explicitly calls (poll_)shutdown on the stream, a
close_notify alert would be sent to the peer and all subsequent write
operations will return 0 bytes, indicating that the stream is closed for
writing. When the Stream is dropped, it will also perform graceful
shutdown automatically.
For TLS 1.2, 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 new<K, E>(
socket: S,
secrets: K,
session: C,
buffer: Option<Buffer>,
) -> Result<Self, Error>
pub fn new<K, E>( socket: S, secrets: K, session: C, buffer: Option<Buffer>, ) -> Result<Self, Error>
Constructs a new Stream from the provided socket, extracted TLS
secrets and TLS session context. An optional buffer may be
provided for early data received during handshake.
§Prerequisites
The socket must have TLS ULP configured with setup_ulp.
§Errors
Unsupported protocol version or cipher suite, or failure to set up kTLS params on the socket.
Sourcepub fn as_mut_raw(
&mut self,
) -> Result<RawStreamMut<'_, S, C>, AccessRawStreamError>
pub fn as_mut_raw( &mut self, ) -> Result<RawStreamMut<'_, S, C>, AccessRawStreamError>
Returns a RawStreamMut which provides low-level access to the
inner socket.
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
RawStreamMut::handle_io_error.
-
The caller MAY handle any
io::Errors returned by direct I/O operations on the inner socket withRawStreamMut::handle_io_error. -
The caller MUST NOT shutdown the inner socket directly, which will lead to undefined behaviours.
§Errors
See AccessRawStreamError.
Sourcepub fn refresh_traffic_keys(&mut self) -> Result<(), Error>
pub fn refresh_traffic_keys(&mut self) -> Result<(), Error>
Context::refresh_traffic_keys against the inner socket.
Use with caution, and do check Context::refresh_traffic_keys for
details.
§Errors
Source§impl<S> Stream<S, DummyTlsSession>where
S: AsFd,
impl<S> Stream<S, DummyTlsSession>where
S: AsFd,
Sourcepub fn new_dummy(
socket: S,
secrets: ExtractedSecrets,
session: DummyTlsSession,
buffer: Option<Buffer>,
) -> Result<Self, Error>
pub fn new_dummy( socket: S, secrets: ExtractedSecrets, session: DummyTlsSession, buffer: Option<Buffer>, ) -> Result<Self, Error>
Creates a new Stream with a DummyTlsSession.
This doesn’t require the socket to have TLS ULP configured, we will configure it here.
See also Stream::new.
§Errors
See Stream::new.
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)