diff --git a/tokio/src/net/udp.rs b/tokio/src/net/udp.rs index 2049527e79b..86b4fe9ce0d 100644 --- a/tokio/src/net/udp.rs +++ b/tokio/src/net/udp.rs @@ -22,8 +22,13 @@ cfg_net! { /// * one to one: [`connect`](`UdpSocket::connect`) and associate with a single address, using [`send`](`UdpSocket::send`) /// and [`recv`](`UdpSocket::recv`) to communicate only with that remote address /// - /// `UdpSocket` can also be used concurrently to `send_to` and `recv_from` in different tasks, - /// all that's required is that you `Arc` and clone a reference for each task. + /// This type does not provide a `split` method, because this functionality + /// can be achieved by wrapping the socket in an [`Arc`]. Note that you do + /// not need a `Mutex` to share the `UdpSocket` — an `Arc` is + /// enough. This is because all of the methods take `&self` instead of `&mut + /// self`. + /// + /// [`Arc`]: std::sync::Arc /// /// # Streams /// @@ -78,11 +83,12 @@ cfg_net! { /// } /// ``` /// - /// # Example: Sending/Receiving concurrently + /// # Example: Splitting with `Arc` /// - /// Because `send_to` and `recv_from` take `&self`. It's perfectly alright to `Arc` - /// and share the references to multiple tasks, in order to send/receive concurrently. Here is - /// a similar "echo" example but that supports concurrent sending/receiving: + /// Because `send_to` and `recv_from` take `&self`. It's perfectly alright + /// to use an `Arc` and share the references to multiple tasks. + /// Here is a similar "echo" example that supports concurrent + /// sending/receiving: /// /// ```no_run /// use tokio::{net::UdpSocket, sync::mpsc}; diff --git a/tokio/src/net/unix/datagram/socket.rs b/tokio/src/net/unix/datagram/socket.rs index 10bda4f3b15..126a243279c 100644 --- a/tokio/src/net/unix/datagram/socket.rs +++ b/tokio/src/net/unix/datagram/socket.rs @@ -20,11 +20,19 @@ cfg_net_unix! { /// A socket can be either named (associated with a filesystem path) or /// unnamed. /// + /// This type does not provide a `split` method, because this functionality + /// can be achieved by wrapping the socket in an [`Arc`]. Note that you do + /// not need a `Mutex` to share the `UnixDatagram` — an `Arc` + /// is enough. This is because all of the methods take `&self` instead of + /// `&mut self`. + /// /// **Note:** named sockets are persisted even after the object is dropped /// and the program has exited, and cannot be reconnected. It is advised /// that you either check for and unlink the existing socket if it exists, /// or use a temporary file that is guaranteed to not already exist. /// + /// [`Arc`]: std::sync::Arc + /// /// # Examples /// Using named sockets, associated with a filesystem path: /// ```