diff --git a/src/handler.rs b/src/handler.rs index a53652a46..eab906347 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -1,72 +1,17 @@ -use reactor::{Reactor}; +use reactor::Reactor; +use token::Token; #[allow(unused_variable)] -pub trait Handler { - fn readable(&mut self, reactor: &mut Reactor, token: T) { +pub trait Handler { + fn readable(&mut self, reactor: &mut Reactor, token: Token) { } - fn writable(&mut self, reactor: &mut Reactor, token: T) { + fn writable(&mut self, reactor: &mut Reactor, token: Token) { } - fn notify(&mut self, reactor: &mut Reactor, msg: M) { + fn notify(&mut self, reactor: &mut Reactor, msg: M) { } - fn timeout(&mut self, reactor: &mut Reactor, timeout: T2) { - } -} - -pub trait Token : Copy { - fn from_u64(val: u64) -> Self; - - fn to_u64(self) -> u64; -} - -impl Token for int { - fn from_u64(val: u64) -> int { - val as int - } - - fn to_u64(self) -> u64 { - self as u64 - } -} - -impl Token for uint { - fn from_u64(val: u64) -> uint { - val as uint - } - - fn to_u64(self) -> u64 { - self as u64 - } -} - -impl Token for i64 { - fn from_u64(val: u64) -> i64 { - val as i64 - } - - fn to_u64(self) -> u64 { - self as u64 - } -} - -impl Token for u64 { - fn from_u64(val: u64) -> u64 { - val - } - - fn to_u64(self) -> u64 { - self - } -} - -impl Token for () { - fn from_u64(_: u64) -> () { - () - } - - fn to_u64(self) -> u64 { - 0 + fn timeout(&mut self, reactor: &mut Reactor, timeout: T) { } } diff --git a/src/lib.rs b/src/lib.rs index 6b729305b..61dd2e89b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -53,6 +53,11 @@ pub use timer::{ Timer, Timeout, }; +pub use token::{ + Token, + TOKEN_0, + TOKEN_1, +}; pub mod buf; mod error; @@ -65,3 +70,4 @@ mod reactor; mod slab; mod socket; mod timer; +mod token; diff --git a/src/os/epoll.rs b/src/os/epoll.rs index 6da4e7741..10070f853 100644 --- a/src/os/epoll.rs +++ b/src/os/epoll.rs @@ -28,12 +28,12 @@ impl Selector { } /// Register event interests for the given IO handle with the OS - pub fn register(&mut self, io: &IoDesc, token: u64) -> MioResult<()> { + pub fn register(&mut self, io: &IoDesc, token: uint) -> MioResult<()> { let interests = EPOLLIN | EPOLLOUT | EPOLLERR; let info = EpollEvent { events: interests | EPOLLET, - data: token + data: token as u64 }; epoll_ctl(self.epfd, EpollCtlAdd, io.fd, &info) diff --git a/src/os/kqueue.rs b/src/os/kqueue.rs index 4c67f7c55..a6ed017d2 100644 --- a/src/os/kqueue.rs +++ b/src/os/kqueue.rs @@ -29,7 +29,7 @@ impl Selector { Ok(()) } - pub fn register(&mut self, io: &IoDesc, token: u64) -> MioResult<()> { + pub fn register(&mut self, io: &IoDesc, token: uint) -> MioResult<()> { let flag = EV_ADD | EV_CLEAR; try!(self.ev_push(io, EVFILT_READ, flag, FilterFlag::empty(), token)); @@ -45,7 +45,7 @@ impl Selector { filter: EventFilter, flags: EventFlag, fflags: FilterFlag, - token: u64) -> MioResult<()> { + token: uint) -> MioResult<()> { // If the change buffer is full, flush it try!(self.maybe_flush_changes()); @@ -53,8 +53,7 @@ impl Selector { let idx = self.changes.len; let ev = &mut self.changes.events[idx]; - // TODO: Don't cast to uint - ev_set(ev, io.fd as uint, filter, flags, fflags, token as uint); + ev_set(ev, io.fd as uint, filter, flags, fflags, token); self.changes.len += 1; @@ -121,8 +120,7 @@ impl Events { } } - // TODO: Don't cast - IoEvent::new(kind, token as u64) + IoEvent::new(kind, token) } #[inline] diff --git a/src/poll.rs b/src/poll.rs index 49562ee91..f579c808b 100644 --- a/src/poll.rs +++ b/src/poll.rs @@ -1,6 +1,7 @@ use error::MioResult; use io::IoHandle; use os; +use token::Token; pub struct Poll { selector: os::Selector, @@ -15,11 +16,11 @@ impl Poll { }) } - pub fn register(&mut self, io: &H, token: u64) -> MioResult<()> { + pub fn register(&mut self, io: &H, token: Token) -> MioResult<()> { debug!("registering IO with poller"); // Register interests for this socket - try!(self.selector.register(io.desc(), token)); + try!(self.selector.register(io.desc(), token.as_uint())); Ok(()) } @@ -47,7 +48,7 @@ bitflags!( #[deriving(Show)] pub struct IoEvent { kind: IoEventKind, - token: u64 + token: Token } /// IoEvent represents the raw event that the OS-specific selector @@ -58,14 +59,14 @@ pub struct IoEvent { /// Selector when they have events to report. impl IoEvent { /// Create a new IoEvent. - pub fn new(kind: IoEventKind, token: u64) -> IoEvent { + pub fn new(kind: IoEventKind, token: uint) -> IoEvent { IoEvent { kind: kind, - token: token + token: Token(token) } } - pub fn token(&self) -> u64 { + pub fn token(&self) -> Token { self.token } diff --git a/src/reactor.rs b/src/reactor.rs index adde12cf7..f1f4ff2e6 100644 --- a/src/reactor.rs +++ b/src/reactor.rs @@ -1,13 +1,14 @@ use std::default::Default; -use std::u64; +use std::uint; use error::{MioResult, MioError}; -use handler::{Handler, Token}; +use handler::Handler; use io::{IoAcceptor, IoHandle}; use notify::Notify; use os; use poll::{Poll, IoEvent}; use socket::{Socket, SockAddr}; use timer::{Timer, Timeout, TimerResult}; +use token::Token; /// A lightweight IO reactor. /// @@ -41,24 +42,24 @@ impl Default for ReactorConfig { } } -pub struct Reactor { +pub struct Reactor { run: bool, poll: Poll, - timer: Timer, + timer: Timer, notify: Notify, config: ReactorConfig, } // Token used to represent notifications -static NOTIFY: u64 = u64::MAX; +static NOTIFY: Token = Token(uint::MAX); -impl Reactor { +impl Reactor { /// Initializes a new reactor. The reactor will not be running yet. - pub fn new() -> MioResult> { + pub fn new() -> MioResult> { Reactor::configured(Default::default()) } - pub fn configured(config: ReactorConfig) -> MioResult> { + pub fn configured(config: ReactorConfig) -> MioResult> { // Create the IO poller let mut poll = try!(Poll::new()); @@ -94,7 +95,7 @@ impl Reactor { /// After the requested time interval, the handler's `timeout` function /// will be called with the supplied token. - pub fn timeout_ms(&mut self, token: T2, delay: u64) -> TimerResult { + pub fn timeout_ms(&mut self, token: T, delay: u64) -> TimerResult { self.timer.timeout_ms(token, delay) } @@ -116,8 +117,8 @@ impl Reactor { } /// Registers an IO handle with the reactor. - pub fn register(&mut self, io: &H, token: T) -> MioResult<()> { - self.poll.register(io, token.to_u64()) + pub fn register(&mut self, io: &H, token: Token) -> MioResult<()> { + self.poll.register(io, token) } /// Connects the socket to the specified address. When the operation @@ -127,9 +128,7 @@ impl Reactor { /// notify about the connection, even if the connection happens /// immediately. Otherwise, every consumer of the reactor would have /// to worry about possibly-immediate connection. - pub fn connect(&mut self, io: &S, - addr: &SockAddr, token: T) -> MioResult<()> { - + pub fn connect(&mut self, io: &S, addr: &SockAddr, token: Token) -> MioResult<()> { debug!("socket connect; addr={}", addr); // Attempt establishing the context. This may not complete immediately. @@ -146,8 +145,8 @@ impl Reactor { Ok(()) } - pub fn listen>(&mut self, io: &A, backlog: uint, - token: T) -> MioResult<()> { + pub fn listen>( + &mut self, io: &A, backlog: uint, token: Token) -> MioResult<()> { debug!("socket listen"); @@ -162,7 +161,7 @@ impl Reactor { /// Keep spinning the reactor indefinitely, and notify the handler whenever /// any of the registered handles are ready. - pub fn run>(&mut self, mut handler: H) -> ReactorResult { + pub fn run>(&mut self, mut handler: H) -> ReactorResult { self.run = true; while self.run { @@ -179,7 +178,7 @@ impl Reactor { /// Spin the reactor once, with a timeout of one second, and notify the /// handler if any of the registered handles become ready during that /// time. - pub fn run_once>(&mut self, mut handler: H) -> ReactorResult { + pub fn run_once>(&mut self, mut handler: H) -> ReactorResult { // Execute a single tick match self.tick(&mut handler) { Err(e) => return Err(ReactorError::new(handler, e)), @@ -190,7 +189,7 @@ impl Reactor { } // Executes a single run of the reactor loop - fn tick>(&mut self, handler: &mut H) -> MioResult<()> { + fn tick>(&mut self, handler: &mut H) -> MioResult<()> { let mut messages; let mut pending; @@ -237,7 +236,7 @@ impl Reactor { } // Process IO events that have been previously polled - fn io_process>(&mut self, handler: &mut H, cnt: uint) { + fn io_process>(&mut self, handler: &mut H, cnt: uint) { let mut i = 0u; // Iterate over the notifications. Each event provides the token @@ -258,8 +257,8 @@ impl Reactor { } } - fn io_event>(&mut self, handler: &mut H, evt: IoEvent) { - let tok = Token::from_u64(evt.token()); + fn io_event>(&mut self, handler: &mut H, evt: IoEvent) { + let tok = evt.token(); if evt.is_readable() { handler.readable(self, tok); @@ -274,7 +273,7 @@ impl Reactor { } } - fn notify>(&mut self, handler: &mut H, mut cnt: uint) { + fn notify>(&mut self, handler: &mut H, mut cnt: uint) { while cnt > 0 { let msg = self.notify.poll() .expect("[BUG] at this point there should always be a message"); @@ -284,7 +283,7 @@ impl Reactor { } } - fn timer_process>(&mut self, handler: &mut H) { + fn timer_process>(&mut self, handler: &mut H) { let now = self.timer.now(); loop { @@ -334,9 +333,9 @@ mod tests { use std::sync::atomics::{AtomicInt, SeqCst}; use super::Reactor; use io::{IoWriter, IoReader}; - use {io, buf, Buf, Handler}; + use {io, buf, Buf, Handler, Token}; - type TestReactor = Reactor; + type TestReactor = Reactor; struct Funtimes { rcount: Arc, @@ -352,10 +351,10 @@ mod tests { } } - impl Handler for Funtimes { - fn readable(&mut self, _reactor: &mut TestReactor, token: u64) { + impl Handler for Funtimes { + fn readable(&mut self, _reactor: &mut TestReactor, token: Token) { (*self.rcount).fetch_add(1, SeqCst); - assert_eq!(token, 10u64); + assert_eq!(token, Token(10)); } } @@ -370,7 +369,7 @@ mod tests { let handler = Funtimes::new(rcount.clone(), wcount.clone()); writer.write(&mut buf::wrap("hello".as_bytes())).unwrap(); - reactor.register(&reader, 10u64).unwrap(); + reactor.register(&reader, Token(10)).unwrap(); let _ = reactor.run_once(handler); let mut b = buf::ByteBuf::new(16); diff --git a/src/slab.rs b/src/slab.rs index 593117c4c..4de63763b 100644 --- a/src/slab.rs +++ b/src/slab.rs @@ -1,5 +1,6 @@ use std::{mem, ptr, int}; use alloc::heap; +use token::Token; /// A preallocated chunk of memory for storing objects of the same type. pub struct Slab { @@ -9,6 +10,8 @@ pub struct Slab { len: int, // The total number of elements that the slab can hold cap: int, + // THe token offset + off: uint, // Offset of the next available slot in the slab. Set to the slab's // capacity when the slab is full. nxt: int, @@ -23,6 +26,10 @@ static IN_USE: int = -1; impl Slab { pub fn new(cap: uint) -> Slab { + Slab::new_starting_at(Token(0), cap) + } + + pub fn new_starting_at(offset: Token, cap: uint) -> Slab { assert!(cap <= MAX, "capacity too large"); // TODO: // - Rename to with_capacity @@ -38,8 +45,9 @@ impl Slab { mem: ptr as *mut Entry, cap: cap as int, len: 0, + off: offset.as_uint(), nxt: 0, - init: 0 + init: 0, } } @@ -76,7 +84,9 @@ impl Slab { false } - pub fn get(&self, idx: uint) -> Option<&T> { + pub fn get(&self, idx: Token) -> Option<&T> { + let idx = self.token_to_idx(idx); + if idx <= MAX { let idx = idx as int; @@ -92,7 +102,7 @@ impl Slab { None } - pub fn insert(&mut self, val: T) -> Result { + pub fn insert(&mut self, val: T) -> Result { let idx = self.nxt; if idx == self.init { @@ -118,13 +128,16 @@ impl Slab { debug!("inserting into reused slot; idx={}", idx); } - Ok(idx as uint) + Ok(self.idx_to_token(idx)) } /// Releases the given slot - pub fn remove(&mut self, idx: uint) -> Option { + pub fn remove(&mut self, idx: Token) -> Option { debug!("removing value; idx={}", idx); + // Cast to uint + let idx = self.token_to_idx(idx); + if idx > MAX { return None; } @@ -170,11 +183,20 @@ impl Slab { fail!("invalid index {} -- greater than capacity {}", idx, self.cap); } + + fn token_to_idx(&self, token: Token) -> uint { + token.as_uint() - self.off + } + + fn idx_to_token(&self, idx: int) -> Token { + Token(idx as uint + self.off) + } } -impl Index for Slab { - fn index<'a>(&'a self, idx: &uint) -> &'a T { - let idx = self.validate_idx(*idx); +impl Index for Slab { + fn index<'a>(&'a self, idx: &Token) -> &'a T { + let idx = self.token_to_idx(*idx); + let idx = self.validate_idx(idx); let e = self.entry(idx); @@ -186,9 +208,10 @@ impl Index for Slab { } } -impl IndexMut for Slab { - fn index_mut<'a>(&'a mut self, idx: &uint) -> &'a mut T { - let idx = self.validate_idx(*idx); +impl IndexMut for Slab { + fn index_mut<'a>(&'a mut self, idx: &Token) -> &'a mut T { + let idx = self.token_to_idx(*idx); + let idx = self.validate_idx(idx); let e = self.mut_entry(idx); @@ -257,7 +280,7 @@ impl Entry { #[cfg(test)] mod tests { - use super::Slab; + use {Slab, Token}; #[test] fn test_insertion() { @@ -374,6 +397,6 @@ mod tests { #[should_fail] fn test_accessing_out_of_bounds() { let slab = Slab::::new(16); - slab[0]; + slab[Token(0)]; } } diff --git a/src/timer.rs b/src/timer.rs index 22b7d645e..c8c9facca 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -2,8 +2,9 @@ use std::uint; use std::num; use time::precise_time_ns; use slab::Slab; +use token::Token; -static EMPTY: uint = uint::MAX; +static EMPTY: Token = Token(uint::MAX); static NS_PER_MS: u64 = 1_000_000; // Implements coarse-grained timeouts using an algorithm based on hashed timing @@ -20,20 +21,20 @@ pub struct Timer { entries: Slab>, // Timeout wheel. Each tick, the timer will look at the next slot for // timeouts that match the current tick. - wheel: Vec, + wheel: Vec, // Tick 0's time in milliseconds start: u64, // The current tick tick: u64, // The next entry to possibly timeout - next: uint, + next: Token, // Masks the target tick to get the slot mask: u64, } pub struct Timeout { // Reference into the timer entry slab - token: uint, + token: Token, // Tick that it should matchup with tick: u64, } @@ -156,7 +157,7 @@ impl Timer { }) } - fn unlink(&mut self, links: &EntryLinks, token: uint) { + fn unlink(&mut self, links: &EntryLinks, token: Token) { debug!("unlinking timeout; slot={}; token={}", self.slot_for(links.tick), token); @@ -257,7 +258,7 @@ struct Entry { } impl Entry { - fn new(token: T, tick: u64, next: uint) -> Entry { + fn new(token: T, tick: u64, next: Token) -> Entry { Entry { token: token, links: EntryLinks { @@ -271,8 +272,8 @@ impl Entry { struct EntryLinks { tick: u64, - prev: uint, - next: uint + prev: Token, + next: Token } pub type TimerResult = Result; diff --git a/src/token.rs b/src/token.rs new file mode 100644 index 000000000..ef23af86e --- /dev/null +++ b/src/token.rs @@ -0,0 +1,14 @@ +#[deriving(Show, PartialEq, Eq)] +pub struct Token(pub uint); + +impl Token { + #[inline] + pub fn as_uint(self) -> uint { + let Token(inner) = self; + inner + } +} + +// Work around for https://github.com/rust-lang/rust/issues/17169 +pub static TOKEN_0:Token = Token(0); +pub static TOKEN_1:Token = Token(1); diff --git a/test/test_close_on_drop.rs b/test/test_close_on_drop.rs index 774f89fc3..c1212331e 100644 --- a/test/test_close_on_drop.rs +++ b/test/test_close_on_drop.rs @@ -2,7 +2,7 @@ use mio::*; use mio::buf::ByteBuf; use super::localhost; -type TestReactor = Reactor; +type TestReactor = Reactor; struct TestHandler { srv: TcpAcceptor, @@ -18,14 +18,14 @@ impl TestHandler { } } -impl Handler for TestHandler { - fn readable(&mut self, reactor: &mut TestReactor, tok: uint) { +impl Handler for TestHandler { + fn readable(&mut self, reactor: &mut TestReactor, tok: Token) { match tok { - 0 => { + Token(0) => { debug!("server connection ready for accept"); let _ = self.srv.accept().unwrap().unwrap(); } - 1 => { + Token(1) => { debug!("client readable"); let mut buf = ByteBuf::new(1024); match self.cli.read(&mut buf) { @@ -37,10 +37,10 @@ impl Handler for TestHandler { } } - fn writable(&mut self, _reactor: &mut TestReactor, tok: uint) { + fn writable(&mut self, _reactor: &mut TestReactor, tok: Token) { match tok { - 0 => fail!("received writable for token 0"), - 1 => { + Token(0) => fail!("received writable for token 0"), + Token(1) => { debug!("client connected"); } _ => fail!("received unknown token {}", tok) @@ -63,12 +63,12 @@ pub fn test_close_on_drop() { let srv = srv.bind(&addr).unwrap(); info!("listening for connections"); - reactor.listen(&srv, 256u, 0u).unwrap(); + reactor.listen(&srv, 256u, Token(0)).unwrap(); let sock = TcpSocket::v4().unwrap(); // Connect to the server - reactor.connect(&sock, &addr, 1u).unwrap(); + reactor.connect(&sock, &addr, Token(1)).unwrap(); // Start the reactor reactor.run(TestHandler::new(srv, sock)) diff --git a/test/test_echo_server.rs b/test/test_echo_server.rs index 4b01f0fef..c00f7a53f 100644 --- a/test/test_echo_server.rs +++ b/test/test_echo_server.rs @@ -2,7 +2,10 @@ use mio::*; use mio::buf::{ByteBuf, RingBuf, SliceBuf}; use super::localhost; -type TestReactor = Reactor; +type TestReactor = Reactor; + +static SERVER: Token = TOKEN_0; +static CLIENT: Token = TOKEN_1; struct EchoConn { sock: TcpSocket, @@ -90,22 +93,22 @@ impl EchoServer { .ok().expect("could not add connectiont o slab"); // Register the connection - reactor.register(&self.conns[tok].sock, 2 + tok) + reactor.register(&self.conns[tok].sock, tok) .ok().expect("could not register socket with reactor"); } - fn conn_readable(&mut self, tok: uint) { + fn conn_readable(&mut self, tok: Token) { debug!("server conn readable; tok={}", tok); self.conn(tok).readable().unwrap(); } - fn conn_writable(&mut self, tok: uint) { + fn conn_writable(&mut self, tok: Token) { debug!("server conn writable; tok={}", tok); self.conn(tok).writable().unwrap(); } - fn conn<'a>(&'a mut self, tok: uint) -> &'a mut EchoConn { - &mut self.conns[tok - 2] + fn conn<'a>(&'a mut self, tok: Token) -> &'a mut EchoConn { + &mut self.conns[tok] } } @@ -216,7 +219,7 @@ impl EchoHandler { EchoHandler { server: EchoServer { sock: srv, - conns: Slab::new(128) + conns: Slab::new_starting_at(Token(2), 128) }, client: EchoClient::new(client, msgs) @@ -224,19 +227,19 @@ impl EchoHandler { } } -impl Handler for EchoHandler { - fn readable(&mut self, reactor: &mut TestReactor, token: uint) { +impl Handler for EchoHandler { + fn readable(&mut self, reactor: &mut TestReactor, token: Token) { match token { - 0 => self.server.accept(reactor), - 1 => self.client.readable(reactor), + SERVER => self.server.accept(reactor), + CLIENT => self.client.readable(reactor), i => self.server.conn_readable(i) } } - fn writable(&mut self, _reactor: &mut TestReactor, token: uint) { + fn writable(&mut self, _reactor: &mut TestReactor, token: Token) { match token { - 0 => fail!("received writable for token 0"), - 1 => self.client.writable(), + SERVER => fail!("received writable for token 0"), + CLIENT => self.client.writable(), i => self.server.conn_writable(i) } } @@ -257,12 +260,12 @@ pub fn test_echo_server() { let srv = srv.bind(&addr).unwrap(); info!("listen for connections"); - reactor.listen(&srv, 256u, 0u).unwrap(); + reactor.listen(&srv, 256u, SERVER).unwrap(); let sock = TcpSocket::v4().unwrap(); // Connect to the server - reactor.connect(&sock, &addr, 1u).unwrap(); + reactor.connect(&sock, &addr, CLIENT).unwrap(); // Start the reactor reactor.run(EchoHandler::new(srv, sock, vec!["foo", "bar"])) diff --git a/test/test_notify.rs b/test/test_notify.rs index 65549e98d..fabf198dc 100644 --- a/test/test_notify.rs +++ b/test/test_notify.rs @@ -3,7 +3,7 @@ use std::time::Duration; use mio::*; use super::localhost; -type TestReactor = Reactor; +type TestReactor = Reactor; struct TestHandler { sender: ReactorSender, @@ -19,7 +19,7 @@ impl TestHandler { } } -impl Handler for TestHandler { +impl Handler for TestHandler { fn notify(&mut self, reactor: &mut TestReactor, msg: String) { match self.notify { 0 => { @@ -48,7 +48,7 @@ pub fn test_notify() { let srv = TcpSocket::v4().unwrap(); srv.set_reuseaddr(true).unwrap(); let srv = srv.bind(&addr).unwrap(); - reactor.listen(&srv, 256u, 0u).unwrap(); + reactor.listen(&srv, 256u, Token(0)).unwrap(); let sender = reactor.channel(); diff --git a/test/test_timer.rs b/test/test_timer.rs index 1d7d8f83a..331a21568 100644 --- a/test/test_timer.rs +++ b/test/test_timer.rs @@ -1,7 +1,10 @@ use mio::*; use super::localhost; -type TestReactor = Reactor; +type TestReactor = Reactor; + +static SERVER: Token = TOKEN_0; +static CLIENT: Token = TOKEN_1; struct TestHandler { srv: TcpAcceptor, @@ -17,15 +20,15 @@ impl TestHandler { } } -impl Handler for TestHandler { - fn readable(&mut self, reactor: &mut TestReactor, tok: uint) { +impl Handler for TestHandler { + fn readable(&mut self, reactor: &mut TestReactor, tok: Token) { match tok { - 0 => { + SERVER => { debug!("server connection ready for accept"); let conn = self.srv.accept().unwrap().unwrap(); reactor.timeout_ms(conn, 200).unwrap(); } - 1 => { + CLIENT => { debug!("client readable"); let mut buf = buf::ByteBuf::new(1024); match self.cli.read(&mut buf) { @@ -41,10 +44,10 @@ impl Handler for TestHandler { } } - fn writable(&mut self, _reactor: &mut TestReactor, tok: uint) { + fn writable(&mut self, _reactor: &mut TestReactor, tok: Token) { match tok { - 0 => fail!("received writable for token 0"), - 1 => debug!("client connected"), + SERVER => fail!("received writable for token 0"), + CLIENT => debug!("client connected"), _ => fail!("received unknown token {}", tok) } } @@ -70,12 +73,12 @@ pub fn test_close_on_drop() { let srv = srv.bind(&addr).unwrap(); info!("listening for connections"); - reactor.listen(&srv, 256u, 0u).unwrap(); + reactor.listen(&srv, 256u, SERVER).unwrap(); let sock = TcpSocket::v4().unwrap(); // Connect to the server - reactor.connect(&sock, &addr, 1u).unwrap(); + reactor.connect(&sock, &addr, CLIENT).unwrap(); // Start the reactor reactor.run(TestHandler::new(srv, sock))