multi_bind_in_range(): limit to 1 socket in windows (#4549)

This commit is contained in:
Michael Vines 2019-06-04 20:55:02 -07:00 committed by GitHub
parent 8ec5a47027
commit aa88c40a9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

View File

@ -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<UdpSocket>)> {
pub fn multi_bind_in_range(range: PortRange, mut num: usize) -> io::Result<(u16, Vec<UdpSocket>)> {
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 = {