Skip to content

Commit

Permalink
Revert "net: add UdpSocket::peer_addr (#4362)"
Browse files Browse the repository at this point in the history
This reverts commit a9d9bde.
  • Loading branch information
taiki-e committed Jan 11, 2022
1 parent 6874013 commit 5772cf3
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 33 deletions.
23 changes: 0 additions & 23 deletions tokio/src/net/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,29 +278,6 @@ impl UdpSocket {
self.io.local_addr()
}

/// Returns the socket address of the remote peer this socket was connected
/// to.
///
/// # Example
///
/// ```
/// use tokio::net::UdpSocket;
/// # use std::{io, net::SocketAddr};
///
/// # #[tokio::main]
/// # async fn main() -> io::Result<()> {
/// let addr = "127.0.0.1:0".parse::<SocketAddr>().unwrap();
/// let peer_addr = "127.0.0.1:11100".parse::<SocketAddr>().unwrap();
/// let sock = UdpSocket::bind(addr).await?;
/// sock.connect(peer_addr).await?;
/// assert_eq!(sock.peer_addr()?.ip(), peer_addr.ip());
/// # Ok(())
/// # }
/// ```
pub fn peer_addr(&self) -> io::Result<SocketAddr> {
self.io.peer_addr()
}

/// Connects the UDP socket setting the default destination for send() and
/// limiting packets that are read via recv from the address specified in
/// `addr`.
Expand Down
10 changes: 0 additions & 10 deletions tokio/tests/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use futures::future::poll_fn;
use std::io;
use std::net::SocketAddr;
use std::sync::Arc;
use tokio::{io::ReadBuf, net::UdpSocket};
use tokio_test::assert_ok;
Expand Down Expand Up @@ -485,12 +484,3 @@ async fn poll_ready() {
}
}
}

#[tokio::test]
async fn peer_addr() {
let addr = "127.0.0.1:0".parse::<SocketAddr>().unwrap();
let peer_addr = "127.0.0.1:11100".parse::<SocketAddr>().unwrap();
let sock = UdpSocket::bind(addr).await.unwrap();
sock.connect(peer_addr).await.unwrap();
assert_eq!(sock.peer_addr().unwrap().ip(), peer_addr.ip());
}

0 comments on commit 5772cf3

Please sign in to comment.