Crates.io | posixmq |
lib.rs | posixmq |
version | 1.0.0 |
source | src |
created_at | 2019-03-25 01:05:10.426745 |
updated_at | 2021-02-02 22:48:27.26159 |
description | An idiomatic library for using posix message queues, with optional mio integration |
homepage | |
repository | https://github.com/tormol/posixmq |
max_upload_size | |
id | 123646 |
size | 129,001 |
A Rust library for using posix message queues.
let mq = posixmq::PosixMq::open("/queue").expect("cannot open /queue");
let mut buf = vec![0; mq.attributes().unwrap_or_default().max_msg_len];
loop {
let (priority, len) = mq.recv(&mut buf).expect("recv() failed");
let msg = std::str::from_utf8(&buf[..len]).expect("not UTF-8");
println!("priority: {:3}, message: {}", priority, msg);
}
posixmq has been tested to work on Linux, FreeBSD, NetBSD, DragonFly BSD and OmniOSce, but not all features are available everywhere. See rustdoc for details.
*macOS, OpenBSD, Android and Windows doesn't have posix message queues, and this crate will fail to compile there.
On Linux, FreeBSD and DragonFly BSD, posix message queues can be registered with epoll / kqueue, and therefore used with mio.
Both mio version 0.6 and 0.7 are supported, through the opt-in crate features mio_06
and mio_07
.
Enable the feature for the mio version you use in Cargo.toml with for example:
[dependencies]
mio = {version="0.7", features=["os-poll"]} # you probably need os-poll
posixmq = {version="1.0", features=["mio_07"]}
Also remember to open the message queues in nonblocking mode.
The minimum Rust version for 1.0.* releases is 1.39.0 if the mio_07
feature is enabled, and 1.31.1 otherwise.
Later 1.*.0 releases might increase this. Until rustup has builds for DragonFly and Illumos, the minimum version will not be increased past what is available in repositories for these operating systems.
New optional features might require newer Rust versions.
To lock to a minor release, use posixmq = "1.0.*"
in Cargo.toml, or copy posixmq.rs into your project and remove feature gates as necessary.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
.attributes()
, .is_nonblocking()
and .is_cloexec()
.
For consistency with std
and to make it easier to catch bugs..receive()
to .recv()
for consistency with std
.
(.receive_deadline()
and .receive_timeout()
are also renamed to .recv_deadline()
and .recv_timeout()
)unlink()
to remove_queue()
for consistency with std
.
(unlink_c()
is also renamed to remove_queue_c()
)Attributes
partially opaque for future extensibility, and implement Default
for it.name_from_bytes()
.mio
feature for integrating with Mio 0.6 to mio_06
.mio_07
feature for integrating with Mio 0.7.Clone
for the borrowing iterator posixmq::Iter
.PosixMq::open()
to open in read-write mode instead of read-only.OpenOptions.permissions()
to .mode()
for consistency with std
.OpenOptions.not_cloexec()
..send_timeout()
, .send_deadline()
, .receive_timeout()
and .receive_deadline()
.Iter
and IntoIter
receiving iterator types..try_clone()
.PosixMq::from_raw_mqd()
, .as_raw_mqd()
and .into_raw_mqd()
.Sync
on FreeBSD.linux-x86_64-unknown-gnux32
.