pub struct EndpointWrite<EpType: BulkOrInterrupt> { /* private fields */ }Expand description
Wrapper for a Bulk or Interrupt OUT Endpoint that
manages transfers to provide a higher-level buffered API.
Most of the functionality of this type is provided through standard IO traits; you’ll want to use one of the following:
std::io::Writefor blocking IO.- With the
tokiocargo feature,tokio::io::AsyncWrite. Tokio also providesAsyncWriteExtwith additional methods. - With the
smolcargo feature,futures_io::AsyncWritefor async IO.futures_liteprovidesAsyncWriteExtwith additional methods.
Written data is buffered and may not be sent until the buffer is full or
submit / submit_end or
flush / flush_end are called.
Implementations§
Source§impl<EpType: BulkOrInterrupt> EndpointWrite<EpType>
impl<EpType: BulkOrInterrupt> EndpointWrite<EpType>
Sourcepub fn new(endpoint: Endpoint<EpType, Out>, transfer_size: usize) -> Self
pub fn new(endpoint: Endpoint<EpType, Out>, transfer_size: usize) -> Self
Create a new EndpointWrite wrapping the given endpoint.
The transfer_size parameter is the size of the buffer passed to the OS
for each transfer. It will be rounded up to the next multiple of the
endpoint’s max packet size. Data will be buffered and sent in chunks of
this size, unless flush or submit are
called to force sending a partial buffer immediately.
Sourcepub fn set_num_transfers(&mut self, num_transfers: usize)
pub fn set_num_transfers(&mut self, num_transfers: usize)
Set the maximum number of transfers that can be queued with the OS before backpressure is applied.
If more than num_transfers transfers are pending, calls to write
will block or async methods will return Pending until a transfer
completes.
Panics if num_transfers is zero.
Sourcepub fn with_num_transfers(self, num_transfers: usize) -> Self
pub fn with_num_transfers(self, num_transfers: usize) -> Self
Set the maximum number of transfers that can be queued with the OS before backpressure is applied.
See Self::set_num_transfers – this is for method chaining with EndpointWrite::new().
Sourcepub fn set_write_timeout(&mut self, timeout: Duration)
pub fn set_write_timeout(&mut self, timeout: Duration)
Set the timeout for a transfer in the blocking write APIs.
This affects the std::io::Write implementation only, and not the async
trait implementations.
When a timeout occurs, writing new data fails but transfers for
previously-written data are not cancelled. The data passed in the failed
write call is not written to the buffer, though note that functions
like write_all that call write multiple times may have successfully
written some of the data.
Sourcepub fn with_write_timeout(self, timeout: Duration) -> Self
pub fn with_write_timeout(self, timeout: Duration) -> Self
Set the timeout for an individual transfer for the blocking write APIs.
See Self::set_write_timeout – this is for method chaining with EndpointWrite::new().
Sourcepub fn into_inner(self) -> Endpoint<EpType, Out>
pub fn into_inner(self) -> Endpoint<EpType, Out>
Destroy this EndpointWrite and return the underlying Endpoint.
Any pending transfers are not cancelled.
Sourcepub fn submit(&mut self)
pub fn submit(&mut self)
Submit any buffered data to the OS immediately.
This submits the current buffer even if it not full, but does not wait for the transfer to complete or confirm that it was successful (see Write::flush). If the buffer is empty, this does nothing.
Sourcepub fn submit_end(&mut self)
pub fn submit_end(&mut self)
Submit any buffered data to the OS immediately, terminating with a short or zero-length packet.
Some USB protocols use packets shorter than the endpoint’s max packet size as a delimiter marking the end of a message. This method forces such a delimiter by adding a zero-length packet if the current buffer is a multiple of the endpoint’s max packet size.
This does not wait for the transfer to complete or confirm that it was successful (see Self::flush_end). If the buffer is empty, this sends a zero-length packet.
Sourcepub fn flush_end(&mut self) -> Result<(), Error>
pub fn flush_end(&mut self) -> Result<(), Error>
Submit any buffered data immediately, terminating with a short or zero-length packet, and wait for all pending transfers to complete or fail.
Sourcepub async fn flush_end_async(&mut self) -> Result<(), Error>
pub async fn flush_end_async(&mut self) -> Result<(), Error>
Submit any buffered data immediately, terminating with a short or zero-length packet, and wait for all pending transfers to complete.
Async version of Self::flush_end.
Trait Implementations§
Source§impl<EpType: BulkOrInterrupt> AsyncWrite for EndpointWrite<EpType>
Available on crate feature smol only.
impl<EpType: BulkOrInterrupt> AsyncWrite for EndpointWrite<EpType>
smol 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>>
Write data to the endpoint.
Data is buffered and not written until the buffer is full or submit()
or flush() are called. Writing will return Poll::Pending if there
are already too many transfers pending, as configured by
set_num_transfers.
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<()>>
Submit any buffered data immediately and wait for all pending transfers to complete or fail.
Source§impl<EpType: BulkOrInterrupt> AsyncWrite for EndpointWrite<EpType>
Available on crate feature tokio only.
impl<EpType: BulkOrInterrupt> AsyncWrite for EndpointWrite<EpType>
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>>
Write data to the endpoint.
Data is buffered and not written until the buffer is full or submit()
or flush() are called. Writing will return Poll::Pending if there
are already too many transfers pending, as configured by
set_num_transfers.
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<()>>
Submit any buffered data immediately and wait for all pending transfers to complete or fail.
Source§fn poll_shutdown(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<(), Error>>
fn poll_shutdown( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Error>>
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<EpType: BulkOrInterrupt> Write for EndpointWrite<EpType>
impl<EpType: BulkOrInterrupt> Write for EndpointWrite<EpType>
Source§fn write(&mut self, src: &[u8]) -> Result<usize>
fn write(&mut self, src: &[u8]) -> Result<usize>
Write data to the endpoint.
Data is buffered and not written until the buffer is full or submit()
or flush() are called. Writing will block if there are already too
many transfers pending, as configured by
set_num_transfers.
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Submit any buffered data immediately and wait for all pending transfers to complete or fail.
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)