You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
428 lines
13 KiB
428 lines
13 KiB
7 years ago
|
From e327ff6cbdabcd4953bc551590c6e70384b1caf8 Mon Sep 17 00:00:00 2001
|
||
|
From: Igor Gnatenko <i.gnatenko.brain@gmail.com>
|
||
|
Date: Wed, 10 Jan 2018 13:20:09 +0100
|
||
|
Subject: [PATCH] deps: update slab to 0.4
|
||
|
|
||
|
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
|
||
|
---
|
||
|
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<T> {
|
||
|
// 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<AtomicUsize>;
|
||
|
|
||
|
-type Slab<T> = slab::Slab<T, ::Token>;
|
||
|
-
|
||
|
-pub type Result<T> = ::std::result::Result<T, TimerError>;
|
||
|
+pub type Result<T> = ::std::result::Result<T, io::Error>;
|
||
|
// TODO: remove
|
||
|
pub type TimerResult<T> = Result<T>;
|
||
|
-
|
||
|
-
|
||
|
-#[derive(Debug)]
|
||
|
-pub struct TimerError {
|
||
|
- kind: TimerErrorKind,
|
||
|
- desc: &'static str,
|
||
|
-}
|
||
|
-
|
||
|
-#[derive(Debug)]
|
||
|
-pub enum TimerErrorKind {
|
||
|
- TimerOverflow,
|
||
|
-}
|
||
|
-
|
||
|
// TODO: Remove
|
||
|
pub type OldTimerResult<T> = Result<T>;
|
||
|
|
||
|
@@ -192,13 +174,13 @@ impl<T> Timer<T> {
|
||
|
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<T> Timer<T> {
|
||
|
}
|
||
|
|
||
|
pub fn cancel_timeout(&mut self, timeout: &Timeout) -> Option<T> {
|
||
|
- 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<T> Timer<T> {
|
||
|
}
|
||
|
|
||
|
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<T> {
|
||
|
@@ -271,7 +253,7 @@ impl<T> Timer<T> {
|
||
|
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<T> Timer<T> {
|
||
|
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<T> Timer<T> {
|
||
|
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<T> Timer<T> {
|
||
|
// Next tick containing a timeout
|
||
|
fn next_tick(&self) -> Option<Tick> {
|
||
|
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<T> Entry<T> {
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
-
|
||
|
-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<u8>
|
||
|
}
|
||
|
|
||
|
-type Slab<T> = slab::Slab<T, Token>;
|
||
|
-
|
||
|
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<T> = slab::Slab<T, Token>;
|
||
|
-
|
||
|
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<T> = slab::Slab<T, Token>;
|
||
|
-
|
||
|
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<T> = slab::Slab<T, Token>;
|
||
|
-
|
||
|
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<T> = slab::Slab<T, Token>;
|
||
|
-
|
||
|
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
|
||
|
|