Skip to content

Commit

Permalink
Merge pull request #15 from Rayzeq/master
Browse files Browse the repository at this point in the history
Permit making blocking sockets
  • Loading branch information
bltavares authored Jul 27, 2023
2 parents dc1868d + fa21881 commit a82567e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Duration>,
pub loopback: bool,
pub buffer_size: usize,
/// The address to bind the socket to.
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn create_on_interfaces(
multicast_address: SocketAddrV4,
) -> io::Result<MulticastSocket> {
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)?;
Expand Down
2 changes: 1 addition & 1 deletion src/win.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn create_on_interfaces(
multicast_address: SocketAddrV4,
) -> io::Result<MulticastSocket> {
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)?;

Expand Down

0 comments on commit a82567e

Please # to comment.