pub struct Stream<IO, Role, Guard = Direct> { /* private fields */ }Expand description
Websocket stream.
Depending on IO, Stream implements std::io::Read and std::io::Write
or tokio::io::AsyncRead and tokio::io::AsyncWrite.
Role decides whether to mask payload data.
It is reserved to provide extra infomation to apply optimizations.
See also: Stream::read, Stream::write.
Implementations§
Source§impl<IO, Role, Guard> Stream<IO, Role, Guard>where
Role: RoleHelper,
impl<IO, Role, Guard> Stream<IO, Role, Guard>where
Role: RoleHelper,
Source§impl<IO, Role, Guard> Stream<IO, Role, Guard>
Check status.
impl<IO, Role, Guard> Stream<IO, Role, Guard>
Check status.
Sourcepub const fn is_ping_completed(&self) -> bool
pub const fn is_ping_completed(&self) -> bool
Check if a Ping frame is completely read.
Sourcepub const fn is_read_eof(&self) -> bool
pub const fn is_read_eof(&self) -> bool
Check if EOF is reached.
Sourcepub const fn is_read_close(&self) -> bool
pub const fn is_read_close(&self) -> bool
Check if a Close frame is received.
Sourcepub const fn is_read_end(&self) -> bool
pub const fn is_read_end(&self) -> bool
Check if a Close frame is received or EOF is reached.
Sourcepub const fn is_write_zero(&self) -> bool
pub const fn is_write_zero(&self) -> bool
Check if a WriteZero error occurred.
Sourcepub const fn is_read_partial_head(&self) -> bool
pub const fn is_read_partial_head(&self) -> bool
Check if a frame head is partially read.
Sourcepub const fn is_write_partial_head(&self) -> bool
pub const fn is_write_partial_head(&self) -> bool
Check if frame head is partially written.
Source§impl<Role: RoleHelper> Stream<TcpStream, Role>
impl<Role: RoleHelper> Stream<TcpStream, Role>
Trait Implementations§
Source§impl<IO, Role> AsyncWrite for Stream<IO, Role>
impl<IO, Role> AsyncWrite for Stream<IO, Role>
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>>
Async version of Stream::write.
Source§fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
This is a no-op since we do not buffer any data.
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<()>>
Shutdown the underlying IO source.
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<IO, Role> AsyncWrite for Stream<IO, Role, Guarded>
impl<IO, Role> AsyncWrite for Stream<IO, Role, Guarded>
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>>
Async version of Stream::write.
Continue to write if frame head is not completely written.
Source§fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
This is a no-op since we do not buffer any data.
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<()>>
Shutdown the underlying IO source.
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<IO: Read, Role: RoleHelper> Read for Stream<IO, Role>
impl<IO: Read, Role: RoleHelper> Read for Stream<IO, Role>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Read some data from the underlying IO source,
returns Ok(0) until a complete frame head is present.
Caller should ensure the available buffer size is larger
than 14 before a read.
Read a control frame(like Ping) returns Ok(0),
which could be detected via Stream::is_pinged.
Any read after receiving a Close frame or reaching EOF
will return Ok(0),
which could be checked via Stream::is_read_end,
Stream::is_read_close, Stream::is_read_eof.
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)Source§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 more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
Source§impl<IO: Read, Role: RoleHelper> Read for Stream<IO, Role, Guarded>
impl<IO: Read, Role: RoleHelper> Read for Stream<IO, Role, Guarded>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Wrap read in a loop. Continue to read if frame head is not complete.
Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
Override default implement, extend reserved buffer size, so that there is enough space to accommodate frame head.
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_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 more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
Source§impl<IO: Write, Role: RoleHelper> Write for Stream<IO, Role>
impl<IO: Write, Role: RoleHelper> Write for Stream<IO, Role>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Write some data to the underlying IO source,
returns Ok(0) until the frame head is completely
written.
if WriteZero occurs, it will also return Ok(0),
which could be detected via Stream::is_write_zero.
Frame head will be generated automatically, according to the length of the provided buffer.
A standard client should mask payload data before sending it.
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
The writer does not buffer any data, simply flush the underlying IO source.
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)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)Source§impl<IO: Write, Role: RoleHelper> Write for Stream<IO, Role, Guarded>
impl<IO: Write, Role: RoleHelper> Write for Stream<IO, Role, Guarded>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Wrap write in a loop. Continue to write if frame head is not completely written.
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
The writer does not buffer any data, simply flush the underlying IO source.
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)