From 762961b0f4fb7e18deea50badd9a85ff2df25634 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sat, 10 Feb 2018 10:22:03 -0800 Subject: [PATCH] simplify HttpServer type definition --- src/server/srv.rs | 57 ++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 35 deletions(-) diff --git a/src/server/srv.rs b/src/server/srv.rs index 5aa3fbdb..3d4a2fd0 100644 --- a/src/server/srv.rs +++ b/src/server/srv.rs @@ -10,20 +10,15 @@ use actix::actors::signal; use futures::{Future, Sink, Stream}; use futures::sync::mpsc; use tokio_io::{AsyncRead, AsyncWrite}; -use tokio_core::net::TcpStream; use mio; use num_cpus; use net2::TcpBuilder; #[cfg(feature="tls")] use native_tls::TlsAcceptor; -#[cfg(feature="tls")] -use tokio_tls::TlsStream; #[cfg(feature="alpn")] use openssl::ssl::{AlpnError, SslAcceptorBuilder}; -#[cfg(feature="alpn")] -use tokio_openssl::SslStream; use helpers; use super::{HttpHandler, IntoHttpHandler, IoStream}; @@ -40,11 +35,10 @@ use super::settings::{ServerSettings, WorkerSettings}; /// `A` - peer address /// /// `H` - request handler -pub struct HttpServer +pub struct HttpServer where H: HttpHandler + 'static { h: Option>>, - io: PhantomData, addr: PhantomData, threads: usize, backlog: i32, @@ -60,13 +54,12 @@ pub struct HttpServer no_signals: bool, } -unsafe impl Sync for HttpServer where H: HttpHandler + 'static {} -unsafe impl Send for HttpServer where H: HttpHandler + 'static {} +unsafe impl Sync for HttpServer where H: HttpHandler + 'static {} +unsafe impl Send for HttpServer where H: HttpHandler + 'static {} -impl Actor for HttpServer +impl Actor for HttpServer where A: 'static, - T: IoStream, H: HttpHandler, U: IntoIterator + 'static, V: IntoHttpHandler, @@ -78,9 +71,8 @@ impl Actor for HttpServer } } -impl HttpServer +impl HttpServer where A: 'static, - T: IoStream, H: HttpHandler, U: IntoIterator + 'static, V: IntoHttpHandler, @@ -90,7 +82,6 @@ impl HttpServer where F: Sync + Send + 'static + Fn() -> U, { HttpServer{ h: None, - io: PhantomData, addr: PhantomData, threads: num_cpus::get(), backlog: 2048, @@ -262,7 +253,7 @@ impl HttpServer } } -impl HttpServer +impl HttpServer where U: IntoIterator + 'static, V: IntoHttpHandler, { @@ -354,7 +345,7 @@ impl HttpServer } #[cfg(feature="tls")] -impl HttpServer, net::SocketAddr, H, U> +impl HttpServer where U: IntoIterator + 'static, V: IntoHttpHandler, { @@ -394,7 +385,7 @@ impl HttpServer, net::SocketAddr, H, } #[cfg(feature="alpn")] -impl HttpServer, net::SocketAddr, H, U> +impl HttpServer where U: IntoIterator + 'static, V: IntoHttpHandler, { @@ -439,9 +430,8 @@ impl HttpServer, net::SocketAddr, H, } } -impl HttpServer, A, H, U> +impl HttpServer where A: 'static, - T: AsyncRead + AsyncWrite + 'static, H: HttpHandler, U: IntoIterator + 'static, V: IntoHttpHandler, @@ -449,8 +439,9 @@ impl HttpServer, A, H, U> /// Start listening for incoming connections from a stream. /// /// This method uses only one thread for handling incoming connections. - pub fn start_incoming(mut self, stream: S, secure: bool) -> SyncAddress - where S: Stream + 'static + pub fn start_incoming(mut self, stream: S, secure: bool) -> SyncAddress + where S: Stream + 'static, + T: AsyncRead + AsyncWrite + 'static, { if !self.sockets.is_empty() { let addrs: Vec<(net::SocketAddr, net::TcpListener)> = @@ -492,9 +483,8 @@ impl HttpServer, A, H, U> /// Signals support /// Handle `SIGINT`, `SIGTERM`, `SIGQUIT` signals and send `SystemExit(0)` /// message to `System` actor. -impl Handler for HttpServer - where T: IoStream, - H: HttpHandler + 'static, +impl Handler for HttpServer + where H: HttpHandler + 'static, U: IntoIterator + 'static, V: IntoHttpHandler, A: 'static, @@ -523,7 +513,7 @@ impl Handler for HttpServer } } -impl Handler>> for HttpServer +impl Handler>> for HttpServer where T: IoStream, H: HttpHandler + 'static, U: IntoIterator + 'static, @@ -544,7 +534,7 @@ impl Handler>> for HttpServer } } -impl Handler> for HttpServer +impl Handler> for HttpServer where T: IoStream, H: HttpHandler + 'static, U: IntoIterator + 'static, @@ -560,9 +550,8 @@ impl Handler> for HttpServer } } -impl Handler for HttpServer - where T: IoStream, - H: HttpHandler + 'static, +impl Handler for HttpServer + where H: HttpHandler + 'static, U: IntoIterator + 'static, V: IntoHttpHandler, A: 'static, @@ -578,9 +567,8 @@ impl Handler for HttpServer } } -impl Handler for HttpServer - where T: IoStream, - H: HttpHandler + 'static, +impl Handler for HttpServer + where H: HttpHandler + 'static, U: IntoIterator + 'static, V: IntoHttpHandler, A: 'static, @@ -595,9 +583,8 @@ impl Handler for HttpServer } } -impl Handler for HttpServer - where T: IoStream, - H: HttpHandler + 'static, +impl Handler for HttpServer + where H: HttpHandler + 'static, U: IntoIterator + 'static, V: IntoHttpHandler, A: 'static,