|
| 1 | +use dox::mem; |
| 2 | + |
1 | 3 | pub type c_char = i8;
|
2 | 4 | pub type c_long = i64;
|
3 | 5 | pub type c_ulong = u64;
|
@@ -27,7 +29,7 @@ pub type off_t = i64;
|
27 | 29 | pub type useconds_t = ::c_uint;
|
28 | 30 | pub type socklen_t = u32;
|
29 | 31 | pub type sa_family_t = u8;
|
30 |
| -pub type pthread_t = ::uintptr_t; |
| 32 | +pub type pthread_t = ::c_uint; |
31 | 33 | pub type pthread_key_t = ::c_uint;
|
32 | 34 | pub type blksize_t = u32;
|
33 | 35 | pub type fflags_t = u32;
|
|
123 | 125 | }
|
124 | 126 |
|
125 | 127 | pub struct fd_set {
|
| 128 | + #[cfg(target_pointer_width = "64")] |
| 129 | + fds_bits: [i64; FD_SETSIZE / 64], |
| 130 | + #[cfg(target_pointer_width = "32")] |
126 | 131 | fds_bits: [i32; FD_SETSIZE / 32],
|
127 | 132 | }
|
128 | 133 |
|
@@ -448,6 +453,9 @@ pub const SIG_SETMASK: ::c_int = 3;
|
448 | 453 | pub const IPV6_MULTICAST_LOOP: ::c_int = 0x8;
|
449 | 454 | pub const IPV6_V6ONLY: ::c_int = 0x27;
|
450 | 455 |
|
| 456 | +#[cfg(target_pointer_width = "64")] |
| 457 | +pub const FD_SETSIZE: usize = 65536; |
| 458 | +#[cfg(target_pointer_width = "32")] |
451 | 459 | pub const FD_SETSIZE: usize = 1024;
|
452 | 460 |
|
453 | 461 | pub const ST_RDONLY: ::c_ulong = 1;
|
@@ -946,19 +954,22 @@ pub const RTLD_CONFGEN: ::c_int = 0x10000;
|
946 | 954 |
|
947 | 955 | f! {
|
948 | 956 | pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () {
|
| 957 | + let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8; |
949 | 958 | let fd = fd as usize;
|
950 |
| - (*set).fds_bits[fd / 32] &= !(1 << (fd % 32)); |
| 959 | + (*set).fds_bits[fd / bits] &= !(1 << (fd % bits)); |
951 | 960 | return
|
952 | 961 | }
|
953 | 962 |
|
954 | 963 | pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool {
|
| 964 | + let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8; |
955 | 965 | let fd = fd as usize;
|
956 |
| - return ((*set).fds_bits[fd / 32] & (1 << (fd % 32))) != 0 |
| 966 | + return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0 |
957 | 967 | }
|
958 | 968 |
|
959 | 969 | pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () {
|
| 970 | + let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8; |
960 | 971 | let fd = fd as usize;
|
961 |
| - (*set).fds_bits[fd / 32] |= 1 << (fd % 32); |
| 972 | + (*set).fds_bits[fd / bits] |= 1 << (fd % bits); |
962 | 973 | return
|
963 | 974 | }
|
964 | 975 |
|
|
0 commit comments