From 52d03fa18c3d3bdf58df2396fe89de87339327c3 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 26 Nov 2019 08:26:22 +0600 Subject: [PATCH] use actix deps instead of tokio --- actix-connect/Cargo.toml | 2 -- actix-connect/src/lib.rs | 4 ++-- actix-connect/tests/test_connect.rs | 2 +- actix-ioframe/Cargo.toml | 4 +--- actix-ioframe/src/dispatcher.rs | 31 ++++++++++++++--------------- actix-ioframe/tests/test_server.rs | 2 +- actix-server-config/Cargo.toml | 2 +- actix-server-config/src/lib.rs | 2 +- actix-server/Cargo.toml | 9 +++------ actix-server/src/accept.rs | 2 +- actix-server/src/builder.rs | 3 +-- actix-server/src/socket.rs | 2 +- actix-server/src/ssl/nativetls.rs | 2 +- actix-server/src/ssl/openssl.rs | 2 +- actix-server/src/ssl/rustls.rs | 2 +- actix-server/src/worker.rs | 2 +- actix-utils/Cargo.toml | 6 +----- actix-utils/src/framed.rs | 2 +- actix-utils/src/inflight.rs | 2 +- actix-utils/src/keepalive.rs | 2 +- actix-utils/src/order.rs | 4 ++-- actix-utils/src/time.rs | 6 +++--- actix-utils/src/timeout.rs | 6 +++--- 23 files changed, 44 insertions(+), 57 deletions(-) diff --git a/actix-connect/Cargo.toml b/actix-connect/Cargo.toml index 19be727f..acc153c5 100644 --- a/actix-connect/Cargo.toml +++ b/actix-connect/Cargo.toml @@ -43,7 +43,6 @@ futures = "0.3.1" http = { version = "0.1.17", optional = true } log = "0.4" tokio-net = "=0.2.0-alpha.6" -tokio-executor = "=0.2.0-alpha.6" trust-dns-resolver = { version="0.18.0-alpha.1", default-features = false } # openssl @@ -60,4 +59,3 @@ webpki = { version = "0.21", optional = true } bytes = "0.4" actix-testing = { version="0.3.0-alpha.1" } actix-server-config = "0.3.0-alpha.1" -tokio = "0.2.0-alpha.6" diff --git a/actix-connect/src/lib.rs b/actix-connect/src/lib.rs index ba5ec7b2..a7d276ef 100644 --- a/actix-connect/src/lib.rs +++ b/actix-connect/src/lib.rs @@ -36,7 +36,7 @@ pub use self::service::{ConnectService, ConnectServiceFactory, TcpConnectService pub fn start_resolver(cfg: ResolverConfig, opts: ResolverOpts) -> AsyncResolver { let (resolver, bg) = AsyncResolver::new(cfg, opts); - tokio_executor::current_thread::spawn(bg); + actix_rt::spawn(bg); resolver } @@ -55,7 +55,7 @@ pub(crate) fn get_default_resolver() -> AsyncResolver { }; let (resolver, bg) = AsyncResolver::new(cfg, opts); - tokio_executor::current_thread::spawn(bg); + actix_rt::spawn(bg); Arbiter::set_item(DefaultResolver(resolver.clone())); resolver diff --git a/actix-connect/tests/test_connect.rs b/actix-connect/tests/test_connect.rs index fec644b3..b1ff8f2a 100644 --- a/actix-connect/tests/test_connect.rs +++ b/actix-connect/tests/test_connect.rs @@ -48,7 +48,7 @@ async fn test_rustls_string() { assert_eq!(con.peer_addr().unwrap(), srv.addr()); } -#[tokio::test] +#[actix_rt::test] async fn test_static_str() { let srv = TestServer::with(|| { service_fn(|io: Io| { diff --git a/actix-ioframe/Cargo.toml b/actix-ioframe/Cargo.toml index df86ad13..e194823b 100644 --- a/actix-ioframe/Cargo.toml +++ b/actix-ioframe/Cargo.toml @@ -21,17 +21,15 @@ path = "src/lib.rs" actix-service = "1.0.0-alpha.1" actix-codec = "0.2.0-alpha.1" actix-utils = "0.5.0-alpha.1" +actix-rt = "1.0.0-alpha.1" bytes = "0.4" either = "1.5.2" futures = "0.3.1" pin-project = "0.4.5" -tokio-executor = "=0.2.0-alpha.6" log = "0.4" [dev-dependencies] -actix-rt = "1.0.0-alpha.1" actix-connect = "1.0.0-alpha.1" actix-testing = "0.3.0-alpha.1" actix-server-config = "0.3.0-alpha.1" tokio-net = "=0.2.0-alpha.6" -tokio-timer = "=0.3.0-alpha.6" diff --git a/actix-ioframe/src/dispatcher.rs b/actix-ioframe/src/dispatcher.rs index 60313f6e..677c2816 100644 --- a/actix-ioframe/src/dispatcher.rs +++ b/actix-ioframe/src/dispatcher.rs @@ -279,22 +279,21 @@ where }; let mut cell = inner.clone(); - tokio_executor::current_thread::spawn( - srv.call(Item::new(state.clone(), sink.clone(), item)) - .then(move |item| { - let item = match item { - Ok(Some(item)) => Ok(item), - Ok(None) => return ready(()), - Err(err) => Err(err), - }; - unsafe { - let inner = cell.get_mut(); - inner.buf.push_back(item); - inner.task.wake(); - } - ready(()) - }), - ); + actix_rt::spawn(srv.call(Item::new(state.clone(), sink.clone(), item)).then( + move |item| { + let item = match item { + Ok(Some(item)) => Ok(item), + Ok(None) => return ready(()), + Err(err) => Err(err), + }; + unsafe { + let inner = cell.get_mut(); + inner.buf.push_back(item); + inner.task.wake(); + } + ready(()) + }, + )); } Poll::Pending => return false, Poll::Ready(Err(err)) => { diff --git a/actix-ioframe/tests/test_server.rs b/actix-ioframe/tests/test_server.rs index 8b92c878..98c95eb5 100644 --- a/actix-ioframe/tests/test_server.rs +++ b/actix-ioframe/tests/test_server.rs @@ -3,12 +3,12 @@ use std::sync::Arc; use std::time::Duration; use actix_codec::BytesCodec; +use actix_rt::time::delay_for; use actix_server_config::Io; use actix_service::{apply_fn_factory, service_fn, Service}; use actix_testing::TestServer; use futures::future::ok; use tokio_net::tcp::TcpStream; -use tokio_timer::delay_for; use actix_ioframe::{Builder, Connect}; diff --git a/actix-server-config/Cargo.toml b/actix-server-config/Cargo.toml index 29b8ad27..708071d2 100644 --- a/actix-server-config/Cargo.toml +++ b/actix-server-config/Cargo.toml @@ -22,7 +22,7 @@ openssl = ["tokio-openssl"] rustls = ["tokio-rustls"] [dependencies] -tokio-io = "=0.2.0-alpha.6" +actix-codec = "0.2.0-alpha.1" tokio-net = { version = "=0.2.0-alpha.6", features = ["tcp", "uds"] } tokio-openssl = { version = "0.4.0-alpha.6", optional = true } #tokio-rustls = { version = "0.12.0-alpha.8", optional = true } diff --git a/actix-server-config/src/lib.rs b/actix-server-config/src/lib.rs index d3b7ab4e..5b9a7dbe 100644 --- a/actix-server-config/src/lib.rs +++ b/actix-server-config/src/lib.rs @@ -5,7 +5,7 @@ use std::net::SocketAddr; use std::rc::Rc; use std::{fmt, io, net, ops, time}; -use tokio_io::{AsyncRead, AsyncWrite}; +use actix_codec::{AsyncRead, AsyncWrite}; use tokio_net::tcp::TcpStream; #[derive(Debug, Clone)] diff --git a/actix-server/Cargo.toml b/actix-server/Cargo.toml index 5683afb5..062dc08e 100644 --- a/actix-server/Cargo.toml +++ b/actix-server/Cargo.toml @@ -24,12 +24,13 @@ path = "src/lib.rs" default = [] nativetls = ["native-tls", "tokio-tls"] openssl = ["open-ssl", "tokio-openssl", "actix-server-config/openssl"] -#rustls = ["rust-tls", "tokio-rustls", "webpki", "webpki-roots", "actix-server-config/rustls"] +rustls = ["rust-tls", "tokio-rustls", "webpki", "webpki-roots", "actix-server-config/rustls"] [dependencies] -actix-rt = "1.0.0-alpha.1" actix-service = "1.0.0-alpha.1" actix-server-config = "0.3.0-alpha.1" +actix-rt = "1.0.0-alpha.1" +actix-codec = "0.2.0-alpha.1" log = "0.4" num_cpus = "1.0" @@ -37,11 +38,7 @@ mio = "0.6.19" net2 = "0.2" futures = "0.3.1" slab = "0.4" - -tokio = "0.2.0-alpha.6" -tokio-io = "0.2.0-alpha.6" tokio-net = { version = "0.2.0-alpha.6", features = ["signal", "tcp", "uds"] } -tokio-timer = "0.3.0-alpha.6" # unix domain sockets mio-uds = { version = "0.6.7" } diff --git a/actix-server/src/accept.rs b/actix-server/src/accept.rs index 421aa0ab..1ee38f85 100644 --- a/actix-server/src/accept.rs +++ b/actix-server/src/accept.rs @@ -2,11 +2,11 @@ use std::sync::mpsc as sync_mpsc; use std::time::{Duration, Instant}; use std::{io, thread}; +use actix_rt::time::delay; use actix_rt::System; use futures::FutureExt; use log::{error, info}; use slab::Slab; -use tokio_timer::delay; use crate::server::Server; use crate::socket::{SocketAddr, SocketListener, StdListener}; diff --git a/actix-server/src/builder.rs b/actix-server/src/builder.rs index e4b4e817..67629a31 100644 --- a/actix-server/src/builder.rs +++ b/actix-server/src/builder.rs @@ -3,7 +3,7 @@ use std::task::{Context, Poll}; use std::time::{Duration, Instant}; use std::{io, mem, net}; -use actix_rt::{spawn, Arbiter, System}; +use actix_rt::{spawn, time::delay, Arbiter, System}; use futures::channel::mpsc::{unbounded, UnboundedReceiver}; use futures::future::ready; use futures::stream::FuturesUnordered; @@ -12,7 +12,6 @@ use log::{error, info}; use net2::TcpBuilder; use num_cpus; use tokio_net::tcp::TcpStream; -use tokio_timer::delay; use crate::accept::{AcceptLoop, AcceptNotify, Command}; use crate::config::{ConfiguredService, ServiceConfig}; diff --git a/actix-server/src/socket.rs b/actix-server/src/socket.rs index 8b71d47d..9030310a 100644 --- a/actix-server/src/socket.rs +++ b/actix-server/src/socket.rs @@ -1,6 +1,6 @@ use std::{fmt, io, net}; -use tokio_io::{AsyncRead, AsyncWrite}; +use actix_codec::{AsyncRead, AsyncWrite}; use tokio_net::driver::Handle; use tokio_net::tcp::TcpStream; diff --git a/actix-server/src/ssl/nativetls.rs b/actix-server/src/ssl/nativetls.rs index 5319f127..a40d77a5 100644 --- a/actix-server/src/ssl/nativetls.rs +++ b/actix-server/src/ssl/nativetls.rs @@ -2,10 +2,10 @@ use std::convert::Infallible; use std::marker::PhantomData; use std::task::{Context, Poll}; +use actix_codec::{AsyncRead, AsyncWrite}; use actix_service::{Service, ServiceFactory}; use futures::future::{self, FutureExt as _, LocalBoxFuture, TryFutureExt as _}; use native_tls::Error; -use tokio::io::{AsyncRead, AsyncWrite}; use tokio_tls::{TlsAcceptor, TlsStream}; use crate::counter::Counter; diff --git a/actix-server/src/ssl/openssl.rs b/actix-server/src/ssl/openssl.rs index 5cbe988b..ebd05397 100644 --- a/actix-server/src/ssl/openssl.rs +++ b/actix-server/src/ssl/openssl.rs @@ -3,10 +3,10 @@ use std::marker::PhantomData; use std::pin::Pin; use std::task::{Context, Poll}; +use actix_codec::{AsyncRead, AsyncWrite}; use actix_service::{Service, ServiceFactory}; use futures::future::{ok, FutureExt, LocalBoxFuture, Ready}; use open_ssl::ssl::SslAcceptor; -use tokio_io::{AsyncRead, AsyncWrite}; use tokio_openssl::{HandshakeError, SslStream}; use crate::counter::{Counter, CounterGuard}; diff --git a/actix-server/src/ssl/rustls.rs b/actix-server/src/ssl/rustls.rs index bb95da0e..971c19bb 100644 --- a/actix-server/src/ssl/rustls.rs +++ b/actix-server/src/ssl/rustls.rs @@ -5,10 +5,10 @@ use std::pin::Pin; use std::sync::Arc; use std::task::{Context, Poll}; +use actix_codec::{AsyncRead, AsyncWrite}; use actix_service::{Service, ServiceFactory}; use futures::future::{ok, Ready}; use rust_tls::ServerConfig; -use tokio_io::{AsyncRead, AsyncWrite}; use tokio_rustls::{server::TlsStream, Accept, TlsAcceptor}; use crate::counter::{Counter, CounterGuard}; diff --git a/actix-server/src/worker.rs b/actix-server/src/worker.rs index a1ba6c78..03a63a05 100644 --- a/actix-server/src/worker.rs +++ b/actix-server/src/worker.rs @@ -4,13 +4,13 @@ use std::sync::Arc; use std::task::{Context, Poll}; use std::{mem, time}; +use actix_rt::time::{delay, Delay}; use actix_rt::{spawn, Arbiter}; use futures::channel::mpsc::{UnboundedReceiver, UnboundedSender}; use futures::channel::oneshot; use futures::future::{join_all, LocalBoxFuture, MapOk}; use futures::{Future, FutureExt, Stream, TryFutureExt}; use log::{error, info, trace}; -use tokio_timer::{delay, Delay}; use crate::accept::AcceptNotify; use crate::counter::Counter; diff --git a/actix-utils/Cargo.toml b/actix-utils/Cargo.toml index 85f4212e..01728d46 100644 --- a/actix-utils/Cargo.toml +++ b/actix-utils/Cargo.toml @@ -19,14 +19,10 @@ path = "src/lib.rs" [dependencies] actix-service = "1.0.0-alpha.1" +actix-rt = "1.0.0-alpha.1" actix-codec = "0.2.0-alpha.1" bytes = "0.4" either = "1.5.2" futures = "0.3.1" pin-project = "0.4.5" -tokio-timer = "0.3.0-alpha.6" -tokio-executor = { version="=0.2.0-alpha.6", features=["current-thread"] } log = "0.4" - -[dev-dependencies] -actix-rt = "1.0.0-alpha.1" diff --git a/actix-utils/src/framed.rs b/actix-utils/src/framed.rs index 3a7086f1..a986f33e 100644 --- a/actix-utils/src/framed.rs +++ b/actix-utils/src/framed.rs @@ -287,7 +287,7 @@ where inner.task.wake(); ready(()) }); - tokio_executor::current_thread::spawn(fut); + actix_rt::spawn(fut); } Poll::Pending => return false, Poll::Ready(Err(err)) => { diff --git a/actix-utils/src/inflight.rs b/actix-utils/src/inflight.rs index 5e425823..c4d6f222 100644 --- a/actix-utils/src/inflight.rs +++ b/actix-utils/src/inflight.rs @@ -131,7 +131,7 @@ mod tests { } fn call(&mut self, _: ()) -> Self::Future { - tokio_timer::delay_for(self.0) + actix_rt::time::delay_for(self.0) .then(|_| ok::<_, ()>(())) .boxed_local() } diff --git a/actix-utils/src/keepalive.rs b/actix-utils/src/keepalive.rs index 6f24dbf6..e113f818 100644 --- a/actix-utils/src/keepalive.rs +++ b/actix-utils/src/keepalive.rs @@ -5,9 +5,9 @@ use std::pin::Pin; use std::task::{Context, Poll}; use std::time::{Duration, Instant}; +use actix_rt::time::{delay, Delay}; use actix_service::{Service, ServiceFactory}; use futures::future::{ok, Ready}; -use tokio_timer::{delay, Delay}; use super::time::{LowResTime, LowResTimeService}; diff --git a/actix-utils/src/order.rs b/actix-utils/src/order.rs index 476a4a5b..6eb31df1 100644 --- a/actix-utils/src/order.rs +++ b/actix-utils/src/order.rs @@ -174,7 +174,7 @@ where let task = self.task.clone(); let fut = self.service.call(request); - tokio_executor::current_thread::spawn(async move { + actix_rt::spawn(async move { let res = fut.await; task.wake(); let _ = tx1.send(res); @@ -252,7 +252,7 @@ mod tests { let _ = lazy(|cx| srv.poll_ready(cx)).await; // dispatcher do this - tokio_timer::delay_for(Duration::from_millis(100)).await; + actix_rt::time::delay_for(Duration::from_millis(100)).await; let _ = lazy(|cx| srv.poll_ready(cx)).await; assert_eq!(res1.await.unwrap(), 1); diff --git a/actix-utils/src/time.rs b/actix-utils/src/time.rs index bd9d0638..d832d4d2 100644 --- a/actix-utils/src/time.rs +++ b/actix-utils/src/time.rs @@ -2,9 +2,9 @@ use std::convert::Infallible; use std::task::{Context, Poll}; use std::time::{self, Duration, Instant}; +use actix_rt::time::delay_for; use actix_service::{Service, ServiceFactory}; use futures::future::{ok, ready, FutureExt, Ready}; -use tokio_timer::delay_for; use super::cell::Cell; @@ -79,7 +79,7 @@ impl LowResTimeService { b.resolution }; - tokio_executor::current_thread::spawn(delay_for(interval).then(move |_| { + actix_rt::spawn(delay_for(interval).then(move |_| { inner.get_mut().current.take(); ready(()) })); @@ -144,7 +144,7 @@ impl SystemTimeService { b.resolution }; - tokio_executor::current_thread::spawn(delay_for(interval).then(move |_| { + actix_rt::spawn(delay_for(interval).then(move |_| { inner.get_mut().current.take(); ready(()) })); diff --git a/actix-utils/src/timeout.rs b/actix-utils/src/timeout.rs index 0a39b456..80337105 100644 --- a/actix-utils/src/timeout.rs +++ b/actix-utils/src/timeout.rs @@ -8,9 +8,9 @@ use std::pin::Pin; use std::task::{Context, Poll}; use std::{fmt, time}; +use actix_rt::time::{delay_for, Delay}; use actix_service::{IntoService, Service, Transform}; use futures::future::{ok, Ready}; -use tokio_timer::{clock, delay, Delay}; /// Applies a timeout to requests. #[derive(Debug)] @@ -138,7 +138,7 @@ where fn call(&mut self, request: S::Request) -> Self::Future { TimeoutServiceResponse { fut: self.service.call(request), - sleep: delay(clock::now() + self.timeout), + sleep: delay_for(self.timeout), } } } @@ -198,7 +198,7 @@ mod tests { } fn call(&mut self, _: ()) -> Self::Future { - tokio_timer::delay_for(self.0) + actix_rt::time::delay_for(self.0) .then(|_| ok::<_, ()>(())) .boxed_local() }