Skip to content

Commit 9b640d5

Browse files
committed
Fix on 32bit platforms
1 parent 772aa42 commit 9b640d5

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

src/sys/socket/mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ pub use libc::{
3535
in_addr,
3636
in6_addr,
3737
sockaddr,
38-
sockaddr_storage,
3938
sockaddr_in,
4039
sockaddr_in6,
4140
sockaddr_un,
@@ -47,6 +46,17 @@ pub use self::multicast::{
4746
};
4847
pub use self::consts::*;
4948

49+
#[cfg(any(not(target_os = "linux"), not(target_arch = "x86")))]
50+
pub use libc::sockaddr_storage;
51+
52+
// Working around rust-lang/rust#23425
53+
#[cfg(all(target_os = "linux", target_arch = "x86"))]
54+
pub struct sockaddr_storage {
55+
pub ss_family: sa_family_t,
56+
pub __ss_align: u32,
57+
pub __ss_pad2: [u8; 120],
58+
}
59+
5060
#[derive(Copy, PartialEq, Eq, Debug, FromPrimitive)]
5161
#[repr(i32)]
5262
pub enum SockType {

src/sys/time.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::{fmt, ops};
22
use std::num::Int;
3-
use std::i64;
43
use libc::{time_t, suseconds_t};
54

65
#[repr(C)]
@@ -14,15 +13,13 @@ const MICROS_PER_SEC: i64 = 1_000_000;
1413
const SECS_PER_MINUTE: i64 = 60;
1514
const SECS_PER_HOUR: i64 = 3600;
1615

17-
const MIN: TimeVal = TimeVal {
18-
tv_sec: -(i64::MAX / MICROS_PER_SEC - 1),
19-
tv_usec: (-(MICROS_PER_SEC - 1)) as suseconds_t,
20-
};
16+
#[cfg(target_pointer_width = "64")]
17+
const MAX_SECONDS: i64 = (::std::i64::MAX / MICROS_PER_SEC) - 1;
2118

22-
const MAX: TimeVal = TimeVal {
23-
tv_sec: i64::MAX / MICROS_PER_SEC - 1,
24-
tv_usec: (MICROS_PER_SEC - 1) as suseconds_t,
25-
};
19+
#[cfg(target_pointer_width = "32")]
20+
const MAX_SECONDS: i64 = ::std::isize::MAX as i64;
21+
22+
const MIN_SECONDS: i64 = -MAX_SECONDS;
2623

2724
impl TimeVal {
2825
#[inline]
@@ -48,9 +45,8 @@ impl TimeVal {
4845

4946
#[inline]
5047
pub fn seconds(seconds: i64) -> TimeVal {
51-
let ret = TimeVal { tv_sec: seconds, tv_usec: 0 };
52-
assert!(ret >= MIN && ret <= MAX, "TimeVal out of bounds");
53-
ret
48+
assert!(seconds >= MIN_SECONDS && seconds <= MAX_SECONDS, "TimeVal out of bounds; seconds={}", seconds);
49+
TimeVal { tv_sec: seconds as time_t, tv_usec: 0 }
5450
}
5551

5652
#[inline]
@@ -66,9 +62,8 @@ impl TimeVal {
6662
#[unstable(feature = "std_misc")]
6763
pub fn microseconds(microseconds: i64) -> TimeVal {
6864
let (secs, micros) = div_mod_floor_64(microseconds, MICROS_PER_SEC);
69-
let ret = TimeVal { tv_sec: secs, tv_usec: micros as suseconds_t };
70-
assert!(ret >= MIN && ret <= MAX, "TimeVal out of bounds");
71-
ret
65+
assert!(secs >= MIN_SECONDS && secs <= MAX_SECONDS, "TimeVal out of bounds");
66+
TimeVal { tv_sec: secs as time_t, tv_usec: micros as suseconds_t }
7267
}
7368

7469
pub fn num_hours(&self) -> i64 {
@@ -81,9 +76,9 @@ impl TimeVal {
8176

8277
pub fn num_seconds(&self) -> i64 {
8378
if self.tv_sec < 0 && self.tv_usec > 0 {
84-
self.tv_sec + 1
79+
(self.tv_sec + 1) as i64
8580
} else {
86-
self.tv_sec
81+
self.tv_sec as i64
8782
}
8883
}
8984

0 commit comments

Comments
 (0)