Permalink
Browse files

Update to mio 0.6.0

  • Loading branch information...
1 parent f0d30e5 commit 70cac3b12dcced9086718d421262dde909017199 @hjr3 committed Sep 2, 2016
Showing with 29 additions and 32 deletions.
  1. +7 −7 Cargo.lock
  2. +2 −2 Cargo.toml
  3. +20 −23 src/server.rs
View
@@ -5,8 +5,8 @@ dependencies = [
"byteorder 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "mio 0.6.0-dev (git+https://github.com/carllerche/mio?rev=ce5d4fb)",
- "slab 0.2.0 (git+https://github.com/carllerche/slab?rev=5476efcafb)",
+ "mio 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "slab 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -75,8 +75,8 @@ dependencies = [
[[package]]
name = "mio"
-version = "0.6.0-dev"
-source = "git+https://github.com/carllerche/mio?rev=ce5d4fb#ce5d4fb5cde330c8486ddf3d91142ac03134c6d7"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"lazycell 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -85,7 +85,7 @@ dependencies = [
"miow 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"net2 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)",
"nix 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "slab 0.2.0 (git+https://github.com/carllerche/slab?rev=5476efcafb)",
+ "slab 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -157,8 +157,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "slab"
-version = "0.2.0"
-source = "git+https://github.com/carllerche/slab?rev=5476efcafb#5476efcafbc5ef4d7315b1bea3f756d8a1fe975e"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "thread-id"
View
@@ -7,8 +7,8 @@ authors = ["Herman J. Radtke III <hermanradtke@gmail.com>"]
byteorder = "0.3"
env_logger = "0.3.1"
log = "0.3.1"
-mio = { git = "https://github.com/carllerche/mio", rev = "ce5d4fb" }
-slab = { git = "https://github.com/carllerche/slab", rev = "5476efcafb" }
+mio = "0.6.0"
+slab = "0.3.0"
[[bin]]
name = "mob-server"
View
@@ -28,18 +28,16 @@ impl Server {
Server {
sock: sock,
- // I don't use Token(0) because kqueue will send stuff to Token(0)
- // by default causing really strange behavior. This way, if I see
- // something as Token(0), I know there are kqueue shenanigans
- // going on.
- token: Token(1),
+ // Give our server token a number much larger than our slab capacity. The slab used to
+ // track an internal offset, but does not anymore.
+ token: Token(10_000_000),
// SERVER is Token(1), so start after that
// we can deal with a max of 126 connections
- conns: Slab::new_starting_at(Token(2), 128),
+ conns: Slab::with_capacity(128),
// list of events from the poller that the server needs to process
- events: Events::new(),
+ events: Events::with_capacity(1024),
}
}
@@ -122,7 +120,6 @@ impl Server {
fn ready(&mut self, poll: &mut Poll, token: Token, event: Ready) {
debug!("{:?} event = {:?}", token, event);
- assert!(token != Token(0), "[BUG]: Received event for Server token {:?}", token);
if event.is_error() {
warn!("Error event for {:?}", token);
@@ -204,25 +201,25 @@ impl Server {
}
};
- match self.conns.insert_with(|token| {
- debug!("registering {:?} with poller", token);
- Connection::new(sock, token)
- }) {
- Some(token) => {
- // If we successfully insert, then register our connection.
- match self.find_connection_by_token(token).register(poll) {
- Ok(_) => {},
- Err(e) => {
- error!("Failed to register {:?} connection with poller, {:?}", token, e);
- self.conns.remove(token);
- }
- }
- },
+ let token = match self.conns.vacant_entry() {
+ Some(entry) => {
+ debug!("registering {:?} with poller", entry.index());
+ let c = Connection::new(sock, entry.index());
+ entry.insert(c).index()
+ }
None => {
- // If we fail to insert, `conn` will go out of scope and be dropped.
error!("Failed to insert connection into slab");
+ return;
}
};
+
+ match self.find_connection_by_token(token).register(poll) {
+ Ok(_) => {},
+ Err(e) => {
+ error!("Failed to register {:?} connection with poller, {:?}", token, e);
+ self.conns.remove(token);
+ }
+ }
}
}

0 comments on commit 70cac3b

Please sign in to comment.