Struct rustbus::connection::ll_conn::SendMessageContext
source · pub struct SendMessageContext<'a> { /* private fields */ }
Expand description
Handles the process of actually sending a message over the connection it was created from. This allows graceful handling of short writes or timeouts with only parts of the message written. You can loop over write or write_once or use write_all to wait until all bytes have been written or an error besides a timeout arises.
Implementations§
source§impl SendMessageContext<'_>
impl SendMessageContext<'_>
pub fn serial(&self) -> u32
sourcepub fn resume<'a>(
conn: &'a mut SendConn,
msg: &'a MarshalledMessage,
progress: SendMessageState
) -> SendMessageContext<'a>
pub fn resume<'a>( conn: &'a mut SendConn, msg: &'a MarshalledMessage, progress: SendMessageState ) -> SendMessageContext<'a>
Resume a SendMessageContext from the progress. This needs to be called with the same conn and msg that were used to create the original SendMessageContext.
sourcepub fn into_progress(self) -> SendMessageState
pub fn into_progress(self) -> SendMessageState
Turn this into the progress to resume the sending later. Note that you cannot send another message while doing that. You need to resume a SendMessageContext from this progress and send the current message beofre starting the next one.
sourcepub fn force_finish(self)
pub fn force_finish(self)
only call if you deem the connection doomed by an error returned from writing. The connection might be left in an invalid state if some but not all bytes of the message have been written
sourcepub fn write(self, timeout: Timeout) -> Result<u32, (Self, Error)>
pub fn write(self, timeout: Timeout) -> Result<u32, (Self, Error)>
Try writing as many bytes as possible until either no more bytes need to be written or the timeout is reached. For an infinite timeout there is write_all as a shortcut
sourcepub fn bytes_total(&self) -> usize
pub fn bytes_total(&self) -> usize
How many bytes need to be sent in total
sourcepub fn all_bytes_written(&self) -> bool
pub fn all_bytes_written(&self) -> bool
Check if all bytes have been written
Trait Implementations§
source§impl<'a> Debug for SendMessageContext<'a>
impl<'a> Debug for SendMessageContext<'a>
source§impl Drop for SendMessageContext<'_>
impl Drop for SendMessageContext<'_>
This panics if the SendMessageContext was dropped when it was not yet finished. Use force_finish / force_finish_on_error if you want to do this. It will be necessary for handling errors that make the connection unusable.