pub struct MessageQueue<D: MessageData = Vec<u8>> { /* private fields */ }Expand description
A MessageQueue stores a FIFO sequence of messages.
Implementations§
Source§impl<D: MessageData> MessageQueue<D>
impl<D: MessageData> MessageQueue<D>
pub fn new(capacity: usize) -> Self
Sourcepub fn available_capacity(&self) -> usize
pub fn available_capacity(&self) -> usize
Returns the number of bytes that can be written to the message queue before the buffer is full.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the total number of bytes this message queue can store, regardless of the current amount of data in the buffer.
pub fn messages(&self) -> impl Iterator<Item = &Message<D>>
Sourcepub fn set_capacity(&mut self, requested_capacity: usize) -> Result<(), Errno>
pub fn set_capacity(&mut self, requested_capacity: usize) -> Result<(), Errno>
Sets the capacity of the message queue to the provided number of bytes.
Reurns an error if the requested capacity could not be set (e.g., if the requested capacity was less than the current number of bytes stored).
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the message queue is empty, or it only contains empty messages.
Sourcepub fn read_stream(
&mut self,
data: &mut dyn OutputBuffer,
) -> Result<MessageReadInfo, Errno>
pub fn read_stream( &mut self, data: &mut dyn OutputBuffer, ) -> Result<MessageReadInfo, Errno>
Reads messages until there are no more messages, a message with ancillary data is
encountered, or data are full.
To read data from the queue without consuming the messages, see peek_stream.
§Parameters
data: TheOutputBufferto write the data to.
Returns the number of bytes that were read into the buffer, and any ancillary data that was read.
Sourcepub fn peek_stream(
&self,
data: &mut dyn OutputBuffer,
) -> Result<MessageReadInfo, Errno>
pub fn peek_stream( &self, data: &mut dyn OutputBuffer, ) -> Result<MessageReadInfo, Errno>
Peeks messages until there are no more messages, a message with ancillary data is
encountered, or data are full.
Unlike read_stream, this function does not remove the messages from the queue.
Used to implement MSG_PEEK.
§Parameters
data: TheOutputBufferto write the data to.
Returns the number of bytes that were read into the buffer, and any ancillary data that was read.
pub fn read_datagram( &mut self, data: &mut dyn OutputBuffer, ) -> Result<MessageReadInfo, Errno>
pub fn peek_datagram( &mut self, data: &mut dyn OutputBuffer, ) -> Result<MessageReadInfo, Errno>
Sourcepub fn read_message(&mut self) -> Option<Message<D>>
pub fn read_message(&mut self) -> Option<Message<D>>
Reads the next message in the buffer, if such a message exists.
pub fn peek_queue(&self) -> &VecDeque<Message<D>>
Sourcepub fn write_stream(
&mut self,
data: &mut dyn InputBuffer,
address: Option<SocketAddress>,
ancillary_data: &mut Vec<AncillaryData>,
) -> Result<usize, Errno>
pub fn write_stream( &mut self, data: &mut dyn InputBuffer, address: Option<SocketAddress>, ancillary_data: &mut Vec<AncillaryData>, ) -> Result<usize, Errno>
Writes the the contents of InputBuffer into this socket.
Will return EAGAIN if not enough capacity is available.
§Parameters
task: The task to read memory from.data: TheInputBufferto read the data from.
Returns the number of bytes that were written to the socket.
Sourcepub fn write_stream_with_filter(
&mut self,
data: &mut dyn InputBuffer,
address: Option<SocketAddress>,
ancillary_data: &mut Vec<AncillaryData>,
filter: impl FnOnce(Message<D>) -> Option<Message<D>>,
) -> Result<usize, Errno>
pub fn write_stream_with_filter( &mut self, data: &mut dyn InputBuffer, address: Option<SocketAddress>, ancillary_data: &mut Vec<AncillaryData>, filter: impl FnOnce(Message<D>) -> Option<Message<D>>, ) -> Result<usize, Errno>
Writes the the contents of InputBuffer into this socket.
Will return EAGAIN if not enough capacity is available.
§Parameters
task: The task to read memory from.data: TheInputBufferto read the data from.filter: A filter to run on the message before inserting it into the queue. If it returns None, no message is enqueued.
Returns the number of bytes that were written to the socket.
Sourcepub fn write_datagram(
&mut self,
data: &mut dyn InputBuffer,
address: Option<SocketAddress>,
ancillary_data: &mut Vec<AncillaryData>,
) -> Result<usize, Errno>
pub fn write_datagram( &mut self, data: &mut dyn InputBuffer, address: Option<SocketAddress>, ancillary_data: &mut Vec<AncillaryData>, ) -> Result<usize, Errno>
Writes the the contents of InputBuffer into this socket as
single message. Will return EAGAIN if not enough capacity is available.
§Parameters
task: The task to read memory from.data: TheInputBufferto read the data from.
Returns the number of bytes that were written to the socket.
Sourcepub fn write_datagram_with_filter(
&mut self,
data: &mut dyn InputBuffer,
address: Option<SocketAddress>,
ancillary_data: &mut Vec<AncillaryData>,
filter: impl FnOnce(Message<D>) -> Option<Message<D>>,
) -> Result<usize, Errno>
pub fn write_datagram_with_filter( &mut self, data: &mut dyn InputBuffer, address: Option<SocketAddress>, ancillary_data: &mut Vec<AncillaryData>, filter: impl FnOnce(Message<D>) -> Option<Message<D>>, ) -> Result<usize, Errno>
Writes the the contents of InputBuffer into this socket as
single message. Will return EAGAIN if not enough capacity is available.
§Parameters
task: The task to read memory from.data: TheInputBufferto read the data from.filter: A filter to run on the message before inserting it into the queue. If it returns None, no message is enqueued.
Returns the number of bytes that were written to the socket.
Sourcepub fn write_front(&mut self, message: Message<D>)
pub fn write_front(&mut self, message: Message<D>)
Writes a message to the front of the message queue.
Sourcepub fn write_message(&mut self, message: Message<D>)
pub fn write_message(&mut self, message: Message<D>)
Writes a message to the back of the message queue.
pub fn query_events(&self) -> FdEvents
Trait Implementations§
Auto Trait Implementations§
impl<D> Freeze for MessageQueue<D>
impl<D = Vec<u8>> !RefUnwindSafe for MessageQueue<D>
impl<D> Send for MessageQueue<D>where
D: Send,
impl<D> Sync for MessageQueue<D>where
D: Sync,
impl<D> Unpin for MessageQueue<D>where
D: Unpin,
impl<D = Vec<u8>> !UnwindSafe for MessageQueue<D>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
Source§impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
§impl<T> InstanceFromServiceTransport<T> for T
impl<T> InstanceFromServiceTransport<T> for T
§fn from_service_transport(handle: T) -> T
fn from_service_transport(handle: T) -> T
T to [Self]Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more