Skip to content

Commit eb45c0a

Browse files
authored
Rollup merge of rust-lang#44388 - tbu-:pr_doc_udp_connect_multiple, r=frewsxcv
Clarify the behavior of UDP sockets wrt. multiple addresses in `connect` CC @frewsxcv rust-lang#22569 rust-lang#44209
2 parents 64690fe + b4d0f61 commit eb45c0a

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

src/libstd/net/udp.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,11 @@ impl UdpSocket {
598598
/// receive data from the specified address.
599599
///
600600
/// If `addr` yields multiple addresses, `connect` will be attempted with
601-
/// each of the addresses until a connection is successful. If none of
602-
/// the addresses are able to be connected, the error returned from the
601+
/// each of the addresses until the underlying OS function returns no
602+
/// error. Note that usually, a successful `connect` call does not specify
603+
/// that there is a remote server listening on the port, rather, such an
604+
/// error would only be detected after the first send. If the OS returns an
605+
/// error for each of the specified addresses, the error returned from the
603606
/// last connection attempt (the last address) is returned.
604607
///
605608
/// # Examples
@@ -614,20 +617,10 @@ impl UdpSocket {
614617
/// socket.connect("127.0.0.1:8080").expect("connect function failed");
615618
/// ```
616619
///
617-
/// Create a UDP socket bound to `127.0.0.1:3400` and connect the socket to
618-
/// `127.0.0.1:8080`. If that connection fails, then the UDP socket will
619-
/// connect to `127.0.0.1:8081`:
620-
///
621-
/// ```no_run
622-
/// use std::net::{SocketAddr, UdpSocket};
623-
///
624-
/// let socket = UdpSocket::bind("127.0.0.1:3400").expect("couldn't bind to address");
625-
/// let connect_addrs = [
626-
/// SocketAddr::from(([127, 0, 0, 1], 8080)),
627-
/// SocketAddr::from(([127, 0, 0, 1], 8081)),
628-
/// ];
629-
/// socket.connect(&connect_addrs[..]).expect("connect function failed");
630-
/// ```
620+
/// Unlike in the TCP case, passing an array of addresses to the `connect`
621+
/// function of a UDP socket is not a useful thing to do: The OS will be
622+
/// unable to determine whether something is listening on the remote
623+
/// address without the application sending data.
631624
#[stable(feature = "net2_mutators", since = "1.9.0")]
632625
pub fn connect<A: ToSocketAddrs>(&self, addr: A) -> io::Result<()> {
633626
super::each_addr(addr, |addr| self.0.connect(addr))

0 commit comments

Comments
 (0)