From e01c6a4bb844d778b4d2a069185e6e687043fc25 Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Tue, 6 Apr 2021 08:21:03 +0800 Subject: [PATCH] Add changelog --- actix-server/CHANGES.md | 6 ++++++ actix-server/src/worker.rs | 35 +++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/actix-server/CHANGES.md b/actix-server/CHANGES.md index 60d7ce37..cf998c91 100644 --- a/actix-server/CHANGES.md +++ b/actix-server/CHANGES.md @@ -1,6 +1,12 @@ # Changes ## Unreleased - 2021-xx-xx +* Server can start regardless what runtime it's in. [#266] +* Remove `Future` impl for `ServerBuilder`. [#266] +* Rename `Server` to `ServerHandle`. `ServerHandle` must be explicitly constructed with `Server::handle` API. [#266] +* Add `Server` type that can be `await` for blocking until server stop. [#266] + +[#266]: https://github.com/actix/actix-net/pull/266 ## 2.0.0-beta.4 - 2021-04-01 diff --git a/actix-server/src/worker.rs b/actix-server/src/worker.rs index f68872f0..c8c6691f 100644 --- a/actix-server/src/worker.rs +++ b/actix-server/src/worker.rs @@ -188,12 +188,12 @@ impl ServerWorker { availability: WorkerAvailability, config: ServerWorkerConfig, ) -> io::Result { + assert!(!availability.available()); + let (tx1, rx) = unbounded_channel(); let (tx2, rx2) = unbounded_channel(); let avail = availability.clone(); - availability.set(false); - // Try to get actix system when have one. let system = System::try_current(); @@ -208,16 +208,7 @@ impl ServerWorker { System::set_current(system); } - let mut wrk = ServerWorker { - rx, - rx2, - services: Vec::new(), - availability, - conns: Counter::new(config.max_concurrent_connections), - factories, - state: Default::default(), - shutdown_timeout: config.shutdown_timeout, - }; + let mut services = Vec::new(); // use a custom tokio runtime builder to change the settings of runtime. let local = tokio::task::LocalSet::new(); @@ -227,7 +218,7 @@ impl ServerWorker { .build() .and_then(|rt| { local.block_on(&rt, async { - for (idx, factory) in wrk.factories.iter().enumerate() { + for (idx, factory) in factories.iter().enumerate() { let service = factory.create().await.map_err(|_| { io::Error::new( io::ErrorKind::Other, @@ -236,8 +227,8 @@ impl ServerWorker { })?; for (token, service) in service { - assert_eq!(token.0, wrk.services.len()); - wrk.services.push(WorkerService { + assert_eq!(token.0, services.len()); + services.push(WorkerService { factory: idx, service, status: WorkerServiceStatus::Unavailable, @@ -253,7 +244,19 @@ impl ServerWorker { match res { Ok(rt) => { factory_tx.send(None).unwrap(); - local.block_on(&rt, wrk) + + let worker = ServerWorker { + rx, + rx2, + services, + availability, + conns: Counter::new(config.max_concurrent_connections), + factories, + state: Default::default(), + shutdown_timeout: config.shutdown_timeout, + }; + + local.block_on(&rt, worker) } Err(e) => factory_tx.send(Some(e)).unwrap(), }