diff --git a/src/lib.rs b/src/lib.rs index b9de136..298a48e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,21 +1,15 @@ use libc::{ - msgctl, msgget, msqid_ds, IPC_CREAT, IPC_EXCL, IPC_INFO, IPC_NOWAIT, IPC_PRIVATE, IPC_RMID, - IPC_SET, IPC_STAT, MSG_COPY, MSG_EXCEPT, MSG_INFO, MSG_NOERROR, MSG_STAT, + msgctl, msgget, msginfo, msqid_ds, IPC_CREAT, IPC_EXCL, IPC_INFO, IPC_NOWAIT, IPC_PRIVATE, + IPC_RMID, IPC_SET, IPC_STAT, MSG_COPY, MSG_EXCEPT, MSG_INFO, MSG_NOERROR, MSG_STAT, }; use nix::errno::{errno, Errno}; -use std::{marker::PhantomData, num::ParseIntError, ptr}; +use std::{marker::PhantomData, mem::MaybeUninit, ptr}; use thiserror::Error; #[derive(Debug, Error)] pub enum SysvMqError { #[error("SysV message queue: {0}")] ErrnoError(&'static str), - #[error("No message queue found with key {0}")] - KeyNotFound(i32), - #[error("IO Error: {0}")] - IoError(#[from] std::io::Error), - #[error("Parse Error: {0}")] - ParserError(#[from] ParseIntError), } /// IPC bit flags @@ -78,6 +72,56 @@ pub fn id_from_key(key: i32) -> Result { } } +pub fn ipc_info(id: i32) -> Result<(), SysvMqError> { + let mut msginfo = MaybeUninit::::uninit(); + + unsafe { + msgctl( + id, + ControlCommands::IpcInfo as i32, + msginfo.as_mut_ptr() as *mut msqid_ds, + ); + } + + let msginfo = unsafe { msginfo.assume_init() }; + + println!("info: {:?}", msginfo); + + Ok(()) +} + +pub fn stat_info(id: i32) -> Result<(), SysvMqError> { + let mut msginfo = MaybeUninit::::uninit(); + + unsafe { + msgctl(id, ControlCommands::Stat as i32, msginfo.as_mut_ptr()); + } + + let msginfo = unsafe { msginfo.assume_init() }; + + println!("info: {:?}", msginfo); + + Ok(()) +} + +pub fn msg_info(id: i32) -> Result<(), SysvMqError> { + let mut msginfo = MaybeUninit::::uninit(); + + unsafe { + msgctl( + id, + ControlCommands::MsgInfo as i32, + msginfo.as_mut_ptr() as *mut msqid_ds, + ); + } + + let msginfo = unsafe { msginfo.assume_init() }; + + println!("info: {:?}", msginfo); + + Ok(()) +} + pub struct SysvMq { pub id: i32, pub key: i32,