@@ -69,14 +69,34 @@ impl UdpSocket {
6969 /// The address type can be any implementor of [`ToSocketAddrs`] trait. See
7070 /// its documentation for concrete examples.
7171 ///
72+ /// If `addr` yields multiple addresses, `bind` will be attempted with
73+ /// each of the addresses until one succeeds and returns the socket. If none
74+ /// of the addresses succeed in creating a socket, the error returned from
75+ /// the last attempt (the last address) is returned.
76+ ///
7277 /// [`ToSocketAddrs`]: ../../std/net/trait.ToSocketAddrs.html
7378 ///
7479 /// # Examples
7580 ///
81+ /// Create a UDP socket bound to `127.0.0.1:3400`:
82+ ///
7683 /// ```no_run
7784 /// use std::net::UdpSocket;
7885 ///
79- /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
86+ /// let socket = UdpSocket::bind("127.0.0.1:3400").expect("couldn't bind to address");
87+ /// ```
88+ ///
89+ /// Create a UDP socket bound to `127.0.0.1:3400`. If the socket cannot be
90+ /// bound to that address, create a UDP socket bound to `127.0.0.1:3401`:
91+ ///
92+ /// ```no_run
93+ /// use std::net::{SocketAddr, UdpSocket};
94+ ///
95+ /// let addrs = [
96+ /// SocketAddr::from(([127, 0, 0, 1], 3400)),
97+ /// SocketAddr::from(([127, 0, 0, 1], 3401)),
98+ /// ];
99+ /// let socket = UdpSocket::bind(&addrs[..]).expect("couldn't bind to address");
80100 /// ```
81101 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
82102 pub fn bind < A : ToSocketAddrs > ( addr : A ) -> io:: Result < UdpSocket > {
@@ -130,6 +150,9 @@ impl UdpSocket {
130150 /// Address type can be any implementor of [`ToSocketAddrs`] trait. See its
131151 /// documentation for concrete examples.
132152 ///
153+ /// It is possible for `addr` to yield multiple addresses, but `send_to`
154+ /// will only send data to the first address yielded by `addr`.
155+ ///
133156 /// This will return an error when the IP version of the local socket
134157 /// does not match that returned from [`ToSocketAddrs`].
135158 ///
@@ -562,14 +585,37 @@ impl UdpSocket {
562585 /// `recv` syscalls to be used to send data and also applies filters to only
563586 /// receive data from the specified address.
564587 ///
588+ /// If `addr` yields multiple addresses, `connect` will be attempted with
589+ /// each of the addresses until a connection is successful. If none of
590+ /// the addresses are able to be connected, the error returned from the
591+ /// last connection attempt (the last address) is returned.
592+ ///
565593 /// # Examples
566594 ///
595+ /// Create a UDP socket bound to `127.0.0.1:3400` and connect the socket to
596+ /// `127.0.0.1:8080`:
597+ ///
567598 /// ```no_run
568599 /// use std::net::UdpSocket;
569600 ///
570- /// let socket = UdpSocket::bind("127.0.0.1:34254 ").expect("couldn't bind to address");
601+ /// let socket = UdpSocket::bind("127.0.0.1:3400 ").expect("couldn't bind to address");
571602 /// socket.connect("127.0.0.1:8080").expect("connect function failed");
572603 /// ```
604+ ///
605+ /// Create a UDP socket bound to `127.0.0.1:3400` and connect the socket to
606+ /// `127.0.0.1:8080`. If that connection fails, then the UDP socket will
607+ /// connect to `127.0.0.1:8081`:
608+ ///
609+ /// ```no_run
610+ /// use std::net::{SocketAddr, UdpSocket};
611+ ///
612+ /// let socket = UdpSocket::bind("127.0.0.1:3400").expect("couldn't bind to address");
613+ /// let connect_addrs = [
614+ /// SocketAddr::from(([127, 0, 0, 1], 8080)),
615+ /// SocketAddr::from(([127, 0, 0, 1], 8081)),
616+ /// ];
617+ /// socket.connect(&connect_addrs[..]).expect("connect function failed");
618+ /// ```
573619 #[ stable( feature = "net2_mutators" , since = "1.9.0" ) ]
574620 pub fn connect < A : ToSocketAddrs > ( & self , addr : A ) -> io:: Result < ( ) > {
575621 super :: each_addr ( addr, |addr| self . 0 . connect ( addr) )
0 commit comments