Skip to content

Commit

Permalink
merge converged endpoint constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
tthebst committed Jun 30, 2023
1 parent f5dc481 commit 139a5f3
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions quinn/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Endpoint {
let socket = std::net::UdpSocket::bind(addr)?;
let runtime = default_runtime()
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "no async runtime found"))?;
Self::new_with_runtime(
Self::new_with_abstract_socket(
EndpointConfig::default(),
None,
runtime.wrap_udp_socket(socket)?,
Expand All @@ -75,7 +75,7 @@ impl Endpoint {
let socket = std::net::UdpSocket::bind(addr)?;
let runtime = default_runtime()
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "no async runtime found"))?;
Self::new_with_runtime(
Self::new_with_abstract_socket(
EndpointConfig::default(),
Some(config),
runtime.wrap_udp_socket(socket)?,
Expand All @@ -91,23 +91,14 @@ impl Endpoint {
runtime: Arc<dyn Runtime>,
) -> io::Result<Self> {
let socket = runtime.wrap_udp_socket(socket)?;
Self::new_with_runtime(config, server_config, socket, runtime)
Self::new_with_abstract_socket(config, server_config, socket, runtime)
}

/// Construct an endpoint with arbitrary configuration and pre-constructed abstract socket
///
/// Useful when `socket` has additional state (e.g. sidechannels) attached for which shared
/// ownership is needed.
pub fn new_with_abstract_socket(
config: EndpointConfig,
server_config: Option<ServerConfig>,
socket: Box<dyn AsyncUdpSocket>,
runtime: Arc<dyn Runtime>,
) -> io::Result<Self> {
Self::new_with_runtime(config, server_config, socket, runtime)
}

fn new_with_runtime(
fn new_with_abstract_socket(
config: EndpointConfig,
server_config: Option<ServerConfig>,
socket: Box<dyn AsyncUdpSocket>,
Expand Down

0 comments on commit 139a5f3

Please sign in to comment.