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>
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 moresource§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 moresource§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
)