Update for latest rust

Tracks rust nightly.

7 tests fail -- still finding source
This commit is contained in:
cyderize
2015-01-10 18:37:10 +11:00
parent 241ebc1270
commit 122e94c8a6
42 changed files with 291 additions and 189 deletions

View File

@@ -50,17 +50,17 @@ impl Server<HttpListener> {
}
}
impl<L: NetworkListener<S, A>, S: NetworkStream, A: NetworkAcceptor<S>> Server<L> {
/// Binds to a socket, and starts handling connections using a task pool.
impl<X> Server<X> {
/// Binds to a socket, and starts handling connections using a task pool.
///
/// This method has unbound type parameters, so can be used when you want to use
/// something other than the provided HttpStream, HttpAcceptor, and HttpListener.
pub fn listen_network<H, S, A, L>(self, handler: H, threads: uint) -> HttpResult<Listening<A>>
pub fn listen_network<H, S, A, L>(self, handler: H, threads: usize) -> HttpResult<Listening<A>>
where H: Handler,
S: NetworkStream + Clone,
A: NetworkAcceptor<S>,
L: NetworkListener<S, A>, {
debug!("binding to {}:{}", self.ip, self.port);
debug!("binding to {:?}:{:?}", self.ip, self.port);
let mut listener: L = try!(NetworkListener::<S, A>::bind((self.ip, self.port)));
let socket = try!(listener.socket_name());
@@ -68,9 +68,9 @@ impl<L: NetworkListener<S, A>, S: NetworkStream, A: NetworkAcceptor<S>> Server<L
let acceptor = try!(listener.listen());
let mut captured = acceptor.clone();
let guard = Builder::new().name("hyper acceptor".to_string()).spawn(move || {
let guard = Builder::new().name("hyper acceptor".to_string()).scoped(move || {
let handler = Arc::new(handler);
debug!("threads = {}", threads);
debug!("threads = {:?}", threads);
let pool = TaskPool::new(threads);
for conn in captured.incoming() {
match conn {
@@ -81,7 +81,7 @@ impl<L: NetworkListener<S, A>, S: NetworkStream, A: NetworkAcceptor<S>> Server<L
let addr = match stream.peer_name() {
Ok(addr) => addr,
Err(e) => {
error!("Peer Name error: {}", e);
error!("Peer Name error: {:?}", e);
return;
}
};
@@ -94,12 +94,12 @@ impl<L: NetworkListener<S, A>, S: NetworkStream, A: NetworkAcceptor<S>> Server<L
let req = match Request::new(&mut rdr, addr) {
Ok(req) => req,
Err(e@HttpIoError(_)) => {
debug!("ioerror in keepalive loop = {}", e);
debug!("ioerror in keepalive loop = {:?}", e);
return;
}
Err(e) => {
//TODO: send a 400 response
error!("request error = {}", e);
error!("request error = {:?}", e);
return;
}
};
@@ -111,7 +111,7 @@ impl<L: NetworkListener<S, A>, S: NetworkStream, A: NetworkAcceptor<S>> Server<L
};
res.version = req.version;
handler.handle(req, res);
debug!("keep_alive = {}", keep_alive);
debug!("keep_alive = {:?}", keep_alive);
}
});
@@ -134,9 +134,12 @@ impl<L: NetworkListener<S, A>, S: NetworkStream, A: NetworkAcceptor<S>> Server<L
socket: socket,
})
}
}
#[old_impl_check]
impl<L: NetworkListener<S, A>, S: NetworkStream, A: NetworkAcceptor<S>> Server<L> {
/// Binds to a socket and starts handling connections with the specified number of tasks.
pub fn listen_threads<H: Handler>(self, handler: H, threads: uint) -> HttpResult<Listening<HttpAcceptor>> {
pub fn listen_threads<H: Handler>(self, handler: H, threads: usize) -> HttpResult<Listening<HttpAcceptor>> {
self.listen_network::<H, HttpStream, HttpAcceptor, HttpListener>(handler, threads)
}
@@ -150,11 +153,12 @@ impl<L: NetworkListener<S, A>, S: NetworkStream, A: NetworkAcceptor<S>> Server<L
/// A listening server, which can later be closed.
pub struct Listening<A = HttpAcceptor> {
acceptor: A,
guard: Option<JoinGuard<()>>,
guard: Option<JoinGuard<'static, ()>>,
/// The socket addresses that the server is bound to.
pub socket: SocketAddr,
}
#[old_impl_check]
impl<A: NetworkAcceptor<S>, S: NetworkStream> Listening<A> {
/// Causes the current thread to wait for this listening to complete.
pub fn await(&mut self) {

View File

@@ -37,9 +37,9 @@ impl<'a> Request<'a> {
/// immediately useful.
pub fn new(mut stream: &'a mut (Reader + 'a), addr: SocketAddr) -> HttpResult<Request<'a>> {
let (method, uri, version) = try!(read_request_line(&mut stream));
debug!("Request Line: {} {} {}", method, uri, version);
debug!("Request Line: {:?} {:?} {:?}", method, uri, version);
let headers = try!(Headers::from_raw(&mut stream));
debug!("Headers: [\n{}]", headers);
debug!("Headers: [\n{:?}]", headers);
let body = if method == Get || method == Head {
@@ -68,7 +68,7 @@ impl<'a> Request<'a> {
}
impl<'a> Reader for Request<'a> {
fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
fn read(&mut self, buf: &mut [u8]) -> IoResult<usize> {
self.body.read(buf)
}
}

View File

@@ -67,7 +67,7 @@ impl<'a> Response<'a, Fresh> {
/// Consume this Response<Fresh>, writing the Headers and Status and creating a Response<Streaming>
pub fn start(mut self) -> IoResult<Response<'a, Streaming>> {
debug!("writing head: {} {}", self.version, self.status);
debug!("writing head: {:?} {:?}", self.version, self.status);
try!(write!(&mut self.body, "{} {}{}{}", self.version, self.status, CR as char, LF as char));
if !self.headers.has::<common::Date>() {
@@ -89,7 +89,7 @@ impl<'a> Response<'a, Fresh> {
// cant do in match above, thanks borrowck
if chunked {
let encodings = match self.headers.get_mut::<common::TransferEncoding>() {
Some(&common::TransferEncoding(ref mut encodings)) => {
Some(&mut common::TransferEncoding(ref mut encodings)) => {
//TODO: check if chunked is already in encodings. use HashSet?
encodings.push(common::transfer_encoding::Encoding::Chunked);
false
@@ -104,7 +104,7 @@ impl<'a> Response<'a, Fresh> {
}
debug!("headers [\n{}]", self.headers);
debug!("headers [\n{:?}]", self.headers);
try!(write!(&mut self.body, "{}", self.headers));
try!(self.body.write_str(LINE_ENDING));
@@ -143,7 +143,7 @@ impl<'a> Response<'a, Streaming> {
impl<'a> Writer for Response<'a, Streaming> {
fn write(&mut self, msg: &[u8]) -> IoResult<()> {
debug!("write {} bytes", msg.len());
debug!("write {:?} bytes", msg.len());
self.body.write(msg)
}