Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update datagram docs on splitting #3448

Merged
merged 1 commit into from Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 12 additions & 6 deletions tokio/src/net/udp.rs
Expand Up @@ -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<UdpSocket>` 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<UdpSocket>` is
/// enough. This is because all of the methods take `&self` instead of `&mut
/// self`.
///
/// [`Arc`]: std::sync::Arc
///
/// # Streams
///
Expand Down Expand Up @@ -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<UdpSocket>`
/// 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<UdpSocket>` 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};
Expand Down
8 changes: 8 additions & 0 deletions tokio/src/net/unix/datagram/socket.rs
Expand Up @@ -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<UnixDatagram>`
/// 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:
/// ```
Expand Down