Split Server::listen into two methods to hack around ICE related to default type params
Trying to default the type parameters leads to an ICE and strange type errors. I think this is just due to the experimental state of default type params and this change can be rolled back when they are fixed.
This commit is contained in:
@@ -8,9 +8,8 @@ extern crate test;
|
||||
use std::fmt::{mod, Show};
|
||||
use std::io::net::ip::Ipv4Addr;
|
||||
use hyper::server::{Incoming, Server};
|
||||
use hyper::net::HttpAcceptor;
|
||||
|
||||
fn listen() -> hyper::server::Listening<HttpAcceptor> {
|
||||
fn listen() -> hyper::server::Listening {
|
||||
let server = Server::http(Ipv4Addr(127, 0, 0, 1), 0);
|
||||
server.listen(handle).unwrap()
|
||||
}
|
||||
@@ -70,11 +69,11 @@ fn bench_hyper(b: &mut test::Bencher) {
|
||||
let mut req = hyper::get(hyper::Url::parse(url).unwrap()).unwrap();
|
||||
req.headers.set(Foo);
|
||||
|
||||
req
|
||||
.send().unwrap()
|
||||
.read_to_string().unwrap()
|
||||
req
|
||||
.send().unwrap()
|
||||
.read_to_string().unwrap()
|
||||
});
|
||||
listening.close().unwrap()
|
||||
listening.close().unwrap()
|
||||
}
|
||||
|
||||
#[bench]
|
||||
|
||||
@@ -28,9 +28,9 @@ fn hyper_handle(mut incoming: hyper::server::Incoming) {
|
||||
#[bench]
|
||||
fn bench_hyper(b: &mut Bencher) {
|
||||
let server = hyper::Server::http(Ipv4Addr(127, 0, 0, 1), 0);
|
||||
let listener = server.listen(hyper_handle).unwrap();
|
||||
let mut listener = server.listen(hyper_handle).unwrap();
|
||||
|
||||
let url = hyper::Url::parse(format!("http://{}", listener.socket_addr).as_slice()).unwrap();
|
||||
let url = hyper::Url::parse(format!("http://{}", listener.sockets[0]).as_slice()).unwrap();
|
||||
b.iter(|| request(url.clone()));
|
||||
listener.close().unwrap();
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ trait ConcurrentHandler: Send + Sync {
|
||||
struct Concurrent<H: ConcurrentHandler> { handler: Arc<H> }
|
||||
|
||||
impl<H: ConcurrentHandler> Handler<HttpAcceptor, HttpStream> for Concurrent<H> {
|
||||
fn handle(self, mut incoming: Incoming<HttpAcceptor>) {
|
||||
fn handle(self, mut incoming: Incoming) {
|
||||
for (mut req, mut res) in incoming {
|
||||
let clone = self.handler.clone();
|
||||
spawn(proc() { clone.handle(req, res) })
|
||||
|
||||
@@ -46,11 +46,14 @@ impl Server<HttpListener> {
|
||||
|
||||
impl<L: NetworkListener<S, A>, S: NetworkStream, A: NetworkAcceptor<S>> Server<L> {
|
||||
/// Binds to a socket, and starts handling connections.
|
||||
pub fn listen<S, A, H, L>(self, handler: H) -> HttpResult<Listening<A>>
|
||||
where S: NetworkStream,
|
||||
///
|
||||
/// 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) -> HttpResult<Listening<A>>
|
||||
where H: Handler<A, S>,
|
||||
S: NetworkStream,
|
||||
A: NetworkAcceptor<S>,
|
||||
H: Handler<A, S>,
|
||||
L: NetworkListener<S, A> {
|
||||
L: NetworkListener<S, A>, {
|
||||
let mut acceptors = Vec::new();
|
||||
let mut sockets = Vec::new();
|
||||
for (ip, port) in self.pairs.move_iter() {
|
||||
@@ -76,6 +79,11 @@ impl<L: NetworkListener<S, A>, S: NetworkStream, A: NetworkAcceptor<S>> Server<L
|
||||
sockets: sockets,
|
||||
})
|
||||
}
|
||||
|
||||
/// Binds to a socket and starts handling connections.
|
||||
pub fn listen<H: Handler<HttpAcceptor, HttpStream>>(self, handler: H) -> HttpResult<Listening<HttpAcceptor>> {
|
||||
self.listen_network::<H, HttpStream, HttpAcceptor, HttpListener>(handler)
|
||||
}
|
||||
}
|
||||
|
||||
/// An iterator over incoming connections, represented as pairs of
|
||||
|
||||
Reference in New Issue
Block a user