1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//! Standard library UDP socket adapter for the [`sntpc`] SNTP client library.
//!
//! This crate provides a thin wrapper around [`std::net::UdpSocket`] that implements
//! the [`NtpUdpSocket`] trait, allowing it to be used with the `sntpc` library for
//! synchronous SNTP requests.
//!
//! # Design Rationale
//!
//! The network adapters are separated into their own crates to:
//! - Allow independent versioning of network implementations
//! - Minimize dependencies (only `std` and `sntpc` core required)
//! - Enable users to choose their preferred network stack
//!
//! # Example
//!
//! ```ignore
//! use sntpc::{sync::get_time, NtpContext, StdTimestampGen};
//! use sntpc_net_std::UdpSocketWrapper;
//! use std::net::UdpSocket;
//!
//! let socket = UdpSocket::bind("0.0.0.0:0").expect("Unable to create UDP socket");
//! socket.set_read_timeout(Some(std::time::Duration::from_secs(2)))
//! .expect("Unable to set read timeout");
//! let socket = UdpSocketWrapper::new(socket);
//! let context = NtpContext::new(StdTimestampGen::default());
//!
//! let result = get_time("pool.ntp.org:123".parse().unwrap(), &socket, context);
//! match result {
//! Ok(time) => println!("Received time: {}.{}", time.sec(), time.sec_fraction()),
//! Err(e) => eprintln!("Failed to get time: {:?}", e),
//! }
//! ```
//!
//! For more examples, see the [repository examples](https://github.com/vpetrigo/sntpc/tree/master/examples).
use ;
use ;
/// A wrapper around [`std::net::UdpSocket`] that implements [`NtpUdpSocket`].
///
/// This type allows standard library UDP sockets to be used with the `sntpc` library
/// for making SNTP requests. It provides a simple synchronous interface suitable for
/// blocking I/O operations.
///
/// # Example
///
/// ```no_run
/// use sntpc_net_std::UdpSocketWrapper;
/// use std::net::UdpSocket;
///
/// let socket = UdpSocket::bind("0.0.0.0:0").expect("Failed to bind socket");
/// let wrapper = UdpSocketWrapper::new(socket);
/// // Use wrapper with sntpc functions
/// ```