From fa21881d65c8408f4ded74a0c37d25104171e6f7 Mon Sep 17 00:00:00 2001 From: Rayzeq Date: Wed, 26 Jul 2023 11:18:58 +0200 Subject: [PATCH] Permit making blocking sockets --- src/lib.rs | 7 +++++-- src/unix.rs | 2 +- src/win.rs | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2c70d3d..fea645b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,10 @@ mod unix; pub use unix::*; pub struct MulticastOptions { - pub read_timeout: Duration, + /// The maximal timeout before [`MulticastSocket::receive`] returns. + /// + /// If this is `None`, [`MulticastSocket::receive`] will block until there is data to read. + pub read_timeout: Option, pub loopback: bool, pub buffer_size: usize, /// The address to bind the socket to. @@ -25,7 +28,7 @@ pub struct MulticastOptions { impl Default for MulticastOptions { fn default() -> Self { MulticastOptions { - read_timeout: Duration::from_secs(1), + read_timeout: Some(Duration::from_secs(1)), loopback: true, buffer_size: 512, bind_address: Ipv4Addr::UNSPECIFIED, diff --git a/src/unix.rs b/src/unix.rs index 14da45c..a0dbcbe 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -15,7 +15,7 @@ fn create_on_interfaces( multicast_address: SocketAddrV4, ) -> io::Result { let socket = Socket::new(Domain::ipv4(), Type::dgram(), Some(Protocol::udp()))?; - socket.set_read_timeout(Some(options.read_timeout))?; + socket.set_read_timeout(options.read_timeout)?; socket.set_multicast_loop_v4(options.loopback)?; socket.set_reuse_address(true)?; socket.set_reuse_port(true)?; diff --git a/src/win.rs b/src/win.rs index 54692b8..f404fd2 100644 --- a/src/win.rs +++ b/src/win.rs @@ -141,7 +141,7 @@ fn create_on_interfaces( multicast_address: SocketAddrV4, ) -> io::Result { let socket = Socket::new(Domain::ipv4(), Type::dgram(), Some(Protocol::udp()))?; - socket.set_read_timeout(Some(options.read_timeout))?; + socket.set_read_timeout(options.read_timeout)?; socket.set_multicast_loop_v4(options.loopback)?; socket.set_reuse_address(true)?;