4
4
5
5
use { Errno , Result } ;
6
6
7
- use libc:: { self , c_char, c_long, mode_t, mqd_t, size_t} ;
7
+ use libc:: { self , c_char, c_long, mode_t, mqd_t, size_t} ;
8
8
use std:: ffi:: CString ;
9
9
use sys:: stat:: Mode ;
10
10
use std:: mem;
@@ -30,28 +30,31 @@ libc_bitflags!{
30
30
#[ repr( C ) ]
31
31
#[ derive( Clone , Copy ) ]
32
32
pub struct MqAttr {
33
- mq_attr : libc:: mq_attr
33
+ mq_attr : libc:: mq_attr ,
34
34
}
35
35
36
36
impl PartialEq < MqAttr > for MqAttr {
37
37
fn eq ( & self , other : & MqAttr ) -> bool {
38
38
let self_attr = self . mq_attr ;
39
39
let other_attr = other. mq_attr ;
40
- self_attr. mq_flags == other_attr. mq_flags &&
41
- self_attr. mq_maxmsg == other_attr. mq_maxmsg &&
42
- self_attr. mq_msgsize == other_attr. mq_msgsize &&
43
- self_attr. mq_curmsgs == other_attr. mq_curmsgs
40
+ self_attr. mq_flags == other_attr. mq_flags && self_attr. mq_maxmsg == other_attr. mq_maxmsg &&
41
+ self_attr. mq_msgsize == other_attr. mq_msgsize &&
42
+ self_attr. mq_curmsgs == other_attr. mq_curmsgs
44
43
}
45
44
}
46
45
47
46
impl MqAttr {
48
- pub fn new ( mq_flags : c_long , mq_maxmsg : c_long , mq_msgsize : c_long , mq_curmsgs : c_long ) -> MqAttr {
47
+ pub fn new ( mq_flags : c_long ,
48
+ mq_maxmsg : c_long ,
49
+ mq_msgsize : c_long ,
50
+ mq_curmsgs : c_long )
51
+ -> MqAttr {
49
52
let mut attr = unsafe { mem:: uninitialized :: < libc:: mq_attr > ( ) } ;
50
53
attr. mq_flags = mq_flags;
51
54
attr. mq_maxmsg = mq_maxmsg;
52
55
attr. mq_msgsize = mq_msgsize;
53
56
attr. mq_curmsgs = mq_curmsgs;
54
- MqAttr { mq_attr : attr}
57
+ MqAttr { mq_attr : attr }
55
58
}
56
59
57
60
pub fn flags ( & self ) -> c_long {
@@ -60,14 +63,19 @@ impl MqAttr {
60
63
}
61
64
62
65
63
- pub fn mq_open ( name : & CString , oflag : MQ_OFlag , mode : Mode , attr : Option < & MqAttr > ) -> Result < mqd_t > {
66
+ pub fn mq_open ( name : & CString ,
67
+ oflag : MQ_OFlag ,
68
+ mode : Mode ,
69
+ attr : Option < & MqAttr > )
70
+ -> Result < mqd_t > {
64
71
let res = match attr {
65
- Some ( mq_attr) => {
66
- unsafe { libc:: mq_open ( name. as_ptr ( ) , oflag. bits ( ) , mode. bits ( ) as mode_t , & mq_attr. mq_attr as * const libc:: mq_attr ) }
72
+ Some ( mq_attr) => unsafe {
73
+ libc:: mq_open ( name. as_ptr ( ) ,
74
+ oflag. bits ( ) ,
75
+ mode. bits ( ) as mode_t ,
76
+ & mq_attr. mq_attr as * const libc:: mq_attr )
67
77
} ,
68
- None => {
69
- unsafe { libc:: mq_open ( name. as_ptr ( ) , oflag. bits ( ) ) }
70
- }
78
+ None => unsafe { libc:: mq_open ( name. as_ptr ( ) , oflag. bits ( ) ) } ,
71
79
} ;
72
80
Errno :: result ( res)
73
81
}
@@ -77,19 +85,29 @@ pub fn mq_unlink(name: &CString) -> Result<()> {
77
85
Errno :: result ( res) . map ( drop)
78
86
}
79
87
80
- pub fn mq_close ( mqdes : mqd_t ) -> Result < ( ) > {
88
+ pub fn mq_close ( mqdes : mqd_t ) -> Result < ( ) > {
81
89
let res = unsafe { libc:: mq_close ( mqdes) } ;
82
90
Errno :: result ( res) . map ( drop)
83
91
}
84
92
85
93
pub fn mq_receive ( mqdes : mqd_t , message : & mut [ u8 ] , msg_prio : & mut u32 ) -> Result < usize > {
86
94
let len = message. len ( ) as size_t ;
87
- let res = unsafe { libc:: mq_receive ( mqdes, message. as_mut_ptr ( ) as * mut c_char , len, msg_prio as * mut u32 ) } ;
95
+ let res = unsafe {
96
+ libc:: mq_receive ( mqdes,
97
+ message. as_mut_ptr ( ) as * mut c_char ,
98
+ len,
99
+ msg_prio as * mut u32 )
100
+ } ;
88
101
Errno :: result ( res) . map ( |r| r as usize )
89
102
}
90
103
91
104
pub fn mq_send ( mqdes : mqd_t , message : & [ u8 ] , msq_prio : u32 ) -> Result < ( ) > {
92
- let res = unsafe { libc:: mq_send ( mqdes, message. as_ptr ( ) as * const c_char , message. len ( ) , msq_prio) } ;
105
+ let res = unsafe {
106
+ libc:: mq_send ( mqdes,
107
+ message. as_ptr ( ) as * const c_char ,
108
+ message. len ( ) ,
109
+ msq_prio)
110
+ } ;
93
111
Errno :: result ( res) . map ( drop)
94
112
}
95
113
@@ -115,7 +133,10 @@ pub fn mq_setattr(mqd: mqd_t, newattr: &MqAttr) -> Result<MqAttr> {
115
133
/// Returns the old attributes
116
134
pub fn mq_set_nonblock ( mqd : mqd_t ) -> Result < ( MqAttr ) > {
117
135
let oldattr = try!( mq_getattr ( mqd) ) ;
118
- let newattr = MqAttr :: new ( O_NONBLOCK . bits ( ) as c_long , oldattr. mq_attr . mq_maxmsg , oldattr. mq_attr . mq_msgsize , oldattr. mq_attr . mq_curmsgs ) ;
136
+ let newattr = MqAttr :: new ( O_NONBLOCK . bits ( ) as c_long ,
137
+ oldattr. mq_attr . mq_maxmsg ,
138
+ oldattr. mq_attr . mq_msgsize ,
139
+ oldattr. mq_attr . mq_curmsgs ) ;
119
140
mq_setattr ( mqd, & newattr)
120
141
}
121
142
@@ -124,6 +145,9 @@ pub fn mq_set_nonblock(mqd: mqd_t) -> Result<(MqAttr)> {
124
145
/// Returns the old attributes
125
146
pub fn mq_remove_nonblock ( mqd : mqd_t ) -> Result < ( MqAttr ) > {
126
147
let oldattr = try!( mq_getattr ( mqd) ) ;
127
- let newattr = MqAttr :: new ( 0 , oldattr. mq_attr . mq_maxmsg , oldattr. mq_attr . mq_msgsize , oldattr. mq_attr . mq_curmsgs ) ;
148
+ let newattr = MqAttr :: new ( 0 ,
149
+ oldattr. mq_attr . mq_maxmsg ,
150
+ oldattr. mq_attr . mq_msgsize ,
151
+ oldattr. mq_attr . mq_curmsgs ) ;
128
152
mq_setattr ( mqd, & newattr)
129
153
}
0 commit comments