1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-06-30 03:44:27 +02:00

use new actix system api

This commit is contained in:
Nikolay Kim
2018-05-29 10:31:37 -07:00
parent fb582a6bca
commit ecd05662c0
13 changed files with 173 additions and 165 deletions

View File

@ -48,16 +48,16 @@ pub(crate) const MAX_WRITE_BUFFER_SIZE: usize = 65_536;
/// use actix_web::{server, App, HttpResponse};
///
/// fn main() {
/// let sys = actix::System::new("guide");
/// actix::System::run(|| {
///
/// server::new(
/// || App::new()
/// .resource("/", |r| r.f(|_| HttpResponse::Ok())))
/// .bind("127.0.0.1:59090").unwrap()
/// .start();
/// server::new(
/// || App::new()
/// .resource("/", |r| r.f(|_| HttpResponse::Ok())))
/// .bind("127.0.0.1:59090").unwrap()
/// .start();
///
/// # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0));
/// let _ = sys.run();
/// });
/// }
/// ```
pub fn new<F, U, H>(factory: F) -> HttpServer<H>

View File

@ -410,16 +410,16 @@ impl<H: IntoHttpHandler> HttpServer<H> {
/// use actix_web::{server, App, HttpResponse};
///
/// fn main() {
/// let sys = actix::System::new("example"); // <- create Actix system
/// // Run actix system, this method actually starts all async processes
/// actix::System::run(|| {
///
/// server::new(
/// || App::new()
/// .resource("/", |r| r.h(|_| HttpResponse::Ok())))
/// .bind("127.0.0.1:0").expect("Can not bind to 127.0.0.1:0")
/// .start();
/// server::new(
/// || App::new()
/// .resource("/", |r| r.h(|_| HttpResponse::Ok())))
/// .bind("127.0.0.1:0").expect("Can not bind to 127.0.0.1:0")
/// .start();
/// # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0));
///
/// let _ = sys.run(); // <- Run actix system, this method actually starts all async processes
/// });
/// }
/// ```
pub fn start(mut self) -> Addr<Self> {
@ -496,9 +496,11 @@ impl<H: IntoHttpHandler> HttpServer<H> {
self.no_signals = false;
let _ = thread::spawn(move || {
let sys = System::new("http-server");
self.start();
let _ = sys.run();
System::new("http-server")
.config(|| {
self.start();
})
.run();
}).join();
}
}
@ -565,7 +567,7 @@ impl<H: IntoHttpHandler> HttpServer<H> {
/// This method uses only one thread for handling incoming connections.
pub fn start_incoming<T, S>(mut self, stream: S, secure: bool) -> Addr<Self>
where
S: Stream<Item = T, Error = io::Error> + 'static,
S: Stream<Item = T, Error = io::Error> + Send + 'static,
T: AsyncRead + AsyncWrite + 'static,
{
// set server settings
@ -588,6 +590,7 @@ impl<H: IntoHttpHandler> HttpServer<H> {
}));
self
});
if let Some(signals) = signals {
signals.do_send(signal::Subscribe(addr.clone().recipient()))
}
@ -686,12 +689,13 @@ where
type Result = ();
fn handle(&mut self, msg: Conn<T>, _: &mut Context<Self>) -> Self::Result {
Arbiter::spawn(HttpChannel::new(
unimplemented!();
/*Arbiter::spawn(HttpChannel::new(
Rc::clone(self.h.as_ref().unwrap()),
msg.io,
msg.peer,
msg.http2,
));
));*/
}
}

View File

@ -1,9 +1,10 @@
use futures::unsync::oneshot;
use futures::sync::oneshot;
use futures::Future;
use net2::TcpStreamExt;
use slab::Slab;
use std::rc::Rc;
use std::{net, time};
use tokio::executor::current_thread;
use tokio_reactor::Handle;
use tokio_tcp::TcpStream;
@ -180,7 +181,7 @@ impl StreamHandlerType {
let io = TcpStream::from_std(msg.io, &Handle::default())
.expect("failed to associate TCP stream");
Arbiter::spawn(HttpChannel::new(h, io, msg.peer, msg.http2));
current_thread::spawn(HttpChannel::new(h, io, msg.peer, msg.http2));
}
#[cfg(feature = "tls")]
StreamHandlerType::Tls(ref acceptor) => {
@ -194,9 +195,9 @@ impl StreamHandlerType {
Arbiter::spawn(TlsAcceptorExt::accept_async(acceptor, io).then(
move |res| {
match res {
Ok(io) => {
Arbiter::spawn(HttpChannel::new(h, io, peer, http2))
}
Ok(io) => current_thread::spawn(HttpChannel::new(
h, io, peer, http2,
)),
Err(err) => {
trace!("Error during handling tls connection: {}", err)
}
@ -223,7 +224,9 @@ impl StreamHandlerType {
} else {
false
};
Arbiter::spawn(HttpChannel::new(h, io, peer, http2));
current_thread::spawn(HttpChannel::new(
h, io, peer, http2,
));
}
Err(err) => {
trace!("Error during handling tls connection: {}", err)