diff --git a/Cargo.toml b/Cargo.toml index 1ecc0e7b9..754335baa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,7 +74,7 @@ required-features = ["rustls"] [dependencies] actix-codec = "0.4.0-beta.1" -actix-macros = "0.1.0" +actix-macros = "0.2.0" actix-router = "0.2.4" actix-rt = "2.0.0-beta.2" actix-server = "2.0.0-beta.2" @@ -137,6 +137,8 @@ actix-server = { git = "https://github.com/actix/actix-net.git" } actix-tls = { git = "https://github.com/actix/actix-net.git" } actix-utils = { git = "https://github.com/actix/actix-net.git" } actix-router = { git = "https://github.com/actix/actix-net.git" } +actix-macros = { git = "https://github.com/actix/actix-net" } +actix = { git = "https://github.com/actix/actix", branch = "feat/actix-rt-2" } [[bench]] name = "server" diff --git a/actix-http-test/src/lib.rs b/actix-http-test/src/lib.rs index 6eec112a4..2958b7f59 100644 --- a/actix-http-test/src/lib.rs +++ b/actix-http-test/src/lib.rs @@ -60,7 +60,7 @@ pub async fn test_server_with_addr>( // run server in separate thread thread::spawn(move || { - let sys = System::new("actix-test-server"); + let sys = System::new(); let local_addr = tcp.local_addr().unwrap(); let srv = Server::build() diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index 009382ecb..cbf5dcf2c 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -43,7 +43,7 @@ actors = ["actix"] actix-service = "2.0.0-beta.3" actix-codec = "0.4.0-beta.1" actix-utils = "3.0.0-beta.1" -actix-rt = "2.0.0-beta.2" +actix-rt = "2.0.0-beta.3" actix-tls = "3.0.0-beta.2" actix = { version = "0.11.0-beta.1", optional = true } diff --git a/actix-http/src/client/pool.rs b/actix-http/src/client/pool.rs index 51754eb54..1eebef53b 100644 --- a/actix-http/src/client/pool.rs +++ b/actix-http/src/client/pool.rs @@ -326,7 +326,7 @@ where { if let Some(timeout) = self.config.disconnect_timeout { if let ConnectionType::H1(io) = conn.io { - actix_rt::spawn(CloseConnection::new(io, timeout)) + actix_rt::spawn(CloseConnection::new(io, timeout)); } } } else { @@ -341,7 +341,7 @@ where if let ConnectionType::H1(io) = io { actix_rt::spawn(CloseConnection::new( io, timeout, - )) + )); } } continue; @@ -373,7 +373,7 @@ where self.acquired -= 1; if let Some(timeout) = self.config.disconnect_timeout { if let ConnectionType::H1(io) = io { - actix_rt::spawn(CloseConnection::new(io, timeout)) + actix_rt::spawn(CloseConnection::new(io, timeout)); } } self.check_availability(); @@ -536,7 +536,7 @@ where rx: Some(rx), inner: Some(inner), config, - }) + }); } } diff --git a/actix-http/src/h1/dispatcher.rs b/actix-http/src/h1/dispatcher.rs index e04d7e4a0..bcab82ac0 100644 --- a/actix-http/src/h1/dispatcher.rs +++ b/actix-http/src/h1/dispatcher.rs @@ -150,16 +150,6 @@ enum PollResponse { DrainWriteBuf, } -impl PartialEq for PollResponse { - fn eq(&self, other: &PollResponse) -> bool { - match self { - PollResponse::DrainWriteBuf => matches!(other, PollResponse::DrainWriteBuf), - PollResponse::DoNothing => matches!(other, PollResponse::DoNothing), - _ => false, - } - } -} - impl Dispatcher where T: AsyncRead + AsyncWrite + Unpin, @@ -324,9 +314,10 @@ where message: Response<()>, body: ResponseBody, ) -> Result<(), DispatchError> { + let size = body.size(); let mut this = self.project(); this.codec - .encode(Message::Item((message, body.size())), &mut this.write_buf) + .encode(Message::Item((message, size)), &mut this.write_buf) .map_err(|err| { if let Some(mut payload) = this.payload.take() { payload.set_error(PayloadError::Incomplete(None)); @@ -335,7 +326,7 @@ where })?; this.flags.set(Flags::KEEPALIVE, this.codec.keepalive()); - match body.size() { + match size { BodySize::None | BodySize::Empty => this.state.set(State::None), _ => this.state.set(State::SendPayload(body)), }; @@ -462,28 +453,28 @@ where req: Request, cx: &mut Context<'_>, ) -> Result<(), DispatchError> { + let mut this = self.as_mut().project(); + // Handle `EXPECT: 100-Continue` header if req.head().expect() { // set dispatcher state so the future is pinned. - let mut this = self.as_mut().project(); let task = this.flow.expect.call(req); this.state.set(State::ExpectCall(task)); } else { // the same as above. - let mut this = self.as_mut().project(); let task = this.flow.service.call(req); this.state.set(State::ServiceCall(task)); }; // eagerly poll the future for once(or twice if expect is resolved immediately). loop { - match self.as_mut().project().state.project() { + match this.state.project() { StateProj::ExpectCall(fut) => { match fut.poll(cx) { // expect is resolved. continue loop and poll the service call branch. Poll::Ready(Ok(req)) => { self.as_mut().send_continue(); - let mut this = self.as_mut().project(); + this = self.as_mut().project(); let task = this.flow.service.call(req); this.state.set(State::ServiceCall(task)); continue; @@ -793,31 +784,32 @@ where if remaining < LW_BUFFER_SIZE { inner_p.write_buf.reserve(HW_BUFFER_SIZE - remaining); } - let result = inner.as_mut().poll_response(cx)?; - let drain = result == PollResponse::DrainWriteBuf; - // switch to upgrade handler - if let PollResponse::Upgrade(req) = result { - let inner_p = inner.as_mut().project(); - let mut parts = FramedParts::with_read_buf( - inner_p.io.take().unwrap(), - mem::take(inner_p.codec), - mem::take(inner_p.read_buf), - ); - parts.write_buf = mem::take(inner_p.write_buf); - let framed = Framed::from_parts(parts); - let upgrade = inner_p - .flow - .upgrade - .as_ref() - .unwrap() - .call((req, framed)); - self.as_mut() - .project() - .inner - .set(DispatcherState::Upgrade(upgrade)); - return self.poll(cx); - } + let drain = match inner.as_mut().poll_response(cx)? { + PollResponse::DrainWriteBuf => true, + PollResponse::DoNothing => false, + PollResponse::Upgrade(req) => { + let inner_p = inner.as_mut().project(); + let mut parts = FramedParts::with_read_buf( + inner_p.io.take().unwrap(), + mem::take(inner_p.codec), + mem::take(inner_p.read_buf), + ); + parts.write_buf = mem::take(inner_p.write_buf); + let framed = Framed::from_parts(parts); + let upgrade = inner_p + .flow + .upgrade + .as_ref() + .unwrap() + .call((req, framed)); + self.as_mut() + .project() + .inner + .set(DispatcherState::Upgrade(upgrade)); + return self.poll(cx); + } + }; // we didn't get WouldBlock from write operation, // so data get written to kernel completely (macOS) diff --git a/actix-web-codegen/src/lib.rs b/actix-web-codegen/src/lib.rs index 50e5be712..ede1e0005 100644 --- a/actix-web-codegen/src/lib.rs +++ b/actix-web-codegen/src/lib.rs @@ -175,7 +175,6 @@ pub fn main(_: TokenStream, item: TokenStream) -> TokenStream { let vis = &input.vis; let sig = &mut input.sig; let body = &input.block; - let name = &sig.ident; if sig.asyncness.is_none() { return syn::Error::new_spanned(sig.fn_token, "only async fn is supported") @@ -188,7 +187,7 @@ pub fn main(_: TokenStream, item: TokenStream) -> TokenStream { (quote! { #(#attrs)* #vis #sig { - actix_web::rt::System::new(stringify!(#name)) + actix_web::rt::System::new() .block_on(async move { #body }) } }) diff --git a/awc/Cargo.toml b/awc/Cargo.toml index 90f33c9ba..dded78a20 100644 --- a/awc/Cargo.toml +++ b/awc/Cargo.toml @@ -40,7 +40,7 @@ compress = ["actix-http/compress"] actix-codec = "0.4.0-beta.1" actix-service = "2.0.0-beta.3" actix-http = "3.0.0-beta.1" -actix-rt = "2.0.0-beta.2" +actix-rt = "2.0.0-beta.3" base64 = "0.13" bytes = "1" @@ -58,9 +58,6 @@ open-ssl = { version = "0.10", package = "openssl", optional = true } rust-tls = { version = "0.19.0", package = "rustls", optional = true, features = ["dangerous_configuration"] } [dev-dependencies] -# TODO: actix is temporary added as dev dep for actix-macro reason. -# Can be removed when it does not impact tests. -actix = "0.11.0-beta.1" actix-web = { version = "4.0.0-beta.1", features = ["openssl"] } actix-http = { version = "3.0.0-beta.1", features = ["openssl"] } actix-http-test = { version = "3.0.0-beta.1", features = ["openssl"] } diff --git a/awc/README.md b/awc/README.md index 972a80140..3d18a07c5 100644 --- a/awc/README.md +++ b/awc/README.md @@ -21,7 +21,7 @@ use actix_rt::System; use awc::Client; fn main() { - System::new("test").block_on(async { + System::new().block_on(async { let client = Client::default(); let res = client diff --git a/benches/responder.rs b/benches/responder.rs index 61180d575..8cfdbd3ea 100644 --- a/benches/responder.rs +++ b/benches/responder.rs @@ -68,7 +68,7 @@ impl Responder for OptionResponder { } fn future_responder(c: &mut Criterion) { - let rt = actix_rt::System::new("test"); + let rt = actix_rt::System::new(); let req = TestRequest::default().to_http_request(); c.bench_function("future_responder", move |b| { @@ -91,7 +91,7 @@ fn future_responder(c: &mut Criterion) { } fn responder(c: &mut Criterion) { - let rt = actix_rt::System::new("test"); + let rt = actix_rt::System::new(); let req = TestRequest::default().to_http_request(); c.bench_function("responder", move |b| { b.iter_custom(|_| { diff --git a/benches/server.rs b/benches/server.rs index 117b6136e..ce79f077d 100644 --- a/benches/server.rs +++ b/benches/server.rs @@ -29,7 +29,7 @@ const STR: &str = "Hello World Hello World Hello World Hello World Hello World \ fn bench_async_burst(c: &mut Criterion) { // We are using System here, since Runtime requires preinitialized tokio // Maybe add to actix_rt docs - let rt = actix_rt::System::new("test"); + let rt = actix_rt::System::new(); let srv = rt.block_on(async { test::start(|| { diff --git a/benches/service.rs b/benches/service.rs index 8ca6cbe28..0d3264857 100644 --- a/benches/service.rs +++ b/benches/service.rs @@ -25,7 +25,7 @@ pub fn bench_async_service(c: &mut Criterion, srv: S, name: &str) where S: Service + 'static, { - let rt = actix_rt::System::new("test"); + let rt = actix_rt::System::new(); let srv = Rc::new(RefCell::new(srv)); let req = TestRequest::default().to_srv_request(); @@ -67,7 +67,7 @@ async fn index(req: ServiceRequest) -> Result { // Sample results on MacBook Pro '14 // time: [2.0724 us 2.1345 us 2.2074 us] fn async_web_service(c: &mut Criterion) { - let rt = actix_rt::System::new("test"); + let rt = actix_rt::System::new(); let srv = Rc::new(RefCell::new(rt.block_on(init_service( App::new().service(web::service("/").finish(index)), )))); diff --git a/src/middleware/normalize.rs b/src/middleware/normalize.rs index cbe3123e3..8519f041a 100644 --- a/src/middleware/normalize.rs +++ b/src/middleware/normalize.rs @@ -57,7 +57,7 @@ impl Default for TrailingSlash { /// ```rust /// use actix_web::{web, middleware, App}; /// -/// # actix_web::rt::System::new("doctest").block_on(async { +/// # actix_web::rt::System::new().block_on(async { /// let app = App::new() /// .wrap(middleware::NormalizePath::default()) /// .route("/test", web::get().to(|| async { "test" })) diff --git a/src/test.rs b/src/test.rs index bef9fc4ac..d51017b1e 100644 --- a/src/test.rs +++ b/src/test.rs @@ -667,7 +667,7 @@ where // run server in separate thread thread::spawn(move || { - let sys = System::new("actix-test-server"); + let sys = System::new(); let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap(); let local_addr = tcp.local_addr().unwrap(); let factory = factory.clone(); diff --git a/tests/test_httpserver.rs b/tests/test_httpserver.rs index 5eca14931..78d4ef685 100644 --- a/tests/test_httpserver.rs +++ b/tests/test_httpserver.rs @@ -13,7 +13,7 @@ async fn test_start() { let (tx, rx) = mpsc::channel(); thread::spawn(move || { - let sys = actix_rt::System::new("test"); + let sys = actix_rt::System::new(); sys.block_on(async { let srv = HttpServer::new(|| { @@ -91,7 +91,7 @@ async fn test_start_ssl() { let (tx, rx) = mpsc::channel(); thread::spawn(move || { - let sys = actix_rt::System::new("test"); + let sys = actix_rt::System::new(); let builder = ssl_acceptor().unwrap(); let srv = HttpServer::new(|| {