Skip to content

Commit afeb723

Browse files
imarkovivmarkov
imarkov
authored andcommitted
Support for the ESP-IDF framework
1 parent d97e78a commit afeb723

File tree

4 files changed

+67
-22
lines changed

4 files changed

+67
-22
lines changed

src/lib.rs

+21-8
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,16 @@ impl Type {
205205
pub const DGRAM: Type = Type(sys::SOCK_DGRAM);
206206

207207
/// Type corresponding to `SOCK_SEQPACKET`.
208-
#[cfg(feature = "all")]
209-
#[cfg_attr(docsrs, doc(cfg(feature = "all")))]
208+
#[cfg(all(feature = "all", not(target_os = "espidf")))]
209+
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", not(target_os = "espidf")))))]
210210
pub const SEQPACKET: Type = Type(sys::SOCK_SEQPACKET);
211211

212212
/// Type corresponding to `SOCK_RAW`.
213-
#[cfg(all(feature = "all", not(target_os = "redox")))]
214-
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", not(target_os = "redox")))))]
213+
#[cfg(all(feature = "all", not(any(target_os = "redox", target_os = "espidf"))))]
214+
#[cfg_attr(
215+
docsrs,
216+
doc(cfg(all(feature = "all", not(any(target_os = "redox", target_os = "espidf")))))
217+
)]
215218
pub const RAW: Type = Type(sys::SOCK_RAW);
216219
}
217220

@@ -328,9 +331,14 @@ impl<'a> DerefMut for MaybeUninitSlice<'a> {
328331
#[derive(Debug, Clone)]
329332
pub struct TcpKeepalive {
330333
time: Option<Duration>,
331-
#[cfg(not(any(target_os = "redox", target_os = "solaris")))]
334+
#[cfg(not(any(target_os = "redox", target_os = "solaris", target_os = "espidf")))]
332335
interval: Option<Duration>,
333-
#[cfg(not(any(target_os = "redox", target_os = "solaris", target_os = "windows")))]
336+
#[cfg(not(any(
337+
target_os = "redox",
338+
target_os = "solaris",
339+
target_os = "windows",
340+
target_os = "espidf"
341+
)))]
334342
retries: Option<u32>,
335343
}
336344

@@ -339,9 +347,14 @@ impl TcpKeepalive {
339347
pub const fn new() -> TcpKeepalive {
340348
TcpKeepalive {
341349
time: None,
342-
#[cfg(not(any(target_os = "redox", target_os = "solaris")))]
350+
#[cfg(not(any(target_os = "redox", target_os = "solaris", target_os = "espidf")))]
343351
interval: None,
344-
#[cfg(not(any(target_os = "redox", target_os = "solaris", target_os = "windows")))]
352+
#[cfg(not(any(
353+
target_os = "redox",
354+
target_os = "solaris",
355+
target_os = "windows",
356+
target_os = "espidf"
357+
)))]
345358
retries: None,
346359
}
347360
}

src/sockaddr.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ impl From<SocketAddrV4> for SockAddr {
235235
target_os = "ios",
236236
target_os = "macos",
237237
target_os = "netbsd",
238-
target_os = "openbsd"
238+
target_os = "openbsd",
239+
target_os = "espidf"
239240
))]
240241
sin_len: 0,
241242
};
@@ -269,7 +270,8 @@ impl From<SocketAddrV6> for SockAddr {
269270
target_os = "ios",
270271
target_os = "macos",
271272
target_os = "netbsd",
272-
target_os = "openbsd"
273+
target_os = "openbsd",
274+
target_os = "espidf"
273275
))]
274276
sin6_len: 0,
275277
#[cfg(any(target_os = "solaris", target_os = "illumos"))]

src/socket.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ fn set_common_flags(socket: Socket) -> io::Result<Socket> {
702702
target_os = "linux",
703703
target_os = "netbsd",
704704
target_os = "openbsd",
705+
target_os = "espidf",
705706
))
706707
))]
707708
socket._set_cloexec(true)?;
@@ -1015,8 +1016,11 @@ impl Socket {
10151016
/// For more information about this option, see [`set_header_included`].
10161017
///
10171018
/// [`set_header_included`]: Socket::set_header_included
1018-
#[cfg(all(feature = "all", not(target_os = "redox")))]
1019-
#[cfg_attr(docsrs, doc(all(feature = "all", not(target_os = "redox"))))]
1019+
#[cfg(all(feature = "all", not(any(target_os = "redox", target_os = "espidf"))))]
1020+
#[cfg_attr(
1021+
docsrs,
1022+
doc(all(feature = "all", not(any(target_os = "redox", target_os = "espidf"))))
1023+
)]
10201024
pub fn header_included(&self) -> io::Result<bool> {
10211025
unsafe {
10221026
getsockopt::<c_int>(self.as_raw(), sys::IPPROTO_IP, sys::IP_HDRINCL)
@@ -1035,8 +1039,11 @@ impl Socket {
10351039
/// [raw(7)]: https://man7.org/linux/man-pages/man7/raw.7.html
10361040
/// [`IP_TTL`]: Socket::set_ttl
10371041
/// [`IP_TOS`]: Socket::set_tos
1038-
#[cfg(all(feature = "all", not(target_os = "redox")))]
1039-
#[cfg_attr(docsrs, doc(all(feature = "all", not(target_os = "redox"))))]
1042+
#[cfg(all(feature = "all", not(any(target_os = "redox", target_os = "espidf"))))]
1043+
#[cfg_attr(
1044+
docsrs,
1045+
doc(all(feature = "all", not(any(target_os = "redox", target_os = "espidf"))))
1046+
)]
10401047
pub fn set_header_included(&self, included: bool) -> io::Result<()> {
10411048
unsafe {
10421049
setsockopt(
@@ -1138,6 +1145,7 @@ impl Socket {
11381145
target_os = "openbsd",
11391146
target_os = "redox",
11401147
target_os = "solaris",
1148+
target_os = "espidf",
11411149
)))]
11421150
pub fn join_multicast_v4_n(
11431151
&self,
@@ -1167,6 +1175,7 @@ impl Socket {
11671175
target_os = "openbsd",
11681176
target_os = "redox",
11691177
target_os = "solaris",
1178+
target_os = "espidf",
11701179
)))]
11711180
pub fn leave_multicast_v4_n(
11721181
&self,
@@ -1196,6 +1205,7 @@ impl Socket {
11961205
target_os = "netbsd",
11971206
target_os = "redox",
11981207
target_os = "fuchsia",
1208+
target_os = "espidf",
11991209
)))]
12001210
pub fn join_ssm_v4(
12011211
&self,
@@ -1228,6 +1238,7 @@ impl Socket {
12281238
target_os = "netbsd",
12291239
target_os = "redox",
12301240
target_os = "fuchsia",
1241+
target_os = "espidf",
12311242
)))]
12321243
pub fn leave_ssm_v4(
12331244
&self,
@@ -1401,6 +1412,7 @@ impl Socket {
14011412
target_os = "openbsd",
14021413
target_os = "redox",
14031414
target_os = "solaris",
1415+
target_os = "espidf",
14041416
)))]
14051417
pub fn set_recv_tos(&self, recv_tos: bool) -> io::Result<()> {
14061418
let recv_tos = if recv_tos { 1 } else { 0 };
@@ -1427,6 +1439,7 @@ impl Socket {
14271439
target_os = "openbsd",
14281440
target_os = "redox",
14291441
target_os = "solaris",
1442+
target_os = "espidf",
14301443
)))]
14311444
pub fn recv_tos(&self) -> io::Result<bool> {
14321445
unsafe {

src/sys/unix.rs

+25-8
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ pub(crate) use libc::c_int;
6060
// Used in `Domain`.
6161
pub(crate) use libc::{AF_INET, AF_INET6};
6262
// Used in `Type`.
63-
#[cfg(all(feature = "all", not(target_os = "redox")))]
63+
#[cfg(all(feature = "all", not(any(target_os = "redox", target_os = "espidf"))))]
6464
pub(crate) use libc::SOCK_RAW;
65-
#[cfg(feature = "all")]
65+
#[cfg(all(feature = "all", not(target_os = "espidf")))]
6666
pub(crate) use libc::SOCK_SEQPACKET;
6767
pub(crate) use libc::{SOCK_DGRAM, SOCK_STREAM};
6868
// Used in `Protocol`.
@@ -72,10 +72,15 @@ pub(crate) use libc::{
7272
sa_family_t, sockaddr, sockaddr_in, sockaddr_in6, sockaddr_storage, socklen_t,
7373
};
7474
// Used in `RecvFlags`.
75+
#[cfg(not(any(target_os = "redox", target_os = "espidf")))]
76+
pub(crate) use libc::MSG_TRUNC;
7577
#[cfg(not(target_os = "redox"))]
76-
pub(crate) use libc::{MSG_TRUNC, SO_OOBINLINE};
77-
// Used in `Socket`.
78-
#[cfg(all(feature = "all", not(target_os = "redox")))]
78+
pub(crate) use libc::SO_OOBINLINE;
79+
#[cfg(target_os = "espidf")]
80+
pub(crate) const MSG_TRUNC: libc::c_int = 4; // TODO: Expose in libc for ESP-IDF/LwIP
81+
// Used in `Socket`.
82+
// Used in `Socket`.
83+
#[cfg(all(feature = "all", not(any(target_os = "redox", target_os = "espidf"))))]
7984
pub(crate) use libc::IP_HDRINCL;
8085
#[cfg(not(any(
8186
target_os = "fuchsia",
@@ -84,6 +89,7 @@ pub(crate) use libc::IP_HDRINCL;
8489
target_os = "openbsd",
8590
target_os = "redox",
8691
target_os = "solaris",
92+
target_os = "espidf",
8793
)))]
8894
pub(crate) use libc::IP_RECVTOS;
8995
#[cfg(not(any(
@@ -109,6 +115,7 @@ pub(crate) use libc::{
109115
target_os = "netbsd",
110116
target_os = "redox",
111117
target_os = "fuchsia",
118+
target_os = "espidf",
112119
)))]
113120
pub(crate) use libc::{
114121
ip_mreq_source as IpMreqSource, IP_ADD_SOURCE_MEMBERSHIP, IP_DROP_SOURCE_MEMBERSHIP,
@@ -216,6 +223,7 @@ type IovLen = usize;
216223
target_os = "netbsd",
217224
target_os = "openbsd",
218225
target_os = "solaris",
226+
target_os = "espidf",
219227
target_vendor = "apple",
220228
))]
221229
type IovLen = c_int;
@@ -355,10 +363,11 @@ impl_debug!(
355363
Type,
356364
libc::SOCK_STREAM,
357365
libc::SOCK_DGRAM,
358-
#[cfg(not(target_os = "redox"))]
366+
#[cfg(not(any(target_os = "redox", target_os = "espidf")))]
359367
libc::SOCK_RAW,
360-
#[cfg(not(any(target_os = "redox", target_os = "haiku")))]
368+
#[cfg(not(any(target_os = "redox", target_os = "haiku", target_os = "espidf")))]
361369
libc::SOCK_RDM,
370+
#[cfg(not(target_os = "espidf"))]
362371
libc::SOCK_SEQPACKET,
363372
/* TODO: add these optional bit OR-ed flags:
364373
#[cfg(any(
@@ -403,7 +412,14 @@ impl RecvFlags {
403412
///
404413
/// On Unix this corresponds to the MSG_EOR flag.
405414
pub const fn is_end_of_record(self) -> bool {
406-
self.0 & libc::MSG_EOR != 0
415+
// TODO: Expose this constant in libc for the ESP-IDF/LwIP framework
416+
#[cfg(target_os = "espidf")]
417+
const MSG_EOR: libc::c_int = 8;
418+
419+
#[cfg(not(target_os = "espidf"))]
420+
use libc::MSG_EOR;
421+
422+
self.0 & MSG_EOR != 0
407423
}
408424

409425
/// Check if the message contains out-of-band data.
@@ -1025,6 +1041,7 @@ pub(crate) fn from_in6_addr(addr: in6_addr) -> Ipv6Addr {
10251041
target_os = "openbsd",
10261042
target_os = "redox",
10271043
target_os = "solaris",
1044+
target_os = "espidf",
10281045
)))]
10291046
pub(crate) fn to_mreqn(
10301047
multiaddr: &Ipv4Addr,

0 commit comments

Comments
 (0)