Skip to content

Commit 14796fb

Browse files
jastaThomasdezeeuw
authored andcommitted
Backport ESP-IDF support from main branch
1 parent 98f4747 commit 14796fb

File tree

4 files changed

+53
-20
lines changed

4 files changed

+53
-20
lines changed

src/lib.rs

Lines changed: 12 additions & 4 deletions
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

@@ -280,6 +283,7 @@ impl RecvFlags {
280283
///
281284
/// On Unix this corresponds to the `MSG_TRUNC` flag.
282285
/// On Windows this corresponds to the `WSAEMSGSIZE` error code.
286+
#[cfg(not(target_os = "espidf"))]
283287
pub const fn is_truncated(self) -> bool {
284288
self.0 & sys::MSG_TRUNC != 0
285289
}
@@ -334,6 +338,7 @@ pub struct TcpKeepalive {
334338
target_os = "redox",
335339
target_os = "solaris",
336340
target_os = "nto",
341+
target_os = "espidf",
337342
)))]
338343
interval: Option<Duration>,
339344
#[cfg(not(any(
@@ -342,6 +347,7 @@ pub struct TcpKeepalive {
342347
target_os = "solaris",
343348
target_os = "windows",
344349
target_os = "nto",
350+
target_os = "espidf",
345351
)))]
346352
retries: Option<u32>,
347353
}
@@ -356,6 +362,7 @@ impl TcpKeepalive {
356362
target_os = "redox",
357363
target_os = "solaris",
358364
target_os = "nto",
365+
target_os = "espidf",
359366
)))]
360367
interval: None,
361368
#[cfg(not(any(
@@ -364,6 +371,7 @@ impl TcpKeepalive {
364371
target_os = "solaris",
365372
target_os = "windows",
366373
target_os = "nto",
374+
target_os = "espidf",
367375
)))]
368376
retries: None,
369377
}

src/sockaddr.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ impl From<SocketAddrV4> for SockAddr {
235235
target_os = "macos",
236236
target_os = "netbsd",
237237
target_os = "openbsd",
238-
target_os = "nto"
238+
target_os = "nto",
239+
target_os = "espidf",
239240
))]
240241
sin_len: 0,
241242
};
@@ -275,7 +276,8 @@ impl From<SocketAddrV6> for SockAddr {
275276
target_os = "macos",
276277
target_os = "netbsd",
277278
target_os = "openbsd",
278-
target_os = "nto"
279+
target_os = "nto",
280+
target_os = "espidf",
279281
))]
280282
sin6_len: 0,
281283
#[cfg(any(target_os = "solaris", target_os = "illumos"))]

src/socket.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,7 @@ fn set_common_flags(socket: Socket) -> io::Result<Socket> {
729729
target_os = "linux",
730730
target_os = "netbsd",
731731
target_os = "openbsd",
732+
target_os = "espidf",
732733
))
733734
))]
734735
socket._set_cloexec(true)?;
@@ -1042,8 +1043,11 @@ impl Socket {
10421043
/// For more information about this option, see [`set_header_included`].
10431044
///
10441045
/// [`set_header_included`]: Socket::set_header_included
1045-
#[cfg(all(feature = "all", not(target_os = "redox")))]
1046-
#[cfg_attr(docsrs, doc(all(feature = "all", not(target_os = "redox"))))]
1046+
#[cfg(all(feature = "all", not(any(target_os = "redox", target_os = "espidf"))))]
1047+
#[cfg_attr(
1048+
docsrs,
1049+
doc(cfg(all(feature = "all", not(any(target_os = "redox", target_os = "espidf")))))
1050+
)]
10471051
pub fn header_included(&self) -> io::Result<bool> {
10481052
unsafe {
10491053
getsockopt::<c_int>(self.as_raw(), sys::IPPROTO_IP, sys::IP_HDRINCL)
@@ -1062,8 +1066,11 @@ impl Socket {
10621066
/// [raw(7)]: https://man7.org/linux/man-pages/man7/raw.7.html
10631067
/// [`IP_TTL`]: Socket::set_ttl
10641068
/// [`IP_TOS`]: Socket::set_tos
1065-
#[cfg(all(feature = "all", not(target_os = "redox")))]
1066-
#[cfg_attr(docsrs, doc(all(feature = "all", not(target_os = "redox"))))]
1069+
#[cfg(all(feature = "all", not(any(target_os = "redox", target_os = "espidf"))))]
1070+
#[cfg_attr(
1071+
docsrs,
1072+
doc(cfg(all(feature = "all", not(any(target_os = "redox", target_os = "espidf")))))
1073+
)]
10671074
pub fn set_header_included(&self, included: bool) -> io::Result<()> {
10681075
unsafe {
10691076
setsockopt(
@@ -1166,6 +1173,7 @@ impl Socket {
11661173
target_os = "redox",
11671174
target_os = "solaris",
11681175
target_os = "nto",
1176+
target_os = "espidf",
11691177
)))]
11701178
pub fn join_multicast_v4_n(
11711179
&self,
@@ -1196,6 +1204,7 @@ impl Socket {
11961204
target_os = "redox",
11971205
target_os = "solaris",
11981206
target_os = "nto",
1207+
target_os = "espidf",
11991208
)))]
12001209
pub fn leave_multicast_v4_n(
12011210
&self,
@@ -1228,6 +1237,7 @@ impl Socket {
12281237
target_os = "redox",
12291238
target_os = "fuchsia",
12301239
target_os = "nto",
1240+
target_os = "espidf",
12311241
)))]
12321242
pub fn join_ssm_v4(
12331243
&self,
@@ -1263,6 +1273,7 @@ impl Socket {
12631273
target_os = "redox",
12641274
target_os = "fuchsia",
12651275
target_os = "nto",
1276+
target_os = "espidf",
12661277
)))]
12671278
pub fn leave_ssm_v4(
12681279
&self,
@@ -1439,6 +1450,7 @@ impl Socket {
14391450
target_os = "solaris",
14401451
target_os = "windows",
14411452
target_os = "nto",
1453+
target_os = "espidf",
14421454
)))]
14431455
pub fn set_recv_tos(&self, recv_tos: bool) -> io::Result<()> {
14441456
let recv_tos = if recv_tos { 1 } else { 0 };
@@ -1468,6 +1480,7 @@ impl Socket {
14681480
target_os = "solaris",
14691481
target_os = "windows",
14701482
target_os = "nto",
1483+
target_os = "espidf",
14711484
)))]
14721485
pub fn recv_tos(&self) -> io::Result<bool> {
14731486
unsafe {

src/sys/unix.rs

Lines changed: 20 additions & 10 deletions
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,8 +72,10 @@ 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};
78+
pub(crate) use libc::SO_OOBINLINE;
7779
// Used in `Socket`.
7880
#[cfg(not(target_os = "nto"))]
7981
pub(crate) use libc::ipv6_mreq as Ipv6Mreq;
@@ -89,6 +91,7 @@ pub(crate) use libc::IP_HDRINCL;
8991
target_os = "solaris",
9092
target_os = "haiku",
9193
target_os = "nto",
94+
target_os = "espidf",
9295
)))]
9396
pub(crate) use libc::IP_RECVTOS;
9497
#[cfg(not(any(
@@ -117,6 +120,7 @@ pub(crate) use libc::{
117120
target_os = "redox",
118121
target_os = "fuchsia",
119122
target_os = "nto",
123+
target_os = "espidf",
120124
)))]
121125
pub(crate) use libc::{
122126
ip_mreq_source as IpMreqSource, IP_ADD_SOURCE_MEMBERSHIP, IP_DROP_SOURCE_MEMBERSHIP,
@@ -232,6 +236,7 @@ type IovLen = usize;
232236
target_os = "solaris",
233237
target_os = "nto",
234238
target_vendor = "apple",
239+
target_os = "espidf",
235240
))]
236241
type IovLen = c_int;
237242

@@ -370,10 +375,11 @@ impl_debug!(
370375
Type,
371376
libc::SOCK_STREAM,
372377
libc::SOCK_DGRAM,
373-
#[cfg(not(target_os = "redox"))]
378+
#[cfg(not(any(target_os = "redox", target_os = "espidf")))]
374379
libc::SOCK_RAW,
375-
#[cfg(not(any(target_os = "redox", target_os = "haiku")))]
380+
#[cfg(not(any(target_os = "redox", target_os = "haiku", target_os = "espidf")))]
376381
libc::SOCK_RDM,
382+
#[cfg(not(target_os = "espidf"))]
377383
libc::SOCK_SEQPACKET,
378384
/* TODO: add these optional bit OR-ed flags:
379385
#[cfg(any(
@@ -417,6 +423,7 @@ impl RecvFlags {
417423
/// a record is terminated by sending a message with the end-of-record flag set.
418424
///
419425
/// On Unix this corresponds to the MSG_EOR flag.
426+
#[cfg(not(target_os = "espidf"))]
420427
pub const fn is_end_of_record(self) -> bool {
421428
self.0 & libc::MSG_EOR != 0
422429
}
@@ -435,11 +442,13 @@ impl RecvFlags {
435442
#[cfg(not(target_os = "redox"))]
436443
impl std::fmt::Debug for RecvFlags {
437444
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
438-
f.debug_struct("RecvFlags")
439-
.field("is_end_of_record", &self.is_end_of_record())
440-
.field("is_out_of_band", &self.is_out_of_band())
441-
.field("is_truncated", &self.is_truncated())
442-
.finish()
445+
let mut s = f.debug_struct("RecvFlags");
446+
#[cfg(not(target_os = "espidf"))]
447+
s.field("is_end_of_record", &self.is_end_of_record());
448+
s.field("is_out_of_band", &self.is_out_of_band());
449+
#[cfg(not(target_os = "espidf"))]
450+
s.field("is_truncated", &self.is_truncated());
451+
s.finish()
443452
}
444453
}
445454

@@ -1056,6 +1065,7 @@ pub(crate) fn from_in6_addr(addr: in6_addr) -> Ipv6Addr {
10561065
target_os = "redox",
10571066
target_os = "solaris",
10581067
target_os = "nto",
1068+
target_os = "espidf",
10591069
)))]
10601070
pub(crate) fn to_mreqn(
10611071
multiaddr: &Ipv4Addr,

0 commit comments

Comments
 (0)