Skip to content

Commit

Permalink
Auto merge of #271 - abbradar:mqueue-fixes, r=kamalmarhubi
Browse files Browse the repository at this point in the history
mqueue: change types to allow more cases

Part of #270, fixed according to @kamalmarhubi's comments.
  • Loading branch information
homu committed Feb 19, 2016
2 parents 7fa7206 + 62ec478 commit 48aa78b
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/mqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
use {Errno, Result};

use libc::{c_int, c_long, c_char, size_t, mode_t, strlen};
use libc::{c_int, c_long, c_char, size_t, mode_t};
use std::ffi::CString;
use sys::stat::Mode;
use std::ptr;

pub use self::consts::*;

Expand Down Expand Up @@ -75,9 +76,9 @@ impl MqAttr {
}


#[inline]
pub fn mq_open(name: &CString, oflag: MQ_OFlag, mode: Mode, attr: &MqAttr) -> Result<MQd> {
let res = unsafe { ffi::mq_open(name.as_ptr(), oflag.bits(), mode.bits() as mode_t, attr as *const MqAttr) };
pub fn mq_open(name: &CString, oflag: MQ_OFlag, mode: Mode, attr: Option<&MqAttr>) -> Result<MQd> {
let attr_p = attr.map(|attr| attr as *const _).unwrap_or(ptr::null());
let res = unsafe { ffi::mq_open(name.as_ptr(), oflag.bits(), mode.bits() as mode_t, attr_p) };

Errno::result(res)
}
Expand All @@ -100,11 +101,10 @@ pub fn mq_receive(mqdes: MQd, message: &mut [u8], msq_prio: u32) -> Result<usize
Errno::result(res).map(|r| r as usize)
}

pub fn mq_send(mqdes: MQd, message: &CString, msq_prio: u32) -> Result<usize> {
let len = unsafe { strlen(message.as_ptr()) as size_t };
let res = unsafe { ffi::mq_send(mqdes, message.as_ptr(), len, msq_prio) };
pub fn mq_send(mqdes: MQd, message: &[u8], msq_prio: u32) -> Result<()> {
let res = unsafe { ffi::mq_send(mqdes, message.as_ptr() as *const c_char, message.len(), msq_prio) };

Errno::result(res).map(|r| r as usize)
Errno::result(res).map(drop)
}

pub fn mq_getattr(mqd: MQd) -> Result<MqAttr> {
Expand Down

0 comments on commit 48aa78b

Please sign in to comment.