Skip to content

Commit 75294de

Browse files
de-vri-esThomasdezeeuw
authored andcommitted
Move platform specific flags and debug impl to sys modules.
1 parent cd68aec commit 75294de

File tree

3 files changed

+47
-39
lines changed

3 files changed

+47
-39
lines changed

src/lib.rs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -247,29 +247,6 @@ pub struct RecvFlags(c_int);
247247

248248
#[cfg(not(target_os = "redox"))]
249249
impl RecvFlags {
250-
/// Check if the message terminates a record.
251-
///
252-
/// Not all socket types support the notion of records.
253-
/// For socket types that do support it (such as [`SEQPACKET`][Type::SEQPACKET]),
254-
/// a record is terminated by sending a message with the end-of-record flag set.
255-
///
256-
/// On Unix this corresponds to the MSG_EOR flag.
257-
#[cfg(unix)]
258-
pub fn is_end_of_record(self) -> bool {
259-
self.0 & sys::MSG_EOR != 0
260-
}
261-
262-
/// Check if the message contains out-of-band data.
263-
///
264-
/// This is useful for protocols where you receive out-of-band data
265-
/// mixed in with the normal data stream.
266-
///
267-
/// On Unix this corresponds to the MSG_OOB flag.
268-
#[cfg(unix)]
269-
pub fn is_out_of_band(self) -> bool {
270-
self.0 & sys::MSG_OOB != 0
271-
}
272-
273250
/// Check if the message contains a truncated datagram.
274251
///
275252
/// This flag is only used for datagram-based sockets,
@@ -281,16 +258,3 @@ impl RecvFlags {
281258
self.0 & sys::MSG_TRUNC != 0
282259
}
283260
}
284-
285-
#[cfg(not(target_os = "redox"))]
286-
impl std::fmt::Debug for RecvFlags {
287-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
288-
let mut dbg = f.debug_struct("RecvFlags");
289-
#[cfg(unix)]
290-
dbg.field("is_end_of_record", &self.is_end_of_record());
291-
#[cfg(unix)]
292-
dbg.field("is_out_of_band", &self.is_out_of_band());
293-
dbg.field("is_truncated", &self.is_truncated());
294-
dbg.finish()
295-
}
296-
}

src/sys/unix.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ macro_rules! syscall {
8585

8686
// Re-export message flags for the RecvFlags struct.
8787
#[cfg(not(target_os = "redox"))]
88-
pub(crate) use libc::{MSG_EOR, MSG_OOB, MSG_TRUNC};
88+
pub(crate) use libc::MSG_TRUNC;
8989

9090
#[cfg(any(target_os = "android", all(target_os = "linux", target_env = "gnu")))]
9191
type IovLen = usize;
@@ -211,6 +211,41 @@ impl_debug!(
211211
libc::IPPROTO_UDP,
212212
);
213213

214+
/// Unix-only API.
215+
impl RecvFlags {
216+
/// Check if the message terminates a record.
217+
///
218+
/// Not all socket types support the notion of records.
219+
/// For socket types that do support it (such as [`SEQPACKET`][Type::SEQPACKET]),
220+
/// a record is terminated by sending a message with the end-of-record flag set.
221+
///
222+
/// On Unix this corresponds to the MSG_EOR flag.
223+
pub fn is_end_of_record(self) -> bool {
224+
self.0 & libc::MSG_EOR != 0
225+
}
226+
227+
/// Check if the message contains out-of-band data.
228+
///
229+
/// This is useful for protocols where you receive out-of-band data
230+
/// mixed in with the normal data stream.
231+
///
232+
/// On Unix this corresponds to the MSG_OOB flag.
233+
pub fn is_out_of_band(self) -> bool {
234+
self.0 & libc::MSG_OOB != 0
235+
}
236+
}
237+
238+
#[cfg(not(target_os = "redox"))]
239+
impl std::fmt::Debug for RecvFlags {
240+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
241+
f.debug_struct("RecvFlags")
242+
.field("is_end_of_record", &self.is_end_of_record())
243+
.field("is_out_of_band", &self.is_out_of_band())
244+
.field("is_truncated", &self.is_truncated())
245+
.finish()
246+
}
247+
}
248+
214249
/// Unix only API.
215250
impl SockAddr {
216251
/// Constructs a `SockAddr` with the family `AF_UNIX` and the provided path.

src/sys/windows.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ pub use winapi::ctypes::c_int;
4444

4545
/// Fake MSG_TRUNC flag for the [`RecvFlags`] struct.
4646
///
47-
/// Value copied from Linux.
48-
pub(crate) const MSG_TRUNC: c_int = 0x20;
47+
/// The flag is enabled when a `WSARecv[From]` call returns `WSAEMSGSIZE`.
48+
/// The value of the flag is defined by us.
49+
pub(crate) const MSG_TRUNC: c_int = 0x01;
4950

5051
// Used in `Domain`.
5152
pub(crate) use winapi::shared::ws2def::{AF_INET, AF_INET6};
@@ -103,6 +104,14 @@ impl_debug!(
103104
self::IPPROTO_UDP,
104105
);
105106

107+
impl std::fmt::Debug for RecvFlags {
108+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
109+
f.debug_struct("RecvFlags")
110+
.field("is_truncated", &self.is_truncated())
111+
.finish()
112+
}
113+
}
114+
106115
#[repr(C)]
107116
struct tcp_keepalive {
108117
onoff: c_ulong,

0 commit comments

Comments
 (0)