aquatic udp load test: use socket2 instead of net2

This commit is contained in:
Joakim Frostegård 2020-05-25 18:42:23 +02:00
parent 96991562e3
commit 5babd8eda0
3 changed files with 13 additions and 27 deletions

13
Cargo.lock generated
View file

@ -81,13 +81,13 @@ dependencies = [
"hashbrown",
"mimalloc",
"mio",
"net2",
"parking_lot",
"quickcheck",
"quickcheck_macros",
"rand",
"rand_distr",
"serde",
"socket2",
]
[[package]]
@ -704,17 +704,6 @@ dependencies = [
"tempfile",
]
[[package]]
name = "net2"
version = "0.2.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ba7c918ac76704fb42afcbbb43891e72731f3dcca3bef2a19786297baf14af7"
dependencies = [
"cfg-if",
"libc",
"winapi",
]
[[package]]
name = "nix"
version = "0.16.1"

View file

@ -16,11 +16,11 @@ crossbeam-channel = "0.4"
hashbrown = "0.7"
mimalloc = { version = "0.1", default-features = false }
mio = { version = "0.7", features = ["udp", "os-poll", "os-util"] }
net2 = "0.2"
parking_lot = "0.10"
rand = { version = "0.7", features = ["small_rng"] }
rand_distr = "0.2"
serde = { version = "1", features = ["derive"] }
socket2 = { version = "0.3", features = ["reuseport"] }
[dev-dependencies]
quickcheck = "0.9"

View file

@ -5,7 +5,7 @@ use std::time::Duration;
use crossbeam_channel::{Receiver, Sender};
use mio::{net::UdpSocket, Events, Poll, Interest, Token};
use net2::{UdpSocketExt, UdpBuilder};
use socket2::{Socket, Domain, Type, Protocol};
use bittorrent_udp::converters::*;
use bittorrent_udp::types::*;
@ -20,17 +20,11 @@ pub fn create_socket(
config: &Config,
addr: SocketAddr
) -> ::std::net::UdpSocket {
let builder = &{
if addr.is_ipv4(){
UdpBuilder::new_v4().expect("socket: build")
} else {
UdpBuilder::new_v6().expect("socket: build")
}
};
let socket = builder.bind(&addr)
.expect(&format!("socket: bind to {}", addr));
let socket = if addr.is_ipv4(){
Socket::new(Domain::ipv4(), Type::dgram(), Some(Protocol::udp()))
} else {
Socket::new(Domain::ipv6(), Type::dgram(), Some(Protocol::udp()))
}.expect("create socket");
socket.set_nonblocking(true)
.expect("socket: set nonblocking");
@ -45,10 +39,13 @@ pub fn create_socket(
}
}
socket.connect(config.server_address)
socket.bind(&addr.into())
.expect(&format!("socket: bind to {}", addr));
socket.connect(&config.server_address.into())
.expect("socket: connect to server");
socket
socket.into_udp_socket()
}