Bug 1716518 - Upgrade mio-uds to v0.6.8. r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D117818
This commit is contained in:
Mike Hommey 2021-06-15 22:04:53 +00:00
Родитель 56cdf52d72
Коммит 63d1fe7a19
8 изменённых файлов: 55 добавлений и 402 удалений

4
Cargo.lock сгенерированный
Просмотреть файл

@ -3120,9 +3120,9 @@ dependencies = [
[[package]]
name = "mio-uds"
version = "0.6.7"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125"
checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0"
dependencies = [
"iovec",
"libc",

Просмотреть файл

@ -1 +1 @@
{"files":{"Cargo.toml":"aab0dbb59fdfce49d6e457d42d5ab7c67e3634156f5f2312defdfa501c1d0a06","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"1c9f4529c7a57cd61cfc1995ebb1c43218cba1e9e78746af97d1dc84927c4103","src/datagram.rs":"b4311804bd4e330905fbf3e47e8c738759bbc039bf6ad2045490080a958d48c2","src/lib.rs":"a827f7a59ddd3c6bc6bd119646493f1c921de48b3ac5d674d5810dff35231dd8","src/listener.rs":"b0b26e81ded0ed57f4e29aab80df901592bfde282b011a2528c5ffca238a62ca","src/socket.rs":"255bf7220e45a06f57ac032ad60b6c712bce6aff300c40a7243774b74caf25a5","src/stream.rs":"31bb65120f6b236a35cfc989c63e06c5e1d4ee9ea1995b150a9a455435f5b1e3","tests/echo.rs":"3056f97689f0696e970cc401bf0b1f5c0cd4f9952b6fe2dda60831c870f6171c","tests/smoke.rs":"666da1e332560747c4a8f8cbc4ce68da06593e0e5b18f1a8115f94f7165e5052"},"package":"966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125"}
{"files":{"Cargo.toml":"6fb189dd6765ec3be1e2cb65d8733979c48f24df77e0b6fece565fbbc27ae022","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"8de91b1fa2bd5014b42e2b33d8b07e1626ed9715cfd8b8bfd80aa95a114d737c","src/datagram.rs":"b4311804bd4e330905fbf3e47e8c738759bbc039bf6ad2045490080a958d48c2","src/lib.rs":"a827f7a59ddd3c6bc6bd119646493f1c921de48b3ac5d674d5810dff35231dd8","src/listener.rs":"297d73cac8fce225972abb9c8747349d6151e5a61cb8f7fbfb050c336375a61d","src/socket.rs":"f278f62d1f751cae4a0dbfaf507012a99f34eb45b58aee6d70fa1a69e13132c6","src/stream.rs":"31bb65120f6b236a35cfc989c63e06c5e1d4ee9ea1995b150a9a455435f5b1e3"},"package":"afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0"}

13
third_party/rust/mio-uds/Cargo.toml поставляемый
Просмотреть файл

@ -3,7 +3,7 @@
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g. crates.io) dependencies
# to registry (e.g., crates.io) dependencies
#
# If you believe there's an error in this file please file an
# issue against the rust-lang/cargo repository. If you're
@ -12,24 +12,23 @@
[package]
name = "mio-uds"
version = "0.6.7"
version = "0.6.8"
authors = ["Alex Crichton <alex@alexcrichton.com>"]
include = ["Cargo.toml", "LICENSE-APACHE", "LICENSE-MIT", "README.md", "src/**/*.rs"]
description = "Unix domain socket bindings for mio\n"
homepage = "https://github.com/alexcrichton/mio-uds"
homepage = "https://github.com/deprecrated/mio-uds"
documentation = "https://docs.rs/mio-uds"
readme = "README.md"
categories = ["asynchronous"]
license = "MIT/Apache-2.0"
repository = "https://github.com/alexcrichton/mio-uds"
repository = "https://github.com/deprecrated/mio-uds"
[dev-dependencies.tempdir]
version = "0.3"
[target."cfg(unix)".dependencies.iovec]
version = "0.1"
[target."cfg(unix)".dependencies.libc]
version = "0.2.42"
version = "0.2.69"
[target."cfg(unix)".dependencies.mio]
version = "0.6.5"
[badges.travis-ci]
repository = "alexcrichton/mio-uds"

24
third_party/rust/mio-uds/README.md поставляемый
Просмотреть файл

@ -1,16 +1,24 @@
# mio-uds
[![Build Status](https://travis-ci.org/alexcrichton/mio-uds.svg?branch=master)](https://travis-ci.org/alexcrichton/mio-uds)
[Documentation](https://docs.rs/mio-uds)
A library for integrating Unix Domain Sockets with [mio]. Based on the standard
library's [support for Unix sockets][std], except all of the abstractions and
types are nonblocking to conform with the expectations of mio.
[mio]: https://github.com/carllerche/mio
[mio]: https://github.com/tokio-rs/mio
[std]: https://doc.rust-lang.org/std/os/unix/net/
[![Build Status](https://github.com/deprecrated/mio-uds/workflows/CI/badge.svg)](https://github.com/deprecrated/mio-uds/actions?query=workflow%3ACI+branch%3Amaster)
[![Documentation](https://docs.rs/mio-uds/badge.svg?version=0.6)](https://docs.rs/mio-uds/~0.6)
# mio-uds is Deprecated
With the 0.7 release, `mio` now includes native support for Unix Domain
Sockets. Consumers should switch to that functionality when updating their
`mio` dependency to the 0.7.x series.
## Usage
```toml
# Cargo.toml
[dependencies]
@ -18,8 +26,6 @@ mio-uds = "0.6"
mio = "0.6"
```
## Usage
The three exported types at the top level, `UnixStream`, `UnixListener`, and
`UnixDatagram`, are thin wrappers around the libstd counterparts. They can be
used in similar fashions to mio's TCP and UDP types in terms of registration and
@ -39,5 +45,5 @@ at your option.
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in Serde by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.
for inclusion in the work by you, as defined in the Apache-2.0 license, shall
be dual licensed as above, without any additional terms or conditions.

2
third_party/rust/mio-uds/src/listener.rs поставляемый
Просмотреть файл

@ -67,7 +67,7 @@ impl UnixListener {
/// Accepts a new incoming connection to this listener.
///
/// This method is the same as `accept`, except that it returns a UDP socket *in blocking mode*
/// This method is the same as `accept`, except that it returns a `net::UnixStream` *in blocking mode*
/// which isn't bound to a `mio` type. This can later be converted to a `mio` type, if
/// necessary.
///

35
third_party/rust/mio-uds/src/socket.rs поставляемый
Просмотреть файл

@ -13,11 +13,26 @@ use cvt;
// get name resolution to work and things to compile we just define a dummy
// SOCK_CLOEXEC here for other platforms. Note that the dummy constant isn't
// actually ever used (the blocks below are wrapped in `if cfg!` as well.
#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(
target_os = "linux",
target_os = "android",
target_os = "illumos",
target_os = "solaris"
))]
use libc::{SOCK_CLOEXEC, SOCK_NONBLOCK};
#[cfg(not(any(target_os = "linux", target_os = "android")))]
#[cfg(not(any(
target_os = "linux",
target_os = "android",
target_os = "illumos",
target_os = "solaris"
)))]
const SOCK_CLOEXEC: c_int = 0;
#[cfg(not(any(target_os = "linux", target_os = "android")))]
#[cfg(not(any(
target_os = "linux",
target_os = "android",
target_os = "illumos",
target_os = "solaris"
)))]
const SOCK_NONBLOCK: c_int = 0;
pub struct Socket {
@ -32,7 +47,12 @@ impl Socket {
// this option, however, was added in 2.6.27, and we still support
// 2.6.18 as a kernel, so if the returned error is EINVAL we
// fallthrough to the fallback.
if cfg!(target_os = "linux") || cfg!(target_os = "android") {
if cfg!(any(
target_os = "linux",
target_os = "android",
target_os = "illumos",
target_os = "solaris"
)) {
let flags = ty | SOCK_CLOEXEC | SOCK_NONBLOCK;
match cvt(libc::socket(libc::AF_UNIX, flags, 0)) {
Ok(fd) => return Ok(Socket { fd: fd }),
@ -54,7 +74,12 @@ impl Socket {
let mut fds = [0, 0];
// Like above, see if we can set cloexec atomically
if cfg!(target_os = "linux") || cfg!(target_os = "android") {
if cfg!(any(
target_os = "linux",
target_os = "android",
target_os = "illumos",
target_os = "solaris"
)) {
let flags = ty | SOCK_CLOEXEC | SOCK_NONBLOCK;
match cvt(libc::socketpair(libc::AF_UNIX, flags, 0, fds.as_mut_ptr())) {
Ok(_) => {

276
third_party/rust/mio-uds/tests/echo.rs поставляемый
Просмотреть файл

@ -1,276 +0,0 @@
extern crate mio;
extern crate tempdir;
extern crate mio_uds;
use std::io::{self, Write, Read};
use std::io::ErrorKind::WouldBlock;
use tempdir::TempDir;
use mio::*;
use mio_uds::*;
macro_rules! t {
($e:expr) => (match $e {
Ok(e) => e,
Err(e) => panic!("{} failed with {}", stringify!($e), e),
})
}
const SERVER: Token = Token(0);
const CLIENT: Token = Token(1);
struct EchoConn {
sock: UnixStream,
buf: Vec<u8>,
token: Option<Token>,
interest: Ready,
}
impl EchoConn {
fn new(sock: UnixStream) -> EchoConn {
EchoConn {
sock: sock,
buf: Vec::new(),
token: None,
interest: Ready::readable(),
}
}
fn writable(&mut self, poll: &Poll) -> io::Result<()> {
match self.sock.write(&self.buf) {
Ok(n) => {
assert_eq!(n, self.buf.len());
self.interest.insert(Ready::readable());
self.interest.remove(Ready::writable());
}
Err(ref e) if e.kind() == WouldBlock => {
self.interest.insert(Ready::writable());
}
Err(e) => panic!("not implemented; client err={:?}", e),
}
assert!(self.interest.is_readable() || self.interest.is_writable(),
"actual={:?}", self.interest);
poll.reregister(&self.sock, self.token.unwrap(), self.interest,
PollOpt::edge() | PollOpt::oneshot())
}
fn readable(&mut self, poll: &Poll) -> io::Result<()> {
let mut buf = [0; 1024];
match self.sock.read(&mut buf) {
Ok(r) => {
self.buf = buf[..r].to_vec();
self.interest.remove(Ready::readable());
self.interest.insert(Ready::writable());
}
Err(ref e) if e.kind() == WouldBlock => {}
Err(_e) => {
self.interest.remove(Ready::readable());
}
}
assert!(self.interest.is_readable() || self.interest.is_writable(),
"actual={:?}", self.interest);
poll.reregister(&self.sock, self.token.unwrap(), self.interest,
PollOpt::edge() | PollOpt::oneshot())
}
}
struct EchoServer {
sock: UnixListener,
conns: Vec<Option<EchoConn>>,
}
impl EchoServer {
fn accept(&mut self, poll: &Poll) -> io::Result<()> {
let sock = t!(self.sock.accept()).unwrap().0;
let conn = EchoConn::new(sock);
let tok = Token(self.conns.len() + 2);
self.conns.push(Some(conn));
// Register the connection
self.conn(tok).token = Some(tok);
t!(poll.register(&self.conn(tok).sock, tok,
Ready::readable(),
PollOpt::edge() | PollOpt::oneshot()));
Ok(())
}
fn conn_readable(&mut self, poll: &Poll, tok: Token) -> io::Result<()> {
self.conn(tok).readable(poll)
}
fn conn_writable(&mut self, poll: &Poll, tok: Token) -> io::Result<()> {
self.conn(tok).writable(poll)
}
fn conn<'a>(&'a mut self, tok: Token) -> &'a mut EchoConn {
self.conns[usize::from(tok) - 2].as_mut().unwrap()
}
}
struct EchoClient {
sock: UnixStream,
msgs: Vec<&'static str>,
tx: &'static [u8],
rx: &'static [u8],
token: Token,
interest: Ready,
active: bool,
}
// Sends a message and expects to receive the same exact message, one at a time
impl EchoClient {
fn new(sock: UnixStream, tok: Token, mut msgs: Vec<&'static str>) -> EchoClient {
let curr = msgs.remove(0);
EchoClient {
sock: sock,
msgs: msgs,
tx: curr.as_bytes(),
rx: curr.as_bytes(),
token: tok,
interest: Ready::empty(),
active: true,
}
}
fn readable(&mut self, poll: &Poll) -> io::Result<()> {
let mut buf = [0; 1024];
match self.sock.read(&mut buf) {
Ok(n) => {
assert_eq!(&self.rx[..n], &buf[..n]);
self.rx = &self.rx[n..];
self.interest.remove(Ready::readable());
if self.rx.len() == 0 {
self.next_msg(poll).unwrap();
}
}
Err(ref e) if e.kind() == WouldBlock => {}
Err(e) => panic!("error {}", e),
}
if !self.interest.is_empty() {
assert!(self.interest.is_readable() || self.interest.is_writable(),
"actual={:?}", self.interest);
try!(poll.reregister(&self.sock, self.token, self.interest,
PollOpt::edge() | PollOpt::oneshot()));
}
Ok(())
}
fn writable(&mut self, poll: &Poll) -> io::Result<()> {
match self.sock.write(self.tx) {
Ok(r) => {
self.tx = &self.tx[r..];
self.interest.insert(Ready::readable());
self.interest.remove(Ready::writable());
}
Err(ref e) if e.kind() == WouldBlock => {
self.interest.insert(Ready::writable());
}
Err(e) => panic!("not implemented; client err={:?}", e)
}
assert!(self.interest.is_readable() || self.interest.is_writable(),
"actual={:?}", self.interest);
poll.reregister(&self.sock, self.token, self.interest,
PollOpt::edge() | PollOpt::oneshot())
}
fn next_msg(&mut self, poll: &Poll) -> io::Result<()> {
if self.msgs.is_empty() {
self.active = false;
return Ok(());
}
let curr = self.msgs.remove(0);
self.tx = curr.as_bytes();
self.rx = curr.as_bytes();
self.interest.insert(Ready::writable());
assert!(self.interest.is_readable() || self.interest.is_writable(),
"actual={:?}", self.interest);
poll.reregister(&self.sock, self.token, self.interest,
PollOpt::edge() | PollOpt::oneshot())
}
}
struct Echo {
server: EchoServer,
client: EchoClient,
}
impl Echo {
fn new(srv: UnixListener, client: UnixStream, msgs: Vec<&'static str>) -> Echo {
Echo {
server: EchoServer {
sock: srv,
conns: Vec::new(),
},
client: EchoClient::new(client, CLIENT, msgs)
}
}
fn ready(&mut self,
poll: &Poll,
token: Token,
events: Ready) {
println!("ready {:?} {:?}", token, events);
if events.is_readable() {
match token {
SERVER => self.server.accept(poll).unwrap(),
CLIENT => self.client.readable(poll).unwrap(),
i => self.server.conn_readable(poll, i).unwrap()
}
}
if events.is_writable() {
match token {
SERVER => panic!("received writable for token 0"),
CLIENT => self.client.writable(poll).unwrap(),
_ => self.server.conn_writable(poll, token).unwrap()
}
}
}
}
#[test]
fn echo_server() {
let tmp_dir = t!(TempDir::new("mio-uds"));
let addr = tmp_dir.path().join("sock");
let poll = t!(Poll::new());
let mut events = Events::with_capacity(1024);
let srv = t!(UnixListener::bind(&addr));
t!(poll.register(&srv,
SERVER,
Ready::readable(),
PollOpt::edge() | PollOpt::oneshot()));
let sock = t!(UnixStream::connect(&addr));
t!(poll.register(&sock,
CLIENT,
Ready::writable(),
PollOpt::edge() | PollOpt::oneshot()));
let mut echo = Echo::new(srv, sock, vec!["foo", "bar"]);
while echo.client.active {
t!(poll.poll(&mut events, None));
for i in 0..events.len() {
let event = events.get(i).unwrap();
echo.ready(&poll, event.token(), event.readiness());
}
}
}

101
third_party/rust/mio-uds/tests/smoke.rs поставляемый
Просмотреть файл

@ -1,101 +0,0 @@
extern crate iovec;
extern crate mio;
extern crate tempdir;
extern crate mio_uds;
use std::io::prelude::*;
use std::time::Duration;
use iovec::IoVec;
use mio::*;
use mio_uds::*;
use tempdir::TempDir;
macro_rules! t {
($e:expr) => (match $e {
Ok(e) => e,
Err(e) => panic!("{} failed with {}", stringify!($e), e),
})
}
#[test]
fn listener() {
let td = t!(TempDir::new("uds"));
let a = t!(UnixListener::bind(td.path().join("foo")));
assert!(t!(a.accept()).is_none());
t!(a.local_addr());
assert!(t!(a.take_error()).is_none());
let b = t!(a.try_clone());
assert!(t!(b.accept()).is_none());
let poll = t!(Poll::new());
let mut events = Events::with_capacity(1024);
t!(poll.register(&a, Token(1), Ready::readable(), PollOpt::edge()));
let s = t!(UnixStream::connect(td.path().join("foo")));
assert_eq!(t!(poll.poll(&mut events, None)), 1);
let (s2, addr) = t!(a.accept()).unwrap();
assert_eq!(t!(s.peer_addr()).as_pathname(), t!(s2.local_addr()).as_pathname());
assert_eq!(t!(s.local_addr()).as_pathname(), t!(s2.peer_addr()).as_pathname());
assert_eq!(addr.as_pathname(), t!(s.local_addr()).as_pathname());
}
#[test]
fn stream() {
let poll = t!(Poll::new());
let mut events = Events::with_capacity(1024);
let (mut a, mut b) = t!(UnixStream::pair());
let both = Ready::readable() | Ready::writable();
t!(poll.register(&a, Token(1), both, PollOpt::edge()));
t!(poll.register(&b, Token(2), both, PollOpt::edge()));
assert_eq!(t!(poll.poll(&mut events, Some(Duration::new(0, 0)))), 2);
assert_eq!(events.get(0).unwrap().readiness(), Ready::writable());
assert_eq!(events.get(1).unwrap().readiness(), Ready::writable());
assert_eq!(t!(a.write(&[3])), 1);
assert_eq!(t!(poll.poll(&mut events, Some(Duration::new(0, 0)))), 1);
assert!(events.get(0).unwrap().readiness().is_readable());
assert_eq!(events.get(0).unwrap().token(), Token(2));
assert_eq!(t!(b.read(&mut [0; 1024])), 1);
}
#[test]
fn stream_iovec() {
let poll = t!(Poll::new());
let mut events = Events::with_capacity(1024);
let (a, b) = t!(UnixStream::pair());
let both = Ready::readable() | Ready::writable();
t!(poll.register(&a, Token(1), both, PollOpt::edge()));
t!(poll.register(&b, Token(2), both, PollOpt::edge()));
assert_eq!(t!(poll.poll(&mut events, Some(Duration::new(0, 0)))), 2);
assert_eq!(events.get(0).unwrap().readiness(), Ready::writable());
assert_eq!(events.get(1).unwrap().readiness(), Ready::writable());
let send = b"Hello, World!";
let vecs: [&IoVec;2] = [ (&send[..6]).into(),
(&send[6..]).into() ];
assert_eq!(t!(a.write_bufs(&vecs)), send.len());
assert_eq!(t!(poll.poll(&mut events, Some(Duration::new(0, 0)))), 1);
assert!(events.get(0).unwrap().readiness().is_readable());
assert_eq!(events.get(0).unwrap().token(), Token(2));
let mut recv = [0; 13];
{
let (mut first, mut last) = recv.split_at_mut(6);
let mut vecs: [&mut IoVec;2] = [ first.into(), last.into() ];
assert_eq!(t!(b.read_bufs(&mut vecs)), send.len());
}
assert_eq!(&send[..], &recv[..]);
}