From aa88c40a9e8e881d9ffe10fdc6dde52d58edffc7 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Tue, 4 Jun 2019 20:55:02 -0700 Subject: [PATCH] multi_bind_in_range(): limit to 1 socket in windows (#4549) --- netutil/src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/netutil/src/lib.rs b/netutil/src/lib.rs index 84d0f2012..5871ae551 100644 --- a/netutil/src/lib.rs +++ b/netutil/src/lib.rs @@ -1,4 +1,5 @@ //! The `netutil` module assists with networking +use log::*; use rand::{thread_rng, Rng}; use socket2::{Domain, SockAddr, Socket, Type}; use std::io; @@ -156,7 +157,15 @@ pub fn bind_in_range(range: PortRange) -> io::Result<(u16, UdpSocket)> { } // binds many sockets to the same port in a range -pub fn multi_bind_in_range(range: PortRange, num: usize) -> io::Result<(u16, Vec)> { +pub fn multi_bind_in_range(range: PortRange, mut num: usize) -> io::Result<(u16, Vec)> { + if cfg!(windows) && num != 1 { + // TODO: Can we do better for windows? + warn!( + "multi_bind_in_range() only supports 1 socket in windows ({} requested)", + num + ); + num = 1; + } let mut sockets = Vec::with_capacity(num); let port = {