[−][src]Struct posixmq::PosixMq
A descriptor for an open posix message queue.
Message queues can sent to and / or received from depending on the options it was opened with.
The descriptor is closed when this struct is dropped.
Methods
impl PosixMq
[src]
pub fn open<N: AsRef<[u8]> + ?Sized>(name: &N) -> Result<Self, Error>
[src]
Open an existing message queue in read-only mode.
See OpenOptions::open()
for
details and possible errors.
pub fn create<N: AsRef<[u8]> + ?Sized>(name: &N) -> Result<Self, Error>
[src]
Open a message queue in read-write mode, creating it if it doesn't exists.
See OpenOptions::open()
for
details and possible errors.
pub fn send(&self, priority: u32, msg: &[u8]) -> Result<(), Error>
[src]
Add a message to the queue.
For maximum portability, avoid using priorities >= 32 or sending zero-length messages.
Errors
- Queue is full and opened in nonblocking mode (EAGAIN) =>
ErrorKind::WouldBlock
- Message is too big for the queue (EMSGSIZE) =>
ErrorKind::Other
- OS doesn't allow empty messages (EMSGSIZE) =>
ErrorKind::Other
- Priority is too high (EINVAL) =>
ErrorKind::InvalidInput
- Possibly other =>
ErrorKind::Other
pub fn receive(&self, msgbuf: &mut [u8]) -> Result<(u32, usize), Error>
[src]
Take the message with the highest priority from the queue.
The buffer must be at least as big as the maximum message length.
Errors
- Queue is empty and opened in nonblocking mode (EAGAIN) =>
ErrorKind::WouldBlock
- The receive buffer is smaller than the queue's maximum message size (EMSGSIZE) =>
ErrorKind::Other
- Possibly other =>
ErrorKind::Other
pub fn attributes(&self) -> Attributes
[src]
Get information about the state of the message queue.
Errors
Retrieving these attributes should only fail if the underlying
descriptor has been closed or is not a message queue.
In that case max_msg_len
, capacity
and current_messages
will be
zero and nonblocking
is set to true
.
The rationale for swallowing these errors is that they're only caused
by buggy code (incorrect usage of from_raw_fd()
or similar),
and not having to .unwrap()
makes the function nicer to use.
Future send()
and receive()
will reveal the bug when they also fail.
(Which also means they won't block.)
pub fn is_nonblocking(&self) -> bool
[src]
Check whether this descriptor is in nonblocking mode.
Errors
Returns true
if retrieving the flag fails,
see attributes()
for rationale.
pub fn set_nonblocking(&self, nonblocking: bool) -> Result<(), Error>
[src]
Enable or disable nonblocking mode for this descriptor.
This can also be set when opening the message queue,
with OpenOptions::nonblocking()
.
Errors
Setting nonblocking mode should only fail due to incorrect usage of
from_raw_fd()
or as_raw_fd()
, see the documentation on
attributes()
for details.
pub fn is_cloexec(&self) -> bool
[src]
Check whether this descriptor will be closed if the process exec
s
into another program.
Errors
Retrieving this flag should only fail if the queue is already closed.
In that case true
is returned because the queue will not be open
after exec
ing.
pub unsafe fn set_cloexec(&self, cloexec: bool) -> Result<(), Error>
[src]
Set close-on-exec for this descriptor.
PosixMq
enables close-on-exec by default when opening message queues,
but this can be disabled with OpenOptions::not_cloexec()
.
Prefer using OpenOptions
to set it, because another thread might
exec
between the message queue being opened and this change taking
effect.
Additionally, this function has a race condition with itself, as the flag cannot portably be set atomically without affecting other attributes.
Errors
This function should only fail if the underlying file descriptor has
been closed (due to incorrect usage of from_raw_fd()
or similar),
and not reused for something else yet.
Trait Implementations
impl Drop for PosixMq
[src]
impl Send for PosixMq
[src]
impl Debug for PosixMq
[src]
impl FromRawFd for PosixMq
[src]
Create a PosixMq
handle from a raw file descriptor.
Note that the queue will be closed when the returned PosixMq
goes out
of scope / is dropped.
unsafe fn from_raw_fd(fd: RawFd) -> Self
[src]
impl AsRawFd for PosixMq
[src]
Get the raw file descriptor for the queue.
Note that the queue will be closed when the returned PosixMq
goes out
of scope / is dropped.
This impl is not available on DragonFlyBSD.
impl IntoRawFd for PosixMq
[src]
Convert the PosixMq
into a raw file descriptor.
fn into_raw_fd(self) -> RawFd
[src]
impl Evented for PosixMq
[src]
Make posix message queues pollable by mio.
This impl requires the mio
feature to be enabled:
[dependencies]
posixmq = {version="0.1", features="mio"}
Remember to open the queue in non-blocking mode. (with OpenOptions.noblocking()
)
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,