Skip to content

Commit

Permalink
Simplify listen address configuration impl details
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralith authored and stammw committed Apr 2, 2020
1 parent 2e49daa commit 8af413c
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions quinn-h3/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{
future::Future,
mem,
net::SocketAddr,
net::{Ipv6Addr, SocketAddr, SocketAddrV6},
pin::Pin,
task::{Context, Poll},
};
Expand Down Expand Up @@ -31,20 +31,13 @@ use crate::{
#[derive(Clone)]
pub struct Builder {
config: quinn::ServerConfigBuilder,
listen: Option<SocketAddr>,
listen: SocketAddr,
settings: Settings,
}

impl Default for Builder {
fn default() -> Self {
let mut config = quinn::ServerConfigBuilder::default();
config.protocols(&[crate::ALPN]);

Self {
config,
listen: None,
settings: Settings::new(),
}
Self::with_quic_config(quinn::ServerConfigBuilder::default())
}
}

Expand All @@ -53,13 +46,13 @@ impl Builder {
config.protocols(&[crate::ALPN]);
Self {
config,
listen: None,
listen: SocketAddrV6::new(Ipv6Addr::UNSPECIFIED, 4433, 0, 0).into(),
settings: Settings::new(),
}
}

pub fn listen(&mut self, addr: SocketAddr) -> &mut Self {
self.listen = Some(addr);
self.listen = addr;
self
}

Expand All @@ -81,10 +74,7 @@ impl Builder {
self,
endpoint: EndpointBuilder,
) -> Result<(Server, IncomingConnection), quinn::EndpointError> {
let listen = self
.listen
.unwrap_or_else(|| "[::]:4433".parse().expect("valid listen address"));
let (_, incoming) = endpoint.bind(&listen)?;
let (_, incoming) = endpoint.bind(&self.listen)?;

Ok((
Server,
Expand All @@ -99,10 +89,7 @@ impl Builder {
let mut endpoint_builder = quinn::Endpoint::builder();
endpoint_builder.listen(self.config.build());

let listen = self
.listen
.unwrap_or_else(|| "[::]:4433".parse().expect("valid listen address"));
let (_, incoming) = endpoint_builder.bind(&listen)?;
let (_, incoming) = endpoint_builder.bind(&self.listen)?;

Ok((
Server,
Expand Down

0 comments on commit 8af413c

Please sign in to comment.