timestamped_socket/
lib.rs1use statime_base::Timestamp;
4
5mod control_message;
6pub mod interface;
8pub mod networkaddress;
10mod raw_socket;
11pub mod socket;
13
14pub(crate) fn cerr(t: libc::c_int) -> std::io::Result<libc::c_int> {
16 match t {
17 -1 => Err(std::io::Error::last_os_error()),
18 _ => Ok(t),
19 }
20}
21
22#[cfg_attr(target_os = "macos", allow(unused))]
24#[expect(
25 clippy::cast_sign_loss,
26 reason = "tv_usec is always in range for the nanos field."
27)]
28#[allow(
29 clippy::cast_possible_truncation,
30 reason = "tv_usec is always in range for the conversion."
31)]
32#[allow(
33 clippy::cast_lossless,
34 reason = "cast is not lossless on all platforms."
35)]
36fn timestamp_from_timespec<T>(timespec: libc::timespec) -> Timestamp<T> {
37 Timestamp::from_seconds_nanos_since_unix_epoch(timespec.tv_sec as _, timespec.tv_nsec as _)
38}
39
40#[expect(
42 clippy::cast_sign_loss,
43 reason = "tv_usec is always in range for the nanos field."
44)]
45#[allow(
46 clippy::cast_possible_truncation,
47 reason = "tv_usec is always in range for the conversion."
48)]
49#[allow(
50 clippy::cast_lossless,
51 reason = "cast is not lossless on all platforms."
52)]
53fn timestamp_from_timeval<T>(timeval: libc::timeval) -> Timestamp<T> {
54 Timestamp::from_seconds_nanos_since_unix_epoch(
55 timeval.tv_sec as _,
56 (timeval.tv_usec * 1000) as _,
57 )
58}