mqrs: Implement send and recv of sysvmq [wip]
TBD: CHANGELOG.md and adapt to recent changes is sysvmq
This commit is contained in:
parent
64d08e2ed4
commit
4978f37168
52
Cargo.lock
generated
52
Cargo.lock
generated
|
@ -88,9 +88,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
|||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.4.0"
|
||||
version = "2.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
|
||||
checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
|
@ -129,9 +129,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.4.6"
|
||||
version = "4.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956"
|
||||
checksum = "ac495e00dcec98c83465d5ad66c5c4fabd652fd6686e7c6269b117e729a6f17b"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
|
@ -139,9 +139,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.4.6"
|
||||
version = "4.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45"
|
||||
checksum = "c77ed9a32a62e6ca27175d00d29d05ca32e396ea1eb5fb01d8256b669cec7663"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
|
@ -151,9 +151,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.4.2"
|
||||
version = "4.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873"
|
||||
checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
|
@ -163,9 +163,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.5.1"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961"
|
||||
checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"
|
||||
|
||||
[[package]]
|
||||
name = "colorchoice"
|
||||
|
@ -222,16 +222,16 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
|
|||
|
||||
[[package]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.57"
|
||||
version = "0.1.58"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613"
|
||||
checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20"
|
||||
dependencies = [
|
||||
"android_system_properties",
|
||||
"core-foundation-sys",
|
||||
"iana-time-zone-haiku",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"windows",
|
||||
"windows-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -356,9 +356,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.10.1"
|
||||
version = "1.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aaac441002f822bc9705a681810a4dd2963094b9ca0ddc41cb963a4c189189ea"
|
||||
checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
|
@ -368,9 +368,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.2"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5011c7e263a695dc8ca064cddb722af1be54e517a280b12a5356f98366899e5d"
|
||||
checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
|
@ -385,9 +385,9 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
|
|||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.38.19"
|
||||
version = "0.38.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "745ecfa778e66b2b63c88a61cb36e0eea109e803b0b86bf9879fbc77c70e86ed"
|
||||
checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"errno",
|
||||
|
@ -433,18 +433,18 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.49"
|
||||
version = "1.0.50"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4"
|
||||
checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.49"
|
||||
version = "1.0.50"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc"
|
||||
checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -549,10 +549,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.48.0"
|
||||
name = "windows-core"
|
||||
version = "0.51.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
|
||||
checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
|
28
src/main.rs
28
src/main.rs
|
@ -1,5 +1,7 @@
|
|||
use anyhow::Result;
|
||||
use clap::{ArgAction, Parser};
|
||||
use clap::Parser;
|
||||
use log::Level;
|
||||
use std::env;
|
||||
|
||||
mod posix;
|
||||
mod sysv;
|
||||
|
@ -30,6 +32,8 @@ enum SysvCommand {
|
|||
Info(sysv::Info),
|
||||
List(sysv::List),
|
||||
Unlink(sysv::Unlink),
|
||||
Send(sysv::Send),
|
||||
Recv(sysv::Recv),
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
|
@ -39,9 +43,9 @@ enum SysvCommand {
|
|||
subcommand_required = true
|
||||
)]
|
||||
struct Opts {
|
||||
/// Produce verbose output, multiple -v options increase the verbosity (max. 3)
|
||||
#[clap(short, long, global = true, action = ArgAction::Count)]
|
||||
verbose: u32,
|
||||
/// Set a log level
|
||||
#[arg(short, long, value_name = "LEVEL", default_value_t = Level::Info)]
|
||||
pub log_level: Level,
|
||||
/// Backend to be used
|
||||
#[clap(subcommand)]
|
||||
backend: Backend,
|
||||
|
@ -50,15 +54,11 @@ struct Opts {
|
|||
fn main() -> Result<()> {
|
||||
let opts: Opts = Opts::parse();
|
||||
|
||||
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or(
|
||||
match opts.verbose {
|
||||
0 => "warn",
|
||||
1 => "info",
|
||||
2 => "debug",
|
||||
_ => "trace",
|
||||
},
|
||||
))
|
||||
.init();
|
||||
if env::var("RUST_LOG").is_err() {
|
||||
env::set_var("RUST_LOG", format!("{}", opts.log_level));
|
||||
}
|
||||
|
||||
env_logger::init();
|
||||
|
||||
match opts.backend {
|
||||
Backend::Posix(p) => match p {
|
||||
|
@ -74,6 +74,8 @@ fn main() -> Result<()> {
|
|||
SysvCommand::Info(i) => i.run()?,
|
||||
SysvCommand::List(l) => l.run()?,
|
||||
SysvCommand::Unlink(u) => u.run()?,
|
||||
SysvCommand::Send(s) => s.run()?,
|
||||
SysvCommand::Recv(r) => r.run()?,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
mod create;
|
||||
mod info;
|
||||
mod list;
|
||||
mod recv;
|
||||
mod send;
|
||||
mod unlink;
|
||||
|
||||
pub use create::Create;
|
||||
pub use info::Info;
|
||||
pub use list::List;
|
||||
pub use recv::Recv;
|
||||
pub use send::Send;
|
||||
pub use unlink::Unlink;
|
||||
|
|
42
src/sysv/recv.rs
Normal file
42
src/sysv/recv.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
use anyhow::Result;
|
||||
// use chrono::DateTime;
|
||||
use clap::Parser;
|
||||
// use humantime::Duration;
|
||||
use log::info;
|
||||
use sysvmq::SysvMq;
|
||||
|
||||
/// Send a message to a message queue
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct Recv {
|
||||
// /// Set a different priority, priority >= 0
|
||||
// #[clap(short, long, default_value = "0")]
|
||||
// priority: u32,
|
||||
// /// Do not block
|
||||
// #[clap(short, long)]
|
||||
// non_blocking: bool,
|
||||
// /// Timeout, example "5h 23min 42ms"
|
||||
// #[clap(short = 'o', long, conflicts_with = "deadline")]
|
||||
// timeout: Option<String>,
|
||||
// /// Deadline until messages are sent (format: "%Y-%m-%d %H:%M:%S")
|
||||
// #[clap(short, long, conflicts_with = "timeout")]
|
||||
// deadline: Option<String>,
|
||||
// /// Name of the queue
|
||||
// #[clap(value_name = "QUEUE")]
|
||||
// queue: String,
|
||||
/// Key of of the queue to write to
|
||||
#[clap(value_name = "Key")]
|
||||
key: i32,
|
||||
// /// Message to be sent to the queue
|
||||
// #[clap(value_name = "MESSAGE")]
|
||||
// msg: String,
|
||||
}
|
||||
|
||||
impl Recv {
|
||||
pub fn run(&self) -> Result<()> {
|
||||
let mq = SysvMq::<String>::new();
|
||||
|
||||
mq.open(self.key)?.recv();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
42
src/sysv/send.rs
Normal file
42
src/sysv/send.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
use anyhow::Result;
|
||||
// use chrono::DateTime;
|
||||
use clap::Parser;
|
||||
// use humantime::Duration;
|
||||
use log::info;
|
||||
use sysvmq::SysvMq;
|
||||
|
||||
/// Send a message to a message queue
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct Send {
|
||||
// /// Set a different priority, priority >= 0
|
||||
// #[clap(short, long, default_value = "0")]
|
||||
// priority: u32,
|
||||
// /// Do not block
|
||||
// #[clap(short, long)]
|
||||
// non_blocking: bool,
|
||||
// /// Timeout, example "5h 23min 42ms"
|
||||
// #[clap(short = 'o', long, conflicts_with = "deadline")]
|
||||
// timeout: Option<String>,
|
||||
// /// Deadline until messages are sent (format: "%Y-%m-%d %H:%M:%S")
|
||||
// #[clap(short, long, conflicts_with = "timeout")]
|
||||
// deadline: Option<String>,
|
||||
// /// Name of the queue
|
||||
// #[clap(value_name = "QUEUE")]
|
||||
// queue: String,
|
||||
/// Key of of the queue to write to
|
||||
#[clap(value_name = "Key")]
|
||||
key: i32,
|
||||
/// Message to be sent to the queue
|
||||
#[clap(value_name = "MESSAGE")]
|
||||
msg: String,
|
||||
}
|
||||
|
||||
impl Send {
|
||||
pub fn run(&self) -> Result<()> {
|
||||
let mq = SysvMq::<String>::new();
|
||||
|
||||
mq.open(self.key)?.send(self.msg.as_bytes());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue