Skip to content

Commit 133d9d0

Browse files
committed
fix: Update ESP-IDF constants
1 parent 1b11393 commit 133d9d0

File tree

2 files changed

+120
-30
lines changed

2 files changed

+120
-30
lines changed

src/unix/newlib/espidf/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ pub const MSG_EOR: ::c_int = 0x08;
8989

9090
pub const PTHREAD_STACK_MIN: ::size_t = 768;
9191

92-
pub const SIGABRT: ::c_int = 1;
93-
pub const SIGFPE: ::c_int = 1;
94-
pub const SIGILL: ::c_int = 1;
95-
pub const SIGINT: ::c_int = 1;
96-
pub const SIGSEGV: ::c_int = 1;
97-
pub const SIGTERM: ::c_int = 1;
92+
pub const SIGABRT: ::c_int = 6;
93+
pub const SIGFPE: ::c_int = 8;
94+
pub const SIGILL: ::c_int = 4;
95+
pub const SIGINT: ::c_int = 2;
96+
pub const SIGSEGV: ::c_int = 11;
97+
pub const SIGTERM: ::c_int = 15;
9898
pub const SIGHUP: ::c_int = 1;
99-
pub const SIGQUIT: ::c_int = 1;
100-
pub const NSIG: ::size_t = 2;
99+
pub const SIGQUIT: ::c_int = 3;
100+
pub const NSIG: ::size_t = 32;
101101

102102
extern "C" {
103103
pub fn pthread_create(

src/unix/newlib/mod.rs

Lines changed: 112 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ cfg_if! {
4242
pub type socklen_t = u32;
4343
pub type speed_t = u32;
4444
pub type suseconds_t = i32;
45-
pub type tcflag_t = ::c_uint;
45+
cfg_if! {
46+
if #[cfg(target_os = "espidf")] {
47+
pub type tcflag_t = u16;
48+
} else {
49+
pub type tcflag_t = ::c_uint;
50+
}
51+
}
4652
pub type useconds_t = u32;
4753

4854
cfg_if! {
@@ -241,7 +247,14 @@ pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
241247
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
242248
size: [__PTHREAD_INITIALIZER_BYTE; __SIZEOF_PTHREAD_RWLOCK_T],
243249
};
244-
pub const NCCS: usize = 32;
250+
251+
cfg_if! {
252+
if #[cfg(target_os = "espidf")] {
253+
pub const NCCS: usize = 11;
254+
} else {
255+
pub const NCCS: usize = 32;
256+
}
257+
}
245258

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

412425
pub const O_ACCMODE: ::c_int = 3;
413-
pub const O_CLOEXEC: ::c_int = 0x80000;
426+
cfg_if! {
427+
if #[cfg(target_os = "espidf")] {
428+
pub const O_CLOEXEC: ::c_int = 0x40000;
429+
} else {
430+
pub const O_CLOEXEC: ::c_int = 0x80000;
431+
}
432+
}
414433

415434
pub const RTLD_LAZY: ::c_int = 0x1;
416435

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

453472
pub const PF_UNSPEC: ::c_int = 0;
454473
pub const PF_INET: ::c_int = 2;
455-
pub const PF_INET6: ::c_int = 23;
474+
cfg_if! {
475+
if #[cfg(target_os = "espidf")] {
476+
pub const PF_INET6: ::c_int = 10;
477+
} else {
478+
pub const PF_INET6: ::c_int = 23;
479+
}
480+
}
456481

457482
pub const AF_UNSPEC: ::c_int = 0;
458483
pub const AF_INET: ::c_int = 2;
@@ -537,6 +562,9 @@ cfg_if! {
537562
if #[cfg(target_os = "vita")] {
538563
pub const TCP_NODELAY: ::c_int = 1;
539564
pub const TCP_MAXSEG: ::c_int = 2;
565+
} else if #[cfg(target_os = "espidf")] {
566+
pub const TCP_NODELAY: ::c_int = 1;
567+
pub const TCP_MAXSEG: ::c_int = 8194;
540568
} else {
541569
pub const TCP_NODELAY: ::c_int = 8193;
542570
pub const TCP_MAXSEG: ::c_int = 8194;
@@ -545,69 +573,131 @@ cfg_if! {
545573

546574
pub const TCP_NOPUSH: ::c_int = 4;
547575
pub const TCP_NOOPT: ::c_int = 8;
548-
pub const TCP_KEEPIDLE: ::c_int = 256;
549-
pub const TCP_KEEPINTVL: ::c_int = 512;
550-
pub const TCP_KEEPCNT: ::c_int = 1024;
576+
cfg_if! {
577+
if #[cfg(target_os = "espidf")] {
578+
pub const TCP_KEEPIDLE: ::c_int = 3;
579+
pub const TCP_KEEPINTVL: ::c_int = 4;
580+
pub const TCP_KEEPCNT: ::c_int = 5;
581+
} else {
582+
pub const TCP_KEEPIDLE: ::c_int = 256;
583+
pub const TCP_KEEPINTVL: ::c_int = 512;
584+
pub const TCP_KEEPCNT: ::c_int = 1024;
585+
}
586+
}
551587

552588
cfg_if! {
553589
if #[cfg(target_os = "horizon")] {
554590
pub const IP_TOS: ::c_int = 7;
591+
} else if #[cfg(target_os = "espidf")] {
592+
pub const IP_TOS: ::c_int = 1;
555593
} else {
556594
pub const IP_TOS: ::c_int = 3;
557595
}
558596
}
559597
cfg_if! {
560598
if #[cfg(target_os = "vita")] {
561599
pub const IP_TTL: ::c_int = 4;
600+
} else if #[cfg(target_os = "espidf")] {
601+
pub const IP_TTL: ::c_int = 2;
562602
} else {
563603
pub const IP_TTL: ::c_int = 8;
564604
}
565605
}
566-
pub const IP_MULTICAST_IF: ::c_int = 9;
567-
pub const IP_MULTICAST_TTL: ::c_int = 10;
568-
pub const IP_MULTICAST_LOOP: ::c_int = 11;
606+
607+
cfg_if! {
608+
if #[cfg(target_os = "espidf")] {
609+
pub const IP_MULTICAST_IF: ::c_int = 6;
610+
pub const IP_MULTICAST_TTL: ::c_int = 5;
611+
pub const IP_MULTICAST_LOOP: ::c_int = 7;
612+
} else {
613+
pub const IP_MULTICAST_IF: ::c_int = 9;
614+
pub const IP_MULTICAST_TTL: ::c_int = 10;
615+
pub const IP_MULTICAST_LOOP: ::c_int = 11;
616+
}
617+
}
618+
569619
cfg_if! {
570620
if #[cfg(target_os = "vita")] {
571621
pub const IP_ADD_MEMBERSHIP: ::c_int = 12;
572622
pub const IP_DROP_MEMBERSHIP: ::c_int = 13;
623+
} else if #[cfg(target_os = "espidf")] {
624+
pub const IP_ADD_MEMBERSHIP: ::c_int = 3;
625+
pub const IP_DROP_MEMBERSHIP: ::c_int = 4;
573626
} else {
574627
pub const IP_ADD_MEMBERSHIP: ::c_int = 11;
575628
pub const IP_DROP_MEMBERSHIP: ::c_int = 12;
576629
}
577630
}
578631
pub const IPV6_UNICAST_HOPS: ::c_int = 4;
579-
pub const IPV6_MULTICAST_IF: ::c_int = 9;
580-
pub const IPV6_MULTICAST_HOPS: ::c_int = 10;
581-
pub const IPV6_MULTICAST_LOOP: ::c_int = 11;
632+
cfg_if! {
633+
if #[cfg(target_os = "espidf")] {
634+
pub const IPV6_MULTICAST_IF: ::c_int = 768;
635+
pub const IPV6_MULTICAST_HOPS: ::c_int = 769;
636+
pub const IPV6_MULTICAST_LOOP: ::c_int = 770;
637+
} else {
638+
pub const IPV6_MULTICAST_IF: ::c_int = 9;
639+
pub const IPV6_MULTICAST_HOPS: ::c_int = 10;
640+
pub const IPV6_MULTICAST_LOOP: ::c_int = 11;
641+
}
642+
}
582643
pub const IPV6_V6ONLY: ::c_int = 27;
583644
pub const IPV6_JOIN_GROUP: ::c_int = 12;
584645
pub const IPV6_LEAVE_GROUP: ::c_int = 13;
585646
pub const IPV6_ADD_MEMBERSHIP: ::c_int = 12;
586647
pub const IPV6_DROP_MEMBERSHIP: ::c_int = 13;
587648

588-
pub const HOST_NOT_FOUND: ::c_int = 1;
589-
pub const NO_DATA: ::c_int = 2;
649+
cfg_if! {
650+
if #[cfg(target_os = "espidf")] {
651+
pub const HOST_NOT_FOUND: ::c_int = 210;
652+
pub const NO_DATA: ::c_int = 211;
653+
pub const NO_RECOVERY: ::c_int = 212;
654+
pub const TRY_AGAIN: ::c_int = 213;
655+
656+
} else {
657+
pub const HOST_NOT_FOUND: ::c_int = 1;
658+
pub const NO_DATA: ::c_int = 2;
659+
pub const NO_RECOVERY: ::c_int = 3;
660+
pub const TRY_AGAIN: ::c_int = 4;
661+
}
662+
}
590663
pub const NO_ADDRESS: ::c_int = 2;
591-
pub const NO_RECOVERY: ::c_int = 3;
592-
pub const TRY_AGAIN: ::c_int = 4;
593664

594665
pub const AI_PASSIVE: ::c_int = 1;
595666
pub const AI_CANONNAME: ::c_int = 2;
596667
pub const AI_NUMERICHOST: ::c_int = 4;
597-
pub const AI_NUMERICSERV: ::c_int = 0;
598-
pub const AI_ADDRCONFIG: ::c_int = 0;
668+
cfg_if! {
669+
if #[cfg(target_os = "espidf")] {
670+
pub const AI_NUMERICSERV: ::c_int = 8;
671+
pub const AI_ADDRCONFIG: ::c_int = 64;
672+
} else {
673+
pub const AI_NUMERICSERV: ::c_int = 0;
674+
pub const AI_ADDRCONFIG: ::c_int = 0;
675+
}
676+
}
599677

600678
pub const NI_MAXHOST: ::c_int = 1025;
601679
pub const NI_MAXSERV: ::c_int = 32;
602680
pub const NI_NOFQDN: ::c_int = 1;
603681
pub const NI_NUMERICHOST: ::c_int = 2;
604682
pub const NI_NAMEREQD: ::c_int = 4;
605-
pub const NI_NUMERICSERV: ::c_int = 0;
606-
pub const NI_DGRAM: ::c_int = 0;
683+
cfg_if! {
684+
if #[cfg(target_os = "espidf")] {
685+
pub const NI_NUMERICSERV: ::c_int = 8;
686+
pub const NI_DGRAM: ::c_int = 16;
687+
} else {
688+
pub const NI_NUMERICSERV: ::c_int = 0;
689+
pub const NI_DGRAM: ::c_int = 0;
690+
}
691+
}
607692

608693
cfg_if! {
609694
// Defined in vita/mod.rs for "vita"
610-
if #[cfg(not(target_os = "vita"))] {
695+
if #[cfg(target_os = "espidf")] {
696+
pub const EAI_FAMILY: ::c_int = 204;
697+
pub const EAI_MEMORY: ::c_int = 203;
698+
pub const EAI_NONAME: ::c_int = 200;
699+
pub const EAI_SOCKTYPE: ::c_int = 10;
700+
} else if #[cfg(not(target_os = "vita"))] {
611701
pub const EAI_FAMILY: ::c_int = -303;
612702
pub const EAI_MEMORY: ::c_int = -304;
613703
pub const EAI_NONAME: ::c_int = -305;

0 commit comments

Comments
 (0)