rustix/backend/libc/net/
send_recv.rs

1use crate::backend::c;
2use bitflags::bitflags;
3
4bitflags! {
5    /// `MSG_*` flags for use with [`send`], [`sendto`], and related
6    /// functions.
7    ///
8    /// [`send`]: crate::net::send
9    /// [`sendto`]: crate::net::sendto
10    #[repr(transparent)]
11    #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
12    pub struct SendFlags: u32 {
13        /// `MSG_CONFIRM`
14        #[cfg(not(any(
15            bsd,
16            solarish,
17            windows,
18            target_os = "aix",
19            target_os = "cygwin",
20            target_os = "espidf",
21            target_os = "nto",
22            target_os = "haiku",
23            target_os = "horizon",
24            target_os = "hurd",
25            target_os = "redox",
26            target_os = "vita",
27        )))]
28        const CONFIRM = bitcast!(c::MSG_CONFIRM);
29        /// `MSG_DONTROUTE`
30        const DONTROUTE = bitcast!(c::MSG_DONTROUTE);
31        /// `MSG_DONTWAIT`
32        #[cfg(not(windows))]
33        const DONTWAIT = bitcast!(c::MSG_DONTWAIT);
34        /// `MSG_EOR`
35        #[cfg(not(any(windows, target_os = "horizon")))]
36        const EOR = bitcast!(c::MSG_EOR);
37        /// `MSG_MORE`
38        #[cfg(not(any(
39            bsd,
40            solarish,
41            windows,
42            target_os = "aix",
43            target_os = "cygwin",
44            target_os = "haiku",
45            target_os = "hurd",
46            target_os = "nto",
47            target_os = "redox",
48            target_os = "vita",
49        )))]
50        const MORE = bitcast!(c::MSG_MORE);
51        #[cfg(not(any(apple, windows, target_os = "redox", target_os = "vita")))]
52        /// `MSG_NOSIGNAL`
53        const NOSIGNAL = bitcast!(c::MSG_NOSIGNAL);
54        /// `MSG_OOB`
55        const OOB = bitcast!(c::MSG_OOB);
56
57        /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
58        const _ = !0;
59    }
60}
61
62bitflags! {
63    /// `MSG_*` flags for use with [`recv`], [`recvfrom`], and related
64    /// functions.
65    ///
66    /// [`recv`]: crate::net::recv
67    /// [`recvfrom`]: crate::net::recvfrom
68    #[repr(transparent)]
69    #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
70    pub struct RecvFlags: u32 {
71        /// `MSG_CMSG_CLOEXEC`
72        #[cfg(not(any(
73            apple,
74            solarish,
75            windows,
76            target_os = "aix",
77            target_os = "espidf",
78            target_os = "haiku",
79            target_os = "horizon",
80            target_os = "nto",
81            target_os = "redox",
82            target_os = "vita",
83        )))]
84        const CMSG_CLOEXEC = bitcast!(c::MSG_CMSG_CLOEXEC);
85        /// `MSG_DONTWAIT`
86        #[cfg(not(windows))]
87        const DONTWAIT = bitcast!(c::MSG_DONTWAIT);
88        /// `MSG_ERRQUEUE`
89        #[cfg(not(any(
90            bsd,
91            solarish,
92            windows,
93            target_os = "aix",
94            target_os = "cygwin",
95            target_os = "espidf",
96            target_os = "haiku",
97            target_os = "horizon",
98            target_os = "hurd",
99            target_os = "nto",
100            target_os = "redox",
101            target_os = "vita",
102        )))]
103        const ERRQUEUE = bitcast!(c::MSG_ERRQUEUE);
104        /// `MSG_OOB`
105        const OOB = bitcast!(c::MSG_OOB);
106        /// `MSG_PEEK`
107        const PEEK = bitcast!(c::MSG_PEEK);
108        /// `MSG_TRUNC`
109        // Apple, illumos, and NetBSD have `MSG_TRUNC` but it's not documented
110        // for use with `recv` and friends, and in practice appears to be
111        // ignored.
112        #[cfg(not(any(apple, solarish, target_os = "horizon", target_os = "netbsd")))]
113        const TRUNC = bitcast!(c::MSG_TRUNC);
114        /// `MSG_WAITALL`
115        const WAITALL = bitcast!(c::MSG_WAITALL);
116
117        /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
118        const _ = !0;
119    }
120}
121
122bitflags! {
123    /// `MSG_*` flags returned from [`recvmsg`], in the `flags` field of
124    /// [`RecvMsg`]
125    ///
126    /// [`recvmsg`]: crate::net::recvmsg
127    /// [`RecvMsg`]: crate::net::RecvMsg
128    #[repr(transparent)]
129    #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
130    pub struct ReturnFlags: u32 {
131        /// `MSG_OOB`
132        const OOB = bitcast!(c::MSG_OOB);
133        /// `MSG_EOR`
134        #[cfg(not(any(windows, target_os = "horizon")))]
135        const EOR = bitcast!(c::MSG_EOR);
136        /// `MSG_TRUNC`
137        #[cfg(not(target_os = "horizon"))]
138        const TRUNC = bitcast!(c::MSG_TRUNC);
139        /// `MSG_CTRUNC`
140        #[cfg(not(target_os = "horizon"))]
141        const CTRUNC = bitcast!(c::MSG_CTRUNC);
142
143        /// `MSG_CMSG_CLOEXEC`
144        #[cfg(linux_kernel)]
145        const CMSG_CLOEXEC = bitcast!(c::MSG_CMSG_CLOEXEC);
146        /// `MSG_ERRQUEUE`
147        #[cfg(linux_kernel)]
148        const ERRQUEUE = bitcast!(c::MSG_ERRQUEUE);
149
150        /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
151        const _ = !0;
152    }
153}