From be5ab04cb6d93a3581eb3e3bf9e87cbc441e564e Mon Sep 17 00:00:00 2001 From: Igor Gnatenko Date: Jan 14 2018 21:33:15 +0000 Subject: initial import Signed-off-by: Igor Gnatenko --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4ee5f10 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/mio-0.6.12.crate diff --git a/0001-deps-update-slab-to-0.4.patch b/0001-deps-update-slab-to-0.4.patch new file mode 100644 index 0000000..cf9c2fa --- /dev/null +++ b/0001-deps-update-slab-to-0.4.patch @@ -0,0 +1,427 @@ +From e327ff6cbdabcd4953bc551590c6e70384b1caf8 Mon Sep 17 00:00:00 2001 +From: Igor Gnatenko +Date: Wed, 10 Jan 2018 13:20:09 +0100 +Subject: [PATCH] deps: update slab to 0.4 + +Signed-off-by: Igor Gnatenko +--- + src/lib.rs | 1 + + src/timer.rs | 74 ++++++++----------------------------------- + test/test_battery.rs | 13 +++----- + test/test_echo_server.rs | 13 +++----- + test/test_uds_shutdown.rs | 13 +++----- + test/test_unix_echo_server.rs | 13 +++----- + test/test_unix_pass_fd.rs | 13 +++----- + 7 files changed, 39 insertions(+), 101 deletions(-) + +diff --git a/src/lib.rs b/src/lib.rs +index a0ce92a..3d04516 100644 +--- a/src/lib.rs ++++ b/src/lib.rs +@@ -83,6 +83,7 @@ + extern crate lazycell; + extern crate net2; + extern crate iovec; ++extern crate slab; + + #[cfg(target_os = "fuchsia")] + extern crate fuchsia_zircon as zircon; +diff --git a/src/timer.rs b/src/timer.rs +index 3d9a4f6..c77e37f 100644 +--- a/src/timer.rs ++++ b/src/timer.rs +@@ -2,18 +2,15 @@ + + #![allow(deprecated, missing_debug_implementations)] + +-extern crate slab; +- + use {convert, io, Ready, Poll, PollOpt, Registration, SetReadiness, Token}; + use event::Evented; + use lazycell::LazyCell; +-use std::{cmp, error, fmt, u64, usize, iter, thread}; ++use slab::Slab; ++use std::{cmp, fmt, u64, usize, iter, thread}; + use std::sync::Arc; + use std::sync::atomic::{AtomicUsize, Ordering}; + use std::time::{Duration, Instant}; + +-use self::TimerErrorKind::TimerOverflow; +- + pub struct Timer { + // Size of each tick in milliseconds + tick_ms: u64, +@@ -94,24 +91,9 @@ const TICK_MAX: Tick = u64::MAX; + // Manages communication with wakeup thread + type WakeupState = Arc; + +-type Slab = slab::Slab; +- +-pub type Result = ::std::result::Result; ++pub type Result = ::std::result::Result; + // TODO: remove + pub type TimerResult = Result; +- +- +-#[derive(Debug)] +-pub struct TimerError { +- kind: TimerErrorKind, +- desc: &'static str, +-} +- +-#[derive(Debug)] +-pub enum TimerErrorKind { +- TimerOverflow, +-} +- + // TODO: Remove + pub type OldTimerResult = Result; + +@@ -192,13 +174,13 @@ impl Timer { + let curr = self.wheel[slot]; + + // Insert the new entry +- let token = self.entries.insert(Entry::new(state, tick, curr.head)) +- .map_err(|_| TimerError::overflow())?; ++ let entry = Entry::new(state, tick, curr.head); ++ let token = Token(self.entries.insert(entry)); + + if curr.head != EMPTY { + // If there was a previous entry, set its prev pointer to the new + // entry +- self.entries[curr.head].links.prev = token; ++ self.entries[curr.head.into()].links.prev = token; + } + + // Update the head slot +@@ -219,7 +201,7 @@ impl Timer { + } + + pub fn cancel_timeout(&mut self, timeout: &Timeout) -> Option { +- let links = match self.entries.get(timeout.token) { ++ let links = match self.entries.get(timeout.token.into()) { + Some(e) => e.links, + None => return None + }; +@@ -230,7 +212,7 @@ impl Timer { + } + + self.unlink(&links, timeout.token); +- self.entries.remove(timeout.token).map(|e| e.state) ++ Some(self.entries.remove(timeout.token.into()).state) + } + + pub fn poll(&mut self) -> Option { +@@ -271,7 +253,7 @@ impl Timer { + self.wheel[slot].next_tick = TICK_MAX; + } + +- let links = self.entries[curr].links; ++ let links = self.entries[curr.into()].links; + + if links.tick <= self.tick { + trace!("triggering; token={:?}", curr); +@@ -280,8 +262,7 @@ impl Timer { + self.unlink(&links, curr); + + // Remove and return the token +- return self.entries.remove(curr) +- .map(|e| e.state); ++ return Some(self.entries.remove(curr.into()).state); + } else { + let next_tick = self.wheel[slot].next_tick; + self.wheel[slot].next_tick = cmp::min(next_tick, links.tick); +@@ -311,11 +292,11 @@ impl Timer { + let slot = self.slot_for(links.tick); + self.wheel[slot].head = links.next; + } else { +- self.entries[links.prev].links.next = links.next; ++ self.entries[links.prev.into()].links.next = links.next; + } + + if links.next != EMPTY { +- self.entries[links.next].links.prev = links.prev; ++ self.entries[links.next.into()].links.prev = links.prev; + + if token == self.next { + self.next = links.next; +@@ -356,7 +337,7 @@ impl Timer { + // Next tick containing a timeout + fn next_tick(&self) -> Option { + if self.next != EMPTY { +- let slot = self.slot_for(self.entries[self.next].links.tick); ++ let slot = self.slot_for(self.entries[self.next.into()].links.tick); + + if self.wheel[slot].next_tick == self.tick { + // There is data ready right now +@@ -497,32 +478,3 @@ impl Entry { + } + } + } +- +-impl fmt::Display for TimerError { +- fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { +- write!(fmt, "{}: {}", self.kind, self.desc) +- } +-} +- +-impl TimerError { +- fn overflow() -> TimerError { +- TimerError { +- kind: TimerOverflow, +- desc: "too many timer entries" +- } +- } +-} +- +-impl error::Error for TimerError { +- fn description(&self) -> &str { +- self.desc +- } +-} +- +-impl fmt::Display for TimerErrorKind { +- fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { +- match *self { +- TimerOverflow => write!(fmt, "TimerOverflow"), +- } +- } +-} +diff --git a/test/test_battery.rs b/test/test_battery.rs +index 3976071..d918196 100644 +--- a/test/test_battery.rs ++++ b/test/test_battery.rs +@@ -3,7 +3,7 @@ use mio::*; + use mio::deprecated::{EventLoop, EventLoopBuilder, Handler}; + use mio::net::{TcpListener, TcpStream}; + use std::collections::LinkedList; +-use slab; ++use slab::Slab; + use std::{io, thread}; + use std::time::Duration; + +@@ -23,8 +23,6 @@ struct EchoConn { + buf: Vec + } + +-type Slab = slab::Slab; +- + impl EchoConn { + fn new(sock: TcpStream) -> EchoConn { + let mut ec = +@@ -81,12 +79,11 @@ impl EchoServer { + + let sock = self.sock.accept().unwrap().0; + let conn = EchoConn::new(sock,); +- let tok = self.conns.insert(conn) +- .ok().expect("could not add connection to slab"); ++ let tok = self.conns.insert(conn); + + // Register the connection +- self.conns[tok].token = Some(tok); +- event_loop.register(&self.conns[tok].sock, tok, Ready::readable(), ++ self.conns[tok].token = Some(Token(tok)); ++ event_loop.register(&self.conns[tok].sock, Token(tok), Ready::readable(), + PollOpt::edge() | PollOpt::oneshot()) + .ok().expect("could not register socket with event loop"); + +@@ -106,7 +103,7 @@ impl EchoServer { + } + + fn conn<'a>(&'a mut self, tok: Token) -> &'a mut EchoConn { +- &mut self.conns[tok] ++ &mut self.conns[tok.into()] + } + } + +diff --git a/test/test_echo_server.rs b/test/test_echo_server.rs +index 6d2a84b..c0eda94 100644 +--- a/test/test_echo_server.rs ++++ b/test/test_echo_server.rs +@@ -2,7 +2,7 @@ use {localhost, TryRead, TryWrite}; + use mio::{Events, Poll, PollOpt, Ready, Token}; + use mio::net::{TcpListener, TcpStream}; + use bytes::{Buf, ByteBuf, MutByteBuf, SliceBuf}; +-use slab; ++use slab::Slab; + use std::io; + + const SERVER: Token = Token(10_000_000); +@@ -16,8 +16,6 @@ struct EchoConn { + interest: Ready + } + +-type Slab = slab::Slab; +- + impl EchoConn { + fn new(sock: TcpStream) -> EchoConn { + EchoConn { +@@ -96,12 +94,11 @@ impl EchoServer { + + let sock = self.sock.accept().unwrap().0; + let conn = EchoConn::new(sock,); +- let tok = self.conns.insert(conn) +- .ok().expect("could not add connection to slab"); ++ let tok = self.conns.insert(conn); + + // Register the connection +- self.conns[tok].token = Some(tok); +- poll.register(&self.conns[tok].sock, tok, Ready::readable(), ++ self.conns[tok].token = Some(Token(tok)); ++ poll.register(&self.conns[tok].sock, Token(tok), Ready::readable(), + PollOpt::edge() | PollOpt::oneshot()) + .ok().expect("could not register socket with event loop"); + +@@ -121,7 +118,7 @@ impl EchoServer { + } + + fn conn<'a>(&'a mut self, tok: Token) -> &'a mut EchoConn { +- &mut self.conns[tok] ++ &mut self.conns[tok.into()] + } + } + +diff --git a/test/test_uds_shutdown.rs b/test/test_uds_shutdown.rs +index 0339c71..58d2431 100644 +--- a/test/test_uds_shutdown.rs ++++ b/test/test_uds_shutdown.rs +@@ -3,7 +3,7 @@ use mio::*; + use mio::deprecated::{EventLoop, Handler}; + use mio::deprecated::unix::*; + use bytes::{Buf, ByteBuf, MutByteBuf, SliceBuf}; +-use slab; ++use slab::Slab; + use std::io; + use std::path::PathBuf; + use tempdir::TempDir; +@@ -19,8 +19,6 @@ struct EchoConn { + interest: Ready + } + +-type Slab = slab::Slab; +- + impl EchoConn { + fn new(sock: UnixStream) -> EchoConn { + EchoConn { +@@ -101,12 +99,11 @@ impl EchoServer { + + let sock = self.sock.accept().unwrap(); + let conn = EchoConn::new(sock,); +- let tok = self.conns.insert(conn) +- .ok().expect("could not add connection to slab"); ++ let tok = self.conns.insert(conn); + + // Register the connection +- self.conns[tok].token = Some(tok); +- event_loop.register(&self.conns[tok].sock, tok, Ready::readable(), ++ self.conns[tok].token = Some(Token(tok)); ++ event_loop.register(&self.conns[tok].sock, Token(tok), Ready::readable(), + PollOpt::edge() | PollOpt::oneshot()) + .ok().expect("could not register socket with event loop"); + +@@ -126,7 +123,7 @@ impl EchoServer { + } + + fn conn<'a>(&'a mut self, tok: Token) -> &'a mut EchoConn { +- &mut self.conns[tok] ++ &mut self.conns[tok.into()] + } + } + +diff --git a/test/test_unix_echo_server.rs b/test/test_unix_echo_server.rs +index ea64815..6f3dd4b 100644 +--- a/test/test_unix_echo_server.rs ++++ b/test/test_unix_echo_server.rs +@@ -3,7 +3,7 @@ use mio::*; + use mio::deprecated::{EventLoop, Handler}; + use mio::deprecated::unix::*; + use bytes::{Buf, ByteBuf, MutByteBuf, SliceBuf}; +-use slab; ++use slab::Slab; + use std::path::PathBuf; + use std::io; + use tempdir::TempDir; +@@ -19,8 +19,6 @@ struct EchoConn { + interest: Ready, + } + +-type Slab = slab::Slab; +- + impl EchoConn { + fn new(sock: UnixStream) -> EchoConn { + EchoConn { +@@ -96,12 +94,11 @@ impl EchoServer { + + let sock = self.sock.accept().unwrap(); + let conn = EchoConn::new(sock); +- let tok = self.conns.insert(conn) +- .ok().expect("could not add connection to slab"); ++ let tok = self.conns.insert(conn); + + // Register the connection +- self.conns[tok].token = Some(tok); +- event_loop.register(&self.conns[tok].sock, tok, Ready::readable(), PollOpt::edge() | PollOpt::oneshot()) ++ self.conns[tok].token = Some(Token(tok)); ++ event_loop.register(&self.conns[tok].sock, Token(tok), Ready::readable(), PollOpt::edge() | PollOpt::oneshot()) + .ok().expect("could not register socket with event loop"); + + Ok(()) +@@ -118,7 +115,7 @@ impl EchoServer { + } + + fn conn<'a>(&'a mut self, tok: Token) -> &'a mut EchoConn { +- &mut self.conns[tok] ++ &mut self.conns[tok.into()] + } + } + +diff --git a/test/test_unix_pass_fd.rs b/test/test_unix_pass_fd.rs +index b62f56e..f43ec22 100644 +--- a/test/test_unix_pass_fd.rs ++++ b/test/test_unix_pass_fd.rs +@@ -3,7 +3,7 @@ use mio::*; + use mio::deprecated::{EventLoop, Handler}; + use mio::deprecated::unix::*; + use bytes::{Buf, ByteBuf, SliceBuf}; +-use slab; ++use slab::Slab; + use std::path::PathBuf; + use std::io::{self, Read}; + use std::os::unix::io::{AsRawFd, FromRawFd}; +@@ -19,8 +19,6 @@ struct EchoConn { + interest: Ready, + } + +-type Slab = slab::Slab; +- + impl EchoConn { + fn new(sock: UnixStream) -> EchoConn { + EchoConn { +@@ -107,12 +105,11 @@ impl EchoServer { + + let sock = self.sock.accept().unwrap(); + let conn = EchoConn::new(sock); +- let tok = self.conns.insert(conn) +- .ok().expect("could not add connection to slab"); ++ let tok = self.conns.insert(conn); + + // Register the connection +- self.conns[tok].token = Some(tok); +- event_loop.register(&self.conns[tok].sock, tok, Ready::readable(), PollOpt::edge() | PollOpt::oneshot()) ++ self.conns[tok].token = Some(Token(tok)); ++ event_loop.register(&self.conns[tok].sock, Token(tok), Ready::readable(), PollOpt::edge() | PollOpt::oneshot()) + .ok().expect("could not register socket with event loop"); + + Ok(()) +@@ -129,7 +126,7 @@ impl EchoServer { + } + + fn conn<'a>(&'a mut self, tok: Token) -> &'a mut EchoConn { +- &mut self.conns[tok] ++ &mut self.conns[tok.into()] + } + } + +-- +2.15.1 + diff --git a/mio-0.6.12-fix-metadata.diff b/mio-0.6.12-fix-metadata.diff new file mode 100644 index 0000000..0b249b0 --- /dev/null +++ b/mio-0.6.12-fix-metadata.diff @@ -0,0 +1,30 @@ +--- mio-0.6.12/Cargo.toml 1970-01-01T01:00:00+01:00 ++++ mio-0.6.12/Cargo.toml 2018-01-12T23:42:45.103287+01:00 +@@ -40,7 +40,7 @@ + version = "0.2.29" + + [dependencies.slab] +-version = "0.3.0" ++version = "0.4.0" + [dev-dependencies.bytes] + version = "0.3.0" + +@@ -54,18 +54,5 @@ + [features] + default = ["with-deprecated"] + with-deprecated = [] +-[target."cfg(target_os = \"fuchsia\")".dependencies.fuchsia-zircon] +-version = "0.3.2" +- +-[target."cfg(target_os = \"fuchsia\")".dependencies.fuchsia-zircon-sys] +-version = "0.3.2" + [target."cfg(unix)".dependencies.libc] + version = "0.2.19" +-[target."cfg(windows)".dependencies.kernel32-sys] +-version = "0.2" +- +-[target."cfg(windows)".dependencies.miow] +-version = "0.2.1" +- +-[target."cfg(windows)".dependencies.winapi] +-version = "0.2.1" diff --git a/rust-mio.spec b/rust-mio.spec new file mode 100644 index 0000000..4272fe4 --- /dev/null +++ b/rust-mio.spec @@ -0,0 +1,83 @@ +# Generated by rust2rpm +# Doctests require networking +%bcond_without check +%global debug_package %{nil} + +%global crate mio + +Name: rust-%{crate} +Version: 0.6.12 +Release: 1%{?dist} +Summary: Lightweight non-blocking IO + +License: MIT +URL: https://crates.io/crates/mio +Source0: https://crates.io/api/v1/crates/%{crate}/%{version}/download#/%{crate}-%{version}.crate +# Initial patched metadata +# * No windows +# * No weird OS +# * Bump slab to 0.4, https://github.com/carllerche/mio/pull/768 +Patch0: mio-0.6.12-fix-metadata.diff +# Make it work with slab v0.4 +Patch1: 0001-deps-update-slab-to-0.4.patch + +ExclusiveArch: %{rust_arches} + +BuildRequires: rust-packaging +# [dependencies] +BuildRequires: (crate(iovec) >= 0.1.1 with crate(iovec) < 0.2.0) +BuildRequires: (crate(lazycell) >= 0.6.0 with crate(lazycell) < 0.7.0) +BuildRequires: (crate(libc) >= 0.2.19 with crate(libc) < 0.3.0) +BuildRequires: (crate(log) >= 0.3.1 with crate(log) < 0.4.0) +BuildRequires: (crate(net2) >= 0.2.29 with crate(net2) < 0.3.0) +BuildRequires: (crate(slab) >= 0.4.0 with crate(slab) < 0.5.0) +%if %{with check} +# [dev-dependencies] +BuildRequires: (crate(bytes) >= 0.3.0 with crate(bytes) < 0.4.0) +BuildRequires: (crate(env_logger) >= 0.4.0 with crate(env_logger) < 0.5.0) +BuildRequires: (crate(tempdir) >= 0.3.4 with crate(tempdir) < 0.4.0) +%endif + +%description +%{summary}. + +%package devel +Summary: %{summary} +BuildArch: noarch + +%description devel +Lightweight non-blocking IO. + +This package contains library source intended for building other packages +which use %{crate} from crates.io. + +%prep +%autosetup -n %{crate}-%{version} -p1 +%cargo_prep + +%build +%cargo_build + +%install +%cargo_install + +%if %{with check} +%check +%cargo_test +%endif + +%files devel +%license LICENSE +%doc README.md CHANGELOG.md +%{cargo_registry}/%{crate}-%{version}/ +%exclude %{cargo_registry}/%{crate}-%{version}/{appveyor.yml,ci} + +%changelog +* Wed Jan 10 2018 Igor Gnatenko - 0.6.12-1 +- Update to 0.6.12 + +* Fri Dec 01 2017 Igor Gnatenko - 0.6.11-1 +- Update to 0.6.11 + +* Fri Jun 16 2017 Igor Gnatenko - 0.6.9-1 +- Initial package diff --git a/sources b/sources new file mode 100644 index 0000000..1d8e57c --- /dev/null +++ b/sources @@ -0,0 +1 @@ +SHA512 (mio-0.6.12.crate) = e2a9dd4a731596d2203a152ea2e0597d93f66139bf0b8eef1b1bd8fb36b0fc2dcfd1aba156af95e136a87173b6e4d25852c2175682b342525aa979b99189b7c1