Skip to content

Commit

Permalink
net: Expose UdpSocket::try_clone
Browse files Browse the repository at this point in the history
Useful for parallel sending.
  • Loading branch information
Ralith committed Dec 19, 2023
1 parent 4aa7bbf commit d143249
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tokio/src/net/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1990,6 +1990,16 @@ impl UdpSocket {
pub fn take_error(&self) -> io::Result<Option<io::Error>> {
self.io.take_error()
}

/// Creates a new independently owned handle to the underlying socket.
///
/// Cloned sockets don't share wakers, allowing multiple tasks to perform I/O in the same
/// direction concurrently.
///
/// See [`std::net::UdpSocket::try_clone`] for further details.
pub fn try_clone(&self) -> io::Result<Self> {
Self::from_std(self.as_socket().try_clone()?.into())
}
}

impl TryFrom<std::net::UdpSocket> for UdpSocket {
Expand Down

0 comments on commit d143249

Please sign in to comment.