mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-28 01:52:57 +01:00
update actix usage
This commit is contained in:
parent
342a194605
commit
e4443226f6
@ -105,7 +105,7 @@ pub struct HttpRequest<S = ()>(SharedHttpInnerMessage, Option<Rc<S>>, Option<Rou
|
||||
impl HttpRequest<()> {
|
||||
/// Construct a new Request.
|
||||
#[inline]
|
||||
pub fn new(
|
||||
pub(crate) fn new(
|
||||
method: Method, uri: Uri, version: Version, headers: HeaderMap,
|
||||
payload: Option<Payload>,
|
||||
) -> HttpRequest {
|
||||
|
@ -4,8 +4,8 @@ use std::time::Duration;
|
||||
use std::{io, net, thread};
|
||||
|
||||
use actix::{
|
||||
fut, signal, Actor, ActorFuture, Addr, Arbiter, AsyncContext, Context,
|
||||
ContextFutureSpawner, Handler, Response, StreamHandler, System, WrapFuture,
|
||||
fut, signal, Actor, ActorFuture, Addr, Arbiter, AsyncContext, Context, Handler,
|
||||
Response, StreamHandler, System, WrapFuture,
|
||||
};
|
||||
|
||||
use futures::sync::mpsc;
|
||||
@ -64,8 +64,7 @@ where
|
||||
no_signals: bool,
|
||||
}
|
||||
|
||||
unsafe impl<H> Sync for HttpServer<H> where H: IntoHttpHandler {}
|
||||
unsafe impl<H> Send for HttpServer<H> where H: IntoHttpHandler {}
|
||||
unsafe impl<H: IntoHttpHandler + 'static> Send for HttpServer<H> {}
|
||||
|
||||
enum ServerCommand {
|
||||
WorkerDied(usize, Slab<SocketInfo>),
|
||||
@ -485,11 +484,9 @@ impl<H: IntoHttpHandler> HttpServer<H> {
|
||||
self.no_signals = false;
|
||||
|
||||
let _ = thread::spawn(move || {
|
||||
System::new("http-server")
|
||||
.config(|| {
|
||||
let sys = System::new("http-server");
|
||||
self.start();
|
||||
})
|
||||
.run();
|
||||
sys.run();
|
||||
}).join();
|
||||
}
|
||||
}
|
||||
@ -557,7 +554,7 @@ impl<H: IntoHttpHandler> HttpServer<H> {
|
||||
pub fn start_incoming<T, S>(mut self, stream: S, secure: bool) -> Addr<Self>
|
||||
where
|
||||
S: Stream<Item = T, Error = io::Error> + Send + 'static,
|
||||
T: AsyncRead + AsyncWrite + 'static,
|
||||
T: AsyncRead + AsyncWrite + Send + 'static,
|
||||
{
|
||||
// set server settings
|
||||
let addr: net::SocketAddr = "127.0.0.1:8080".parse().unwrap();
|
||||
@ -730,6 +727,7 @@ impl<H: IntoHttpHandler> Handler<StopServer> for HttpServer<H> {
|
||||
};
|
||||
for worker in &self.workers {
|
||||
let tx2 = tx.clone();
|
||||
ctx.spawn(
|
||||
worker
|
||||
.1
|
||||
.send(StopWorker { graceful: dur })
|
||||
@ -747,8 +745,8 @@ impl<H: IntoHttpHandler> Handler<StopServer> for HttpServer<H> {
|
||||
}
|
||||
}
|
||||
fut::ok(())
|
||||
})
|
||||
.spawn(ctx);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if !self.workers.is_empty() {
|
||||
|
@ -65,6 +65,8 @@ where
|
||||
tcp_ka: Option<time::Duration>,
|
||||
}
|
||||
|
||||
unsafe impl<H: HttpHandler + 'static> Send for Worker<H> {}
|
||||
|
||||
impl<H: HttpHandler + 'static> Worker<H> {
|
||||
pub(crate) fn new(
|
||||
h: Vec<H>, socks: Slab<SocketInfo>, keep_alive: KeepAlive,
|
||||
|
@ -109,7 +109,6 @@ impl TestServer {
|
||||
let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
let local_addr = tcp.local_addr().unwrap();
|
||||
|
||||
sys.config(move || {
|
||||
HttpServer::new(factory)
|
||||
.disable_signals()
|
||||
.listen(tcp)
|
||||
@ -117,7 +116,7 @@ impl TestServer {
|
||||
|
||||
tx.send((System::current(), local_addr, TestServer::get_conn()))
|
||||
.unwrap();
|
||||
}).run();
|
||||
sys.run();
|
||||
});
|
||||
|
||||
let (system, addr, conn) = rx.recv().unwrap();
|
||||
@ -280,8 +279,7 @@ impl<S: 'static> TestServerBuilder<S> {
|
||||
let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
let local_addr = tcp.local_addr().unwrap();
|
||||
|
||||
System::new("actix-test-server")
|
||||
.config(move || {
|
||||
let sys = System::new("actix-test-server");
|
||||
let state = self.state;
|
||||
let srv = HttpServer::new(move || {
|
||||
let mut app = TestApp::new(state());
|
||||
@ -306,8 +304,7 @@ impl<S: 'static> TestServerBuilder<S> {
|
||||
{
|
||||
srv.listen(tcp).start();
|
||||
}
|
||||
})
|
||||
.run();
|
||||
sys.run();
|
||||
});
|
||||
|
||||
let (system, addr, conn) = rx.recv().unwrap();
|
||||
|
Loading…
Reference in New Issue
Block a user