Skip to content

Commit

Permalink
fix: Update ESP-IDF constants
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioGasquez committed Sep 13, 2024
1 parent 1b11393 commit 133d9d0
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 30 deletions.
16 changes: 8 additions & 8 deletions src/unix/newlib/espidf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ pub const MSG_EOR: ::c_int = 0x08;

pub const PTHREAD_STACK_MIN: ::size_t = 768;

pub const SIGABRT: ::c_int = 1;
pub const SIGFPE: ::c_int = 1;
pub const SIGILL: ::c_int = 1;
pub const SIGINT: ::c_int = 1;
pub const SIGSEGV: ::c_int = 1;
pub const SIGTERM: ::c_int = 1;
pub const SIGABRT: ::c_int = 6;
pub const SIGFPE: ::c_int = 8;
pub const SIGILL: ::c_int = 4;
pub const SIGINT: ::c_int = 2;
pub const SIGSEGV: ::c_int = 11;
pub const SIGTERM: ::c_int = 15;
pub const SIGHUP: ::c_int = 1;
pub const SIGQUIT: ::c_int = 1;
pub const NSIG: ::size_t = 2;
pub const SIGQUIT: ::c_int = 3;
pub const NSIG: ::size_t = 32;

extern "C" {
pub fn pthread_create(
Expand Down
134 changes: 112 additions & 22 deletions src/unix/newlib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ cfg_if! {
pub type socklen_t = u32;
pub type speed_t = u32;
pub type suseconds_t = i32;
pub type tcflag_t = ::c_uint;
cfg_if! {
if #[cfg(target_os = "espidf")] {
pub type tcflag_t = u16;
} else {
pub type tcflag_t = ::c_uint;
}
}
pub type useconds_t = u32;

cfg_if! {
Expand Down Expand Up @@ -241,7 +247,14 @@ pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
size: [__PTHREAD_INITIALIZER_BYTE; __SIZEOF_PTHREAD_RWLOCK_T],
};
pub const NCCS: usize = 32;

cfg_if! {
if #[cfg(target_os = "espidf")] {
pub const NCCS: usize = 11;
} else {
pub const NCCS: usize = 32;
}
}

cfg_if! {
if #[cfg(target_os = "espidf")] {
Expand Down Expand Up @@ -410,7 +423,13 @@ pub const O_SYNC: ::c_int = 8192;
pub const O_NONBLOCK: ::c_int = 16384;

pub const O_ACCMODE: ::c_int = 3;
pub const O_CLOEXEC: ::c_int = 0x80000;
cfg_if! {
if #[cfg(target_os = "espidf")] {
pub const O_CLOEXEC: ::c_int = 0x40000;
} else {
pub const O_CLOEXEC: ::c_int = 0x80000;
}
}

pub const RTLD_LAZY: ::c_int = 0x1;

Expand Down Expand Up @@ -452,7 +471,13 @@ pub const SOL_TCP: ::c_int = 6;

pub const PF_UNSPEC: ::c_int = 0;
pub const PF_INET: ::c_int = 2;
pub const PF_INET6: ::c_int = 23;
cfg_if! {
if #[cfg(target_os = "espidf")] {
pub const PF_INET6: ::c_int = 10;
} else {
pub const PF_INET6: ::c_int = 23;
}
}

pub const AF_UNSPEC: ::c_int = 0;
pub const AF_INET: ::c_int = 2;
Expand Down Expand Up @@ -537,6 +562,9 @@ cfg_if! {
if #[cfg(target_os = "vita")] {
pub const TCP_NODELAY: ::c_int = 1;
pub const TCP_MAXSEG: ::c_int = 2;
} else if #[cfg(target_os = "espidf")] {
pub const TCP_NODELAY: ::c_int = 1;
pub const TCP_MAXSEG: ::c_int = 8194;
} else {
pub const TCP_NODELAY: ::c_int = 8193;
pub const TCP_MAXSEG: ::c_int = 8194;
Expand All @@ -545,69 +573,131 @@ cfg_if! {

pub const TCP_NOPUSH: ::c_int = 4;
pub const TCP_NOOPT: ::c_int = 8;
pub const TCP_KEEPIDLE: ::c_int = 256;
pub const TCP_KEEPINTVL: ::c_int = 512;
pub const TCP_KEEPCNT: ::c_int = 1024;
cfg_if! {
if #[cfg(target_os = "espidf")] {
pub const TCP_KEEPIDLE: ::c_int = 3;
pub const TCP_KEEPINTVL: ::c_int = 4;
pub const TCP_KEEPCNT: ::c_int = 5;
} else {
pub const TCP_KEEPIDLE: ::c_int = 256;
pub const TCP_KEEPINTVL: ::c_int = 512;
pub const TCP_KEEPCNT: ::c_int = 1024;
}
}

cfg_if! {
if #[cfg(target_os = "horizon")] {
pub const IP_TOS: ::c_int = 7;
} else if #[cfg(target_os = "espidf")] {
pub const IP_TOS: ::c_int = 1;
} else {
pub const IP_TOS: ::c_int = 3;
}
}
cfg_if! {
if #[cfg(target_os = "vita")] {
pub const IP_TTL: ::c_int = 4;
} else if #[cfg(target_os = "espidf")] {
pub const IP_TTL: ::c_int = 2;
} else {
pub const IP_TTL: ::c_int = 8;
}
}
pub const IP_MULTICAST_IF: ::c_int = 9;
pub const IP_MULTICAST_TTL: ::c_int = 10;
pub const IP_MULTICAST_LOOP: ::c_int = 11;

cfg_if! {
if #[cfg(target_os = "espidf")] {
pub const IP_MULTICAST_IF: ::c_int = 6;
pub const IP_MULTICAST_TTL: ::c_int = 5;
pub const IP_MULTICAST_LOOP: ::c_int = 7;
} else {
pub const IP_MULTICAST_IF: ::c_int = 9;
pub const IP_MULTICAST_TTL: ::c_int = 10;
pub const IP_MULTICAST_LOOP: ::c_int = 11;
}
}

cfg_if! {
if #[cfg(target_os = "vita")] {
pub const IP_ADD_MEMBERSHIP: ::c_int = 12;
pub const IP_DROP_MEMBERSHIP: ::c_int = 13;
} else if #[cfg(target_os = "espidf")] {
pub const IP_ADD_MEMBERSHIP: ::c_int = 3;
pub const IP_DROP_MEMBERSHIP: ::c_int = 4;
} else {
pub const IP_ADD_MEMBERSHIP: ::c_int = 11;
pub const IP_DROP_MEMBERSHIP: ::c_int = 12;
}
}
pub const IPV6_UNICAST_HOPS: ::c_int = 4;
pub const IPV6_MULTICAST_IF: ::c_int = 9;
pub const IPV6_MULTICAST_HOPS: ::c_int = 10;
pub const IPV6_MULTICAST_LOOP: ::c_int = 11;
cfg_if! {
if #[cfg(target_os = "espidf")] {
pub const IPV6_MULTICAST_IF: ::c_int = 768;
pub const IPV6_MULTICAST_HOPS: ::c_int = 769;
pub const IPV6_MULTICAST_LOOP: ::c_int = 770;
} else {
pub const IPV6_MULTICAST_IF: ::c_int = 9;
pub const IPV6_MULTICAST_HOPS: ::c_int = 10;
pub const IPV6_MULTICAST_LOOP: ::c_int = 11;
}
}
pub const IPV6_V6ONLY: ::c_int = 27;
pub const IPV6_JOIN_GROUP: ::c_int = 12;
pub const IPV6_LEAVE_GROUP: ::c_int = 13;
pub const IPV6_ADD_MEMBERSHIP: ::c_int = 12;
pub const IPV6_DROP_MEMBERSHIP: ::c_int = 13;

pub const HOST_NOT_FOUND: ::c_int = 1;
pub const NO_DATA: ::c_int = 2;
cfg_if! {
if #[cfg(target_os = "espidf")] {
pub const HOST_NOT_FOUND: ::c_int = 210;
pub const NO_DATA: ::c_int = 211;
pub const NO_RECOVERY: ::c_int = 212;
pub const TRY_AGAIN: ::c_int = 213;

} else {
pub const HOST_NOT_FOUND: ::c_int = 1;
pub const NO_DATA: ::c_int = 2;
pub const NO_RECOVERY: ::c_int = 3;
pub const TRY_AGAIN: ::c_int = 4;
}
}
pub const NO_ADDRESS: ::c_int = 2;
pub const NO_RECOVERY: ::c_int = 3;
pub const TRY_AGAIN: ::c_int = 4;

pub const AI_PASSIVE: ::c_int = 1;
pub const AI_CANONNAME: ::c_int = 2;
pub const AI_NUMERICHOST: ::c_int = 4;
pub const AI_NUMERICSERV: ::c_int = 0;
pub const AI_ADDRCONFIG: ::c_int = 0;
cfg_if! {
if #[cfg(target_os = "espidf")] {
pub const AI_NUMERICSERV: ::c_int = 8;
pub const AI_ADDRCONFIG: ::c_int = 64;
} else {
pub const AI_NUMERICSERV: ::c_int = 0;
pub const AI_ADDRCONFIG: ::c_int = 0;
}
}

pub const NI_MAXHOST: ::c_int = 1025;
pub const NI_MAXSERV: ::c_int = 32;
pub const NI_NOFQDN: ::c_int = 1;
pub const NI_NUMERICHOST: ::c_int = 2;
pub const NI_NAMEREQD: ::c_int = 4;
pub const NI_NUMERICSERV: ::c_int = 0;
pub const NI_DGRAM: ::c_int = 0;
cfg_if! {
if #[cfg(target_os = "espidf")] {
pub const NI_NUMERICSERV: ::c_int = 8;
pub const NI_DGRAM: ::c_int = 16;
} else {
pub const NI_NUMERICSERV: ::c_int = 0;
pub const NI_DGRAM: ::c_int = 0;
}
}

cfg_if! {
// Defined in vita/mod.rs for "vita"
if #[cfg(not(target_os = "vita"))] {
if #[cfg(target_os = "espidf")] {
pub const EAI_FAMILY: ::c_int = 204;
pub const EAI_MEMORY: ::c_int = 203;
pub const EAI_NONAME: ::c_int = 200;
pub const EAI_SOCKTYPE: ::c_int = 10;
} else if #[cfg(not(target_os = "vita"))] {
pub const EAI_FAMILY: ::c_int = -303;
pub const EAI_MEMORY: ::c_int = -304;
pub const EAI_NONAME: ::c_int = -305;
Expand Down

0 comments on commit 133d9d0

Please sign in to comment.