Skip to content

Update hyper to latest nightly #324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
2 changes: 1 addition & 1 deletion benches/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(core, io, test)]
#![feature(core, old_io, test)]
extern crate hyper;

extern crate test;
Expand Down
2 changes: 1 addition & 1 deletion benches/client_mock_tcp.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(collections, io, test)]
#![feature(collections, old_io, test)]
extern crate hyper;

extern crate test;
Expand Down
2 changes: 1 addition & 1 deletion benches/server.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(io, test)]
#![feature(old_io, test)]
extern crate hyper;
extern crate test;

Expand Down
2 changes: 1 addition & 1 deletion examples/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(env, io)]
#![feature(env, old_io)]
extern crate hyper;

use std::env;
Expand Down
2 changes: 1 addition & 1 deletion examples/hello.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(io)]
#![feature(old_io)]
extern crate hyper;

use std::old_io::net::ip::Ipv4Addr;
Expand Down
2 changes: 1 addition & 1 deletion examples/server.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(io)]
#![feature(old_io)]
extern crate hyper;
#[macro_use] extern crate log;

Expand Down
4 changes: 2 additions & 2 deletions src/header/common/authorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl<S: Scheme> DerefMut for Authorization<S> {
}
}

impl<S: Scheme> Header for Authorization<S> {
impl<S: Scheme + 'static> Header for Authorization<S> {
fn header_name() -> &'static str {
"Authorization"
}
Expand All @@ -43,7 +43,7 @@ impl<S: Scheme> Header for Authorization<S> {
}
}

impl<S: Scheme> HeaderFormat for Authorization<S> {
impl<S: Scheme + 'static> HeaderFormat for Authorization<S> {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match Scheme::scheme(None::<S>) {
Some(scheme) => try!(write!(fmt, "{} ", scheme)),
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![feature(core, collections, hash, io, os, path, std_misc,
slicing_syntax, box_syntax, unsafe_destructor)]
#![feature(core, collections, hash, io, old_io, os, old_path,
std_misc, box_syntax, unsafe_destructor)]
#![deny(missing_docs)]
#![cfg_attr(test, deny(warnings))]
#![cfg_attr(test, feature(alloc, test))]
Expand Down
2 changes: 1 addition & 1 deletion src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub trait NetworkAcceptor: Clone + Send {
}

/// An iterator wrapper over a NetworkAcceptor.
pub struct NetworkConnections<'a, N: NetworkAcceptor>(&'a mut N);
pub struct NetworkConnections<'a, N: NetworkAcceptor + 'a>(&'a mut N);

impl<'a, N: NetworkAcceptor> Iterator for NetworkConnections<'a, N> {
type Item = IoResult<N::Stream>;
Expand Down
19 changes: 9 additions & 10 deletions src/server/acceptor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::thread::{Thread, JoinGuard};
use std::thread::{self, JoinGuard};
use std::sync::Arc;
use std::sync::mpsc;
use net::NetworkAcceptor;
Expand All @@ -7,7 +7,7 @@ pub struct AcceptorPool<A: NetworkAcceptor> {
acceptor: A
}

impl<A: NetworkAcceptor> AcceptorPool<A> {
impl<A: NetworkAcceptor + 'static> AcceptorPool<A> {
/// Create a thread pool to manage the acceptor.
pub fn new(acceptor: A) -> AcceptorPool<A> {
AcceptorPool { acceptor: acceptor }
Expand All @@ -18,9 +18,8 @@ impl<A: NetworkAcceptor> AcceptorPool<A> {
/// ## Panics
///
/// Panics if threads == 0.
pub fn accept<F: Fn(A::Stream) + Send + Sync>(self,
work: F,
threads: usize) -> JoinGuard<'static, ()> {
pub fn accept<F>(self, work: F, threads: usize) -> JoinGuard<'static, ()>
where F: Fn(A::Stream) + Send + Sync + 'static {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional advantage of making this blocking: 'a here instead of 'static, so this can be used with non-'static data.

assert!(threads != 0, "Can't accept on 0 threads.");

// Replace with &F when Send changes land.
Expand All @@ -35,16 +34,16 @@ impl<A: NetworkAcceptor> AcceptorPool<A> {
for _ in 0..threads { spawn() }

// Spawn the supervisor
Thread::scoped(move || for () in supervisor_rx.iter() { spawn() })
thread::scoped(move || for () in supervisor_rx.iter() { spawn() })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make this blocking we'd just remove the thread::scoped call here and just run this loop.

}
}

fn spawn_with<A, F>(supervisor: mpsc::Sender<()>, work: Arc<F>, mut acceptor: A)
where A: NetworkAcceptor,
F: Fn(<A as NetworkAcceptor>::Stream) + Send + Sync {
where A: NetworkAcceptor + 'static,
F: Fn(<A as NetworkAcceptor>::Stream) + Send + Sync + 'static {
use std::old_io::EndOfFile;

Thread::spawn(move || {
thread::spawn(move || {
let sentinel = Sentinel::new(supervisor, ());

loop {
Expand Down Expand Up @@ -83,7 +82,7 @@ impl<T: Send> Sentinel<T> {
}

#[unsafe_destructor]
impl<T: Send> Drop for Sentinel<T> {
impl<T: Send + 'static> Drop for Sentinel<T> {
fn drop(&mut self) {
// If we were cancelled, get out of here.
if !self.active { return; }
Expand Down
6 changes: 3 additions & 3 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Server<HttpListener> {

impl<
L: NetworkListener<Acceptor=A> + Send,
A: NetworkAcceptor<Stream=S> + Send,
A: NetworkAcceptor<Stream=S> + Send + 'static,
S: NetworkStream + Clone + Send> Server<L> {
/// Creates a new server that will handle `HttpStream`s.
pub fn with_listener(ip: IpAddr, port: Port, listener: L) -> Server<L> {
Expand All @@ -68,7 +68,7 @@ S: NetworkStream + Clone + Send> Server<L> {
}

/// Binds to a socket, and starts handling connections using a task pool.
pub fn listen_threads<H: Handler>(mut self, handler: H, threads: usize) -> HttpResult<Listening<L::Acceptor>> {
pub fn listen_threads<H: Handler + 'static>(mut self, handler: H, threads: usize) -> HttpResult<Listening<L::Acceptor>> {
debug!("binding to {:?}:{:?}", self.ip, self.port);
let acceptor = try!(self.listener.listen((self.ip, self.port)));
let socket = try!(acceptor.socket_name());
Expand All @@ -85,7 +85,7 @@ S: NetworkStream + Clone + Send> Server<L> {
}

/// Binds to a socket and starts handling connections.
pub fn listen<H: Handler>(self, handler: H) -> HttpResult<Listening<L::Acceptor>> {
pub fn listen<H: Handler + 'static>(self, handler: H) -> HttpResult<Listening<L::Acceptor>> {
self.listen_threads(handler, os::num_cpus() * 5 / 4)
}

Expand Down