14 releases

0.8.0 Nov 10, 2024
0.7.1 Nov 15, 2023
0.7.0 Mar 3, 2023
0.5.6 Nov 30, 2022
0.3.0 Nov 6, 2020

#62 in Unix APIs

Download history 8388/week @ 2024-08-18 7583/week @ 2024-08-25 7583/week @ 2024-09-01 7738/week @ 2024-09-08 8458/week @ 2024-09-15 8093/week @ 2024-09-22 8502/week @ 2024-09-29 8551/week @ 2024-10-06 10566/week @ 2024-10-13 11064/week @ 2024-10-20 12169/week @ 2024-10-27 9080/week @ 2024-11-03 10343/week @ 2024-11-10 10700/week @ 2024-11-17 8046/week @ 2024-11-24 8589/week @ 2024-12-01

37,887 downloads per month
Used in 2 crates

BSD-2-Clause

66KB
1K SLoC

Docs.rs Tests

tokio-seqpacket

Unix seqpacket sockets for tokio.

Seqpacket sockets combine a number of useful properties:

  • They are connection oriented.
  • They guarantee in-order message delivery.
  • They provide datagrams with well-defined semantics for passing along file descriptors.

These properties make seqpacket sockets very well suited for local servers that need to pass file-descriptors around with their clients.

You can create a UnixSeqpacketListener to start accepting connections, or create a UnixSeqpacket to connect to a listening socket. You can also create a pair of connected sockets with UnixSeqpacket::pair().

Passing file descriptors and other ancillary data.

You can use send_vectored_with_ancillary and recv_vectored_with_ancillary to send and receive ancillary data. This can be used to pass file descriptors and unix credentials over sockets.

&self versus &mut self

Seqpacket sockets have well-defined semantics when sending or receiving on the same socket from different threads. Although the order is not guaranteed in that scenario, each datagram will be delivered intact. Since tokio 0.3, it is also possible for multiple tasks to await the same file descriptor. As such, all I/O functions now take &self instead of &mut self, and the split() API has been deprecated.

Example

use tokio_seqpacket::UnixSeqpacket;

let mut socket = UnixSeqpacket::connect("/run/foo.sock").await?;
socket.send(b"Hello!").await?;

let mut buffer = [0u8; 128];
let len = socket.recv(&mut buffer).await?;
println!("{}", String::from_utf8_lossy(&buffer[..len]));

Dependencies

~2.3–10MB
~92K SLoC