Skip to content

Commit 1b4ed63

Browse files
TODO: TX_TIME is invalid for some reason
1 parent 0b19199 commit 1b4ed63

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

dgram/src/syscalls.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub fn send_msg(
6363
cmsgs.push(ControlMessage::TxTime(&raw_time));
6464
}
6565

66+
let client_addr = dst.map(SockaddrStorage::from);
6667
raw_send_to(
6768
&fd.as_fd(),
6869
send_buf,
@@ -76,8 +77,9 @@ pub fn send_msg(
7677
#[cfg(target_os = "linux")]
7778
pub fn send_with_cmsgs(
7879
fd: impl AsFd, send_buf: &[u8], cmsgs: &[ControlMessage],
79-
client_addr: &SockaddrStorage,
80+
dst: Option<SocketAddr>,
8081
) -> SyscallResult<usize> {
82+
let client_addr = dst.map(SockaddrStorage::from);
8183
raw_send_to(&fd.as_fd(), send_buf, cmsgs, MsgFlags::empty(), client_addr)
8284
}
8385

@@ -160,6 +162,19 @@ pub fn recv_msg(
160162
}
161163
}
162164

165+
fn std_time_to_u64(time: &Instant) -> u64 {
166+
const NANOS_PER_SEC: u64 = 1_000_000_000;
167+
const INSTANT_ZERO: std::time::Instant =
168+
unsafe { std::mem::transmute(std::time::UNIX_EPOCH) };
169+
170+
let raw_time = time.duration_since(INSTANT_ZERO);
171+
172+
let sec = raw_time.as_secs();
173+
let nsec = raw_time.subsec_nanos();
174+
175+
sec * NANOS_PER_SEC + nsec as u64
176+
}
177+
163178
#[cfg(all(test, target_os = "linux", not(target_os = "android")))]
164179
mod tests {
165180
use nix::cmsg_space;
@@ -315,7 +330,7 @@ mod tests {
315330

316331
send_msg(send, send_buf, SendMsgCmsgSettings {
317332
segment_size: None,
318-
tx_time: Some(Instant::now() + std::time::Duration::from_millis(5)),
333+
tx_time: Some(Instant::now() + std::time::Duration::from_secs(5)),
319334
dst: addr,
320335
})?;
321336

0 commit comments

Comments
 (0)