From 446431028e252f14fe0453f01c53a72b330b1570 Mon Sep 17 00:00:00 2001 From: Markus Pettersson Date: Wed, 11 Dec 2024 05:57:28 +0100 Subject: [PATCH] Add `UdpSocket::bind` (#1810) --- crates/shadowsocks/src/net/udp.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/shadowsocks/src/net/udp.rs b/crates/shadowsocks/src/net/udp.rs index d1b788d658cb..a84e75a45c2d 100644 --- a/crates/shadowsocks/src/net/udp.rs +++ b/crates/shadowsocks/src/net/udp.rs @@ -166,6 +166,12 @@ impl UdpSocket { }) } + /// Binds to a specific address as an outbound socket + #[inline] + pub async fn bind(addr: &SocketAddr) -> io::Result { + UdpSocket::bind_with_opts(addr, &ConnectOpts::default()).await + } + /// Binds to a specific address with opts as an outbound socket pub async fn bind_with_opts(addr: &SocketAddr, opts: &ConnectOpts) -> io::Result { bind_outbound_udp_socket(addr, opts).await.map(|socket| UdpSocket {