Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial networking stack with software timestamping #52

Merged
merged 3 commits into from
Apr 28, 2022
Merged

Conversation

rnijveld
Copy link
Member

@rnijveld rnijveld commented Apr 28, 2022

Right now the receive timestamp is returned via an output parameter. I think it could be made to return as a return value just as easily, but this might feel more natural in places where a normal recv could also be used.

See #14

@rnijveld rnijveld changed the title Initial networking stack Initial networking stack with software timestamping Apr 28, 2022
@davidv1992 davidv1992 merged commit 58730ad into main Apr 28, 2022
@davidv1992 davidv1992 deleted the ntp-udp branch April 28, 2022 11:26
fn recv(
socket: &std::net::UdpSocket,
buf: &mut [u8],
recv_ts: &mut Option<NtpTimestamp>,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a &mut Option as an outparam seems pretty unidiomatic. I think it would definitely be better to return a tuple (why do we think callers will be interested in the length of the read?).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely! So the final version already changed that! The length of the read would mostly be important to ensure that the buffer was filled with the expected number of bytes and not fewer than expected.

@@ -24,7 +24,7 @@ async fn setup_connection() -> std::io::Result<UdpSocket> {

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let socket = setup_connection().await?;
let socket = ntp_udp::UdpSocket::from_tokio(setup_connection().await?)?;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not add a basic constructor to ntp_udp::UdpSocket that takes the source and destination addresses, and move that functionality out of this crate's setup_connection()? That seems a simpler design. (I would probably skip having the from_std() and from_tokio() constructors unless they add value for testing.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants