Skip to content

Commit

Permalink
udp: add UdpSocket::take_error (#3051)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darksonn committed Oct 26, 2020
1 parent a9da220 commit cbb8fe6
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tokio/src/net/udp/socket.rs
Expand Up @@ -822,6 +822,29 @@ impl UdpSocket {
pub fn leave_multicast_v6(&self, multiaddr: &Ipv6Addr, interface: u32) -> io::Result<()> {
self.io.get_ref().leave_multicast_v6(multiaddr, interface)
}

/// Returns the value of the `SO_ERROR` option.
///
/// # Examples
/// ```
/// # use std::error::Error;
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn Error>> {
/// use tokio::net::UdpSocket;
///
/// // Create a socket
/// let socket = UdpSocket::bind("0.0.0.0:8080").await?;
///
/// if let Ok(Some(err)) = socket.take_error() {
/// println!("Got error: {:?}", err);
/// }
///
/// # Ok(())
/// # }
/// ```
pub fn take_error(&self) -> io::Result<Option<io::Error>> {
self.io.get_ref().take_error()
}
}

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

0 comments on commit cbb8fe6

Please sign in to comment.