Skip to content

Commit

Permalink
Add a mean to set the local address in the perf_client
Browse files Browse the repository at this point in the history
  • Loading branch information
lu-zero authored and djc committed May 24, 2021
1 parent 8c89bfb commit 5ab895b
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions perf/src/bin/perf_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ struct Opt {
/// Receive buffer size in bytes
#[structopt(long, default_value = "2097152")]
recv_buffer_size: usize,
/// Specify the local socket address
#[structopt(long)]
local_addr: Option<SocketAddr>,
}

#[tokio::main(flavor = "current_thread")]
Expand Down Expand Up @@ -79,17 +82,18 @@ async fn run(opt: Opt) -> Result<()> {

info!("connecting to {} at {}", host_name, addr);

let bind_addr = if addr.is_ipv4() {
Ipv4Addr::UNSPECIFIED.into()
} else {
Ipv6Addr::UNSPECIFIED.into()
};
let bind_addr = opt.local_addr.unwrap_or_else(|| {
let unspec = if addr.is_ipv4() {
Ipv4Addr::UNSPECIFIED.into()
} else {
Ipv6Addr::UNSPECIFIED.into()
};
SocketAddr::new(unspec, 0)
});

info!("local addr {:?}", bind_addr);

let socket = bind_socket(
SocketAddr::new(bind_addr, 0),
opt.send_buffer_size,
opt.recv_buffer_size,
)?;
let socket = bind_socket(bind_addr, opt.send_buffer_size, opt.recv_buffer_size)?;

let endpoint = quinn::EndpointBuilder::default();

Expand Down

0 comments on commit 5ab895b

Please sign in to comment.