feat(server): keep-alive!
Internals have been shuffled around such that Request and Reponse are now given only a mutable reference to the stream, instead of being allowed to consume it. This allows the server to re-use the streams if keep-alive is true. A task pool is used, and the number of the threads can currently be adjusted by using the `listen_threads()` method on Server. [breaking-change]
This commit is contained in:
@@ -7,28 +7,25 @@ extern crate test;
|
||||
|
||||
use std::fmt::{mod, Show};
|
||||
use std::io::net::ip::Ipv4Addr;
|
||||
use hyper::server::{Incoming, Server};
|
||||
use hyper::server::{Request, Response, Server};
|
||||
|
||||
fn listen() -> hyper::server::Listening {
|
||||
let server = Server::http(Ipv4Addr(127, 0, 0, 1), 0);
|
||||
server.listen(handle).unwrap()
|
||||
}
|
||||
|
||||
macro_rules! try_continue(
|
||||
macro_rules! try_return(
|
||||
($e:expr) => {{
|
||||
match $e {
|
||||
Ok(v) => v,
|
||||
Err(..) => continue
|
||||
Err(..) => return
|
||||
}
|
||||
}})
|
||||
|
||||
fn handle(mut incoming: Incoming) {
|
||||
for conn in incoming {
|
||||
let (_, res) = try_continue!(conn.open());
|
||||
let mut res = try_continue!(res.start());
|
||||
try_continue!(res.write(b"Benchmarking hyper vs others!"))
|
||||
try_continue!(res.end());
|
||||
}
|
||||
fn handle(_: Request, res: Response) {
|
||||
let mut res = try_return!(res.start());
|
||||
try_return!(res.write(b"Benchmarking hyper vs others!"))
|
||||
try_return!(res.end());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ use test::Bencher;
|
||||
use std::io::net::ip::{SocketAddr, Ipv4Addr};
|
||||
|
||||
use http::server::Server;
|
||||
use hyper::server::{Request, Response};
|
||||
|
||||
static PHRASE: &'static [u8] = b"Benchmarking hyper vs others!";
|
||||
|
||||
@@ -17,13 +18,10 @@ fn request(url: hyper::Url) {
|
||||
req.start().unwrap().send().unwrap().read_to_string().unwrap();
|
||||
}
|
||||
|
||||
fn hyper_handle(mut incoming: hyper::server::Incoming) {
|
||||
for conn in incoming {
|
||||
let (_, res) = conn.open().unwrap();
|
||||
let mut res = res.start().unwrap();
|
||||
res.write(PHRASE).unwrap();
|
||||
res.end().unwrap();
|
||||
}
|
||||
fn hyper_handle(_: Request, res: Response) {
|
||||
let mut res = res.start().unwrap();
|
||||
res.write(PHRASE).unwrap();
|
||||
res.end().unwrap();
|
||||
}
|
||||
|
||||
#[bench]
|
||||
|
||||
Reference in New Issue
Block a user