mirror of
https://github.com/fafhrd91/actix-net
synced 2025-08-31 23:16:58 +02:00
Compare commits
12 Commits
bytestring
...
rt-v2.0.0-
Author | SHA1 | Date | |
---|---|---|---|
|
a2e03700e7 | ||
|
6edf9b8278 | ||
|
f07d807707 | ||
|
d4c46b7da9 | ||
|
b0a8f8411b | ||
|
46bfe5de36 | ||
|
a95afe2800 | ||
|
f751cf5acb | ||
|
a1982bdbad | ||
|
147c4f4f2c | ||
|
5285656bdc | ||
|
296294061f |
@@ -6,7 +6,6 @@ members = [
|
|||||||
"actix-rt",
|
"actix-rt",
|
||||||
"actix-server",
|
"actix-server",
|
||||||
"actix-service",
|
"actix-service",
|
||||||
"actix-threadpool",
|
|
||||||
"actix-tls",
|
"actix-tls",
|
||||||
"actix-tracing",
|
"actix-tracing",
|
||||||
"actix-utils",
|
"actix-utils",
|
||||||
@@ -20,7 +19,6 @@ actix-router = { path = "actix-router" }
|
|||||||
actix-rt = { path = "actix-rt" }
|
actix-rt = { path = "actix-rt" }
|
||||||
actix-server = { path = "actix-server" }
|
actix-server = { path = "actix-server" }
|
||||||
actix-service = { path = "actix-service" }
|
actix-service = { path = "actix-service" }
|
||||||
actix-threadpool = { path = "actix-threadpool" }
|
|
||||||
actix-tls = { path = "actix-tls" }
|
actix-tls = { path = "actix-tls" }
|
||||||
actix-tracing = { path = "actix-tracing" }
|
actix-tracing = { path = "actix-tracing" }
|
||||||
actix-utils = { path = "actix-utils" }
|
actix-utils = { path = "actix-utils" }
|
||||||
|
66
README.md
66
README.md
@@ -1,9 +1,12 @@
|
|||||||
# Actix net [](https://codecov.io/gh/actix/actix-net) [](https://gitter.im/actix/actix?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
# Actix Net
|
||||||
|
|
||||||
Actix net - framework for composable network services
|
> A collection of lower-level libraries for composable network services.
|
||||||
|
|
||||||
|

|
||||||
|
[](https://codecov.io/gh/actix/actix-net)
|
||||||
|
[](https://discord.gg/NWpN5mmg3x)
|
||||||
|
|
||||||
## Build statuses
|
## Build statuses
|
||||||
|
|
||||||
| Platform | Build Status |
|
| Platform | Build Status |
|
||||||
| ---------------- | ------------ |
|
| ---------------- | ------------ |
|
||||||
| Linux | [](https://github.com/actix/actix-net/actions?query=workflow%3A"CI+(Linux)") |
|
| Linux | [](https://github.com/actix/actix-net/actions?query=workflow%3A"CI+(Linux)") |
|
||||||
@@ -11,59 +14,13 @@ Actix net - framework for composable network services
|
|||||||
| Windows | [](https://github.com/actix/actix-net/actions?query=workflow%3A"CI+(Windows)") |
|
| Windows | [](https://github.com/actix/actix-net/actions?query=workflow%3A"CI+(Windows)") |
|
||||||
| Windows (MinGW) | [](https://github.com/actix/actix-net/actions?query=workflow%3A"CI+(Windows-mingw)") |
|
| Windows (MinGW) | [](https://github.com/actix/actix-net/actions?query=workflow%3A"CI+(Windows-mingw)") |
|
||||||
|
|
||||||
## Documentation & community resources
|
|
||||||
|
|
||||||
* [Chat on Gitter](https://gitter.im/actix/actix)
|
|
||||||
* Minimum supported Rust version: 1.46 or later
|
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
See `actix-server/examples` and `actix-tls/examples` for some basic examples.
|
||||||
|
|
||||||
```rust
|
### MSRV
|
||||||
fn main() -> io::Result<()> {
|
This repo's Minimum Supported Rust Version (MSRV) is 1.46.0.
|
||||||
// load ssl keys
|
|
||||||
let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls()).unwrap();
|
|
||||||
builder.set_private_key_file("./examples/key.pem", SslFiletype::PEM).unwrap();
|
|
||||||
builder.set_certificate_chain_file("./examples/cert.pem").unwrap();
|
|
||||||
let acceptor = builder.build();
|
|
||||||
|
|
||||||
let num = Arc::new(AtomicUsize::new(0));
|
|
||||||
|
|
||||||
// bind socket address and start workers. By default server uses number of
|
|
||||||
// available logical cpu as threads count. actix net start separate
|
|
||||||
// instances of service pipeline in each worker.
|
|
||||||
Server::build()
|
|
||||||
.bind(
|
|
||||||
// configure service pipeline
|
|
||||||
"basic", "0.0.0.0:8443",
|
|
||||||
move || {
|
|
||||||
let num = num.clone();
|
|
||||||
let acceptor = acceptor.clone();
|
|
||||||
|
|
||||||
// construct transformation pipeline
|
|
||||||
pipeline(
|
|
||||||
// service for converting incoming TcpStream to a SslStream<TcpStream>
|
|
||||||
fn_service(move |stream: actix_rt::net::TcpStream| async move {
|
|
||||||
SslAcceptorExt::accept_async(&acceptor, stream.into_parts().0).await
|
|
||||||
.map_err(|e| println!("Openssl error: {}", e))
|
|
||||||
}))
|
|
||||||
// .and_then() combinator chains result of previos service call to argument
|
|
||||||
/// for next service calll. in this case, on success we chain
|
|
||||||
/// ssl stream to the `logger` service.
|
|
||||||
.and_then(fn_service(logger))
|
|
||||||
// Next service counts number of connections
|
|
||||||
.and_then(move |_| {
|
|
||||||
let num = num.fetch_add(1, Ordering::Relaxed);
|
|
||||||
println!("got ssl connection {:?}", num);
|
|
||||||
future::ok(())
|
|
||||||
})
|
|
||||||
},
|
|
||||||
)?
|
|
||||||
.run()
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
This project is licensed under either of
|
This project is licensed under either of
|
||||||
|
|
||||||
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0))
|
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0))
|
||||||
@@ -73,6 +30,5 @@ at your option.
|
|||||||
|
|
||||||
## Code of Conduct
|
## Code of Conduct
|
||||||
|
|
||||||
Contribution to the actix-net crate is organized under the terms of the
|
Contribution to the actix-net repo is organized under the terms of the Contributor Covenant.
|
||||||
Contributor Covenant, the maintainer of actix-net, @fafhrd91, promises to
|
The Actix team promises to intervene to uphold that code of conduct.
|
||||||
intervene to uphold that code of conduct.
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## Unreleased - 2020-xx-xx
|
## Unreleased - 2021-xx-xx
|
||||||
|
|
||||||
|
|
||||||
## 0.4.0-beta.1 - 2020-12-28
|
## 0.4.0-beta.1 - 2020-12-28
|
||||||
|
@@ -1,13 +1,19 @@
|
|||||||
# CHANGES
|
# Changes
|
||||||
|
|
||||||
## 0.1.3 - 2020-12-3
|
## Unreleased - 2021-xx-xx
|
||||||
|
|
||||||
|
|
||||||
|
## 0.2.0-beta.1 - 2021-01-09
|
||||||
|
* Remove `actix-reexport` feature.
|
||||||
|
|
||||||
|
|
||||||
|
## 0.1.3 - 2020-12-03
|
||||||
|
* Add `actix-reexport` feature. [#218]
|
||||||
|
|
||||||
|
[#218]: https://github.com/actix/actix-net/pull/218
|
||||||
|
|
||||||
* Add `actix-reexport` feature
|
|
||||||
|
|
||||||
## 0.1.2 - 2020-05-18
|
## 0.1.2 - 2020-05-18
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
* Forward actix_rt::test arguments to test function [#127]
|
* Forward actix_rt::test arguments to test function [#127]
|
||||||
|
|
||||||
[#127]: https://github.com/actix/actix-net/pull/127
|
[#127]: https://github.com/actix/actix-net/pull/127
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-macros"
|
name = "actix-macros"
|
||||||
version = "0.1.3"
|
version = "0.2.0-beta.1"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Actix runtime macros"
|
description = "Actix runtime macros"
|
||||||
repository = "https://github.com/actix/actix-net"
|
repository = "https://github.com/actix/actix-net"
|
||||||
|
@@ -11,7 +11,7 @@ use quote::quote;
|
|||||||
///
|
///
|
||||||
/// ## Usage
|
/// ## Usage
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
/// #[actix_rt::main]
|
/// #[actix_rt::main]
|
||||||
/// async fn main() {
|
/// async fn main() {
|
||||||
/// println!("Hello world");
|
/// println!("Hello world");
|
||||||
@@ -36,25 +36,14 @@ pub fn main(_: TokenStream, item: TokenStream) -> TokenStream {
|
|||||||
|
|
||||||
sig.asyncness = None;
|
sig.asyncness = None;
|
||||||
|
|
||||||
if cfg!(feature = "actix-reexport") {
|
(quote! {
|
||||||
(quote! {
|
#(#attrs)*
|
||||||
#(#attrs)*
|
#vis #sig {
|
||||||
#vis #sig {
|
actix_rt::System::new(stringify!(#name))
|
||||||
actix::System::new(stringify!(#name))
|
.block_on(async move { #body })
|
||||||
.block_on(async move { #body })
|
}
|
||||||
}
|
})
|
||||||
})
|
.into()
|
||||||
.into()
|
|
||||||
} else {
|
|
||||||
(quote! {
|
|
||||||
#(#attrs)*
|
|
||||||
#vis #sig {
|
|
||||||
actix_rt::System::new(stringify!(#name))
|
|
||||||
.block_on(async move { #body })
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.into()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Marks async test function to be executed by actix runtime.
|
/// Marks async test function to be executed by actix runtime.
|
||||||
|
@@ -1,6 +1,12 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## Unreleased - 2020-xx-xx
|
## Unreleased - 2021-xx-xx
|
||||||
|
|
||||||
|
|
||||||
|
## 0.2.6 - 2021-01-09
|
||||||
|
* Use `bytestring` version range compatible with Bytes v1.0. [#246]
|
||||||
|
|
||||||
|
[#246]: https://github.com/actix/actix-net/pull/246
|
||||||
|
|
||||||
|
|
||||||
## 0.2.5 - 2020-09-20
|
## 0.2.5 - 2020-09-20
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-router"
|
name = "actix-router"
|
||||||
version = "0.2.5"
|
version = "0.2.6"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Resource path matching library"
|
description = "Resource path matching library"
|
||||||
keywords = ["actix"]
|
keywords = ["actix"]
|
||||||
@@ -20,7 +20,7 @@ default = ["http"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
regex = "1.3.1"
|
regex = "1.3.1"
|
||||||
serde = "1.0.104"
|
serde = "1.0.104"
|
||||||
bytestring = "0.1.2"
|
bytestring = ">=0.1.5, <2"
|
||||||
log = "0.4.8"
|
log = "0.4.8"
|
||||||
http = { version = "0.2.2", optional = true }
|
http = { version = "0.2.2", optional = true }
|
||||||
|
|
||||||
|
@@ -1,6 +1,13 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## Unreleased - 2020-xx-xx
|
## Unreleased - 2021-xx-xx
|
||||||
|
|
||||||
|
|
||||||
|
## 2.0.0-beta.2 - 2021-01-09
|
||||||
|
* Add `task` mod with re-export of `tokio::task::{spawn_blocking, yield_now, JoinHandle}` [#245]
|
||||||
|
* Add default "macros" feature to allow faster compile times when using `default-features=false`.
|
||||||
|
|
||||||
|
[#245]: https://github.com/actix/actix-net/pull/245
|
||||||
|
|
||||||
|
|
||||||
## 2.0.0-beta.1 - 2020-12-28
|
## 2.0.0-beta.1 - 2020-12-28
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-rt"
|
name = "actix-rt"
|
||||||
version = "2.0.0-beta.1"
|
version = "2.0.0-beta.2"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Tokio-based single-thread async runtime for the Actix ecosystem"
|
description = "Tokio-based single-thread async runtime for the Actix ecosystem"
|
||||||
keywords = ["network", "framework", "async", "futures"]
|
keywords = ["network", "framework", "async", "futures"]
|
||||||
@@ -15,7 +15,11 @@ edition = "2018"
|
|||||||
name = "actix_rt"
|
name = "actix_rt"
|
||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[features]
|
||||||
actix-macros = "0.1.0"
|
default = ["macros"]
|
||||||
|
macros = ["actix-macros"]
|
||||||
|
|
||||||
tokio = { version = "1", features = ["rt", "net", "signal", "sync", "time"] }
|
[dependencies]
|
||||||
|
actix-macros = { version = "0.2.0-beta.1", optional = true }
|
||||||
|
|
||||||
|
tokio = { version = "1", features = ["rt", "net", "parking_lot", "signal", "sync", "time"] }
|
||||||
|
@@ -7,7 +7,9 @@
|
|||||||
|
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
|
||||||
#[cfg(not(test))] // Work around for rust-lang/rust#62127
|
// Cannot define a main macro when compiled into test harness.
|
||||||
|
// Workaround for https://github.com/rust-lang/rust/issues/62127.
|
||||||
|
#[cfg(all(feature = "macros", not(test)))]
|
||||||
pub use actix_macros::{main, test};
|
pub use actix_macros::{main, test};
|
||||||
|
|
||||||
mod arbiter;
|
mod arbiter;
|
||||||
@@ -63,3 +65,8 @@ pub mod time {
|
|||||||
pub use tokio::time::{sleep, sleep_until, Sleep};
|
pub use tokio::time::{sleep, sleep_until, Sleep};
|
||||||
pub use tokio::time::{timeout, Timeout};
|
pub use tokio::time::{timeout, Timeout};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Blocking task management.
|
||||||
|
pub mod task {
|
||||||
|
pub use tokio::task::{spawn_blocking, yield_now, JoinHandle};
|
||||||
|
}
|
||||||
|
@@ -41,7 +41,7 @@ impl Runtime {
|
|||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```rust,ignore
|
/// ```ignore
|
||||||
/// # use futures::{future, Future, Stream};
|
/// # use futures::{future, Future, Stream};
|
||||||
/// use actix_rt::Runtime;
|
/// use actix_rt::Runtime;
|
||||||
///
|
///
|
||||||
|
@@ -70,7 +70,7 @@ impl System {
|
|||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```rust,ignore
|
/// ```ignore
|
||||||
/// use tokio::{runtime::Runtime, task::LocalSet};
|
/// use tokio::{runtime::Runtime, task::LocalSet};
|
||||||
/// use actix_rt::System;
|
/// use actix_rt::System;
|
||||||
/// use futures_util::future::try_join_all;
|
/// use futures_util::future::try_join_all;
|
||||||
@@ -139,7 +139,7 @@ impl System {
|
|||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```rust,ignore
|
/// ```ignore
|
||||||
/// use tokio::runtime::Runtime;
|
/// use tokio::runtime::Runtime;
|
||||||
/// use actix_rt::System;
|
/// use actix_rt::System;
|
||||||
/// use futures_util::future::try_join_all;
|
/// use futures_util::future::try_join_all;
|
||||||
|
@@ -1,7 +1,16 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## Unreleased - 2020-xx-xx
|
## Unreleased - 2021-xx-xx
|
||||||
* Merge `actix-testing` to `actix-server` as `test_server` mod.
|
* Hidden `ServerBuilder::start` method has been removed. Use `ServerBuilder::run`. [#246]
|
||||||
|
|
||||||
|
[#246]: https://github.com/actix/actix-net/pull/246
|
||||||
|
|
||||||
|
|
||||||
|
## 2.0.0-beta.2 - 2021-01-03
|
||||||
|
* Merge `actix-testing` to `actix-server` as `test_server` mod. [#242]
|
||||||
|
|
||||||
|
[#242]: https://github.com/actix/actix-net/pull/242
|
||||||
|
|
||||||
|
|
||||||
## 2.0.0-beta.1 - 2020-12-28
|
## 2.0.0-beta.1 - 2020-12-28
|
||||||
* Added explicit info log message on accept queue pause. [#215]
|
* Added explicit info log message on accept queue pause. [#215]
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-server"
|
name = "actix-server"
|
||||||
version = "2.0.0-beta.1"
|
version = "2.0.0-beta.2"
|
||||||
authors = [
|
authors = [
|
||||||
"Nikolay Kim <fafhrd91@gmail.com>",
|
"Nikolay Kim <fafhrd91@gmail.com>",
|
||||||
"fakeshadow <24548779@qq.com>",
|
"fakeshadow <24548779@qq.com>",
|
||||||
@@ -25,7 +25,7 @@ default = []
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
actix-codec = "0.4.0-beta.1"
|
actix-codec = "0.4.0-beta.1"
|
||||||
actix-rt = "2.0.0-beta.1"
|
actix-rt = "2.0.0-beta.1"
|
||||||
actix-service = "2.0.0-beta.1"
|
actix-service = "2.0.0-beta.2"
|
||||||
actix-utils = "3.0.0-beta.1"
|
actix-utils = "3.0.0-beta.1"
|
||||||
|
|
||||||
futures-core = { version = "0.3.7", default-features = false }
|
futures-core = { version = "0.3.7", default-features = false }
|
||||||
|
@@ -252,11 +252,6 @@ impl ServerBuilder {
|
|||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub fn start(self) -> Server {
|
|
||||||
self.run()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Starts processing incoming connections and return server controller.
|
/// Starts processing incoming connections and return server controller.
|
||||||
pub fn run(mut self) -> Server {
|
pub fn run(mut self) -> Server {
|
||||||
if self.sockets.is_empty() {
|
if self.sockets.is_empty() {
|
||||||
|
@@ -12,7 +12,7 @@ use crate::{Server, ServerBuilder, ServiceFactory};
|
|||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
/// use actix_service::fn_service;
|
/// use actix_service::fn_service;
|
||||||
/// use actix_server::TestServer;
|
/// use actix_server::TestServer;
|
||||||
///
|
///
|
||||||
@@ -49,10 +49,7 @@ impl TestServer {
|
|||||||
// run server in separate thread
|
// run server in separate thread
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let sys = System::new("actix-test-server");
|
let sys = System::new("actix-test-server");
|
||||||
factory(Server::build())
|
factory(Server::build()).workers(1).disable_signals().run();
|
||||||
.workers(1)
|
|
||||||
.disable_signals()
|
|
||||||
.start();
|
|
||||||
|
|
||||||
tx.send(System::current()).unwrap();
|
tx.send(System::current()).unwrap();
|
||||||
sys.run()
|
sys.run()
|
||||||
@@ -83,7 +80,7 @@ impl TestServer {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.workers(1)
|
.workers(1)
|
||||||
.disable_signals()
|
.disable_signals()
|
||||||
.start();
|
.run();
|
||||||
tx.send((System::current(), local_addr)).unwrap();
|
tx.send((System::current(), local_addr)).unwrap();
|
||||||
});
|
});
|
||||||
sys.run()
|
sys.run()
|
||||||
|
@@ -28,7 +28,7 @@ fn test_bind() {
|
|||||||
.disable_signals()
|
.disable_signals()
|
||||||
.bind("test", addr, move || fn_service(|_| ok::<_, ()>(())))
|
.bind("test", addr, move || fn_service(|_| ok::<_, ()>(())))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.start()
|
.run()
|
||||||
}));
|
}));
|
||||||
let _ = tx.send((srv, actix_rt::System::current()));
|
let _ = tx.send((srv, actix_rt::System::current()));
|
||||||
let _ = sys.run();
|
let _ = sys.run();
|
||||||
@@ -55,7 +55,7 @@ fn test_listen() {
|
|||||||
.workers(1)
|
.workers(1)
|
||||||
.listen("test", lst, move || fn_service(|_| ok::<_, ()>(())))
|
.listen("test", lst, move || fn_service(|_| ok::<_, ()>(())))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.start();
|
.run();
|
||||||
let _ = tx.send(actix_rt::System::current());
|
let _ = tx.send(actix_rt::System::current());
|
||||||
});
|
});
|
||||||
let _ = sys.run();
|
let _ = sys.run();
|
||||||
@@ -94,7 +94,7 @@ fn test_start() {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.start()
|
.run()
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let _ = tx.send((srv, actix_rt::System::current()));
|
let _ = tx.send((srv, actix_rt::System::current()));
|
||||||
@@ -173,7 +173,7 @@ fn test_configure() {
|
|||||||
})
|
})
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.workers(1)
|
.workers(1)
|
||||||
.start()
|
.run()
|
||||||
}));
|
}));
|
||||||
let _ = tx.send((srv, actix_rt::System::current()));
|
let _ = tx.send((srv, actix_rt::System::current()));
|
||||||
let _ = sys.run();
|
let _ = sys.run();
|
||||||
|
@@ -1,6 +1,16 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## Unreleased - 2020-xx-xx
|
## Unreleased - 2021-xx-xx
|
||||||
|
|
||||||
|
|
||||||
|
## 2.0.0-beta.3 - 2021-01-09
|
||||||
|
* The `forward_ready!` macro converts errors. [#246]
|
||||||
|
|
||||||
|
[#246]: https://github.com/actix/actix-net/pull/246
|
||||||
|
|
||||||
|
|
||||||
|
## 2.0.0-beta.2 - 2021-01-03
|
||||||
|
* Remove redundant type parameter from `map_config`.
|
||||||
|
|
||||||
|
|
||||||
## 2.0.0-beta.1 - 2020-12-28
|
## 2.0.0-beta.1 - 2020-12-28
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-service"
|
name = "actix-service"
|
||||||
version = "2.0.0-beta.1"
|
version = "2.0.0-beta.3"
|
||||||
authors = [
|
authors = [
|
||||||
"Nikolay Kim <fafhrd91@gmail.com>",
|
"Nikolay Kim <fafhrd91@gmail.com>",
|
||||||
"Rob Ede <robjtede@icloud.com>",
|
"Rob Ede <robjtede@icloud.com>",
|
||||||
|
@@ -17,7 +17,7 @@ where
|
|||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
/// use std::io;
|
/// use std::io;
|
||||||
/// use actix_service::{fn_factory, fn_service, Service, ServiceFactory};
|
/// use actix_service::{fn_factory, fn_service, Service, ServiceFactory};
|
||||||
/// use futures_util::future::ok;
|
/// use futures_util::future::ok;
|
||||||
@@ -67,7 +67,7 @@ where
|
|||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
/// use std::io;
|
/// use std::io;
|
||||||
/// use actix_service::{fn_factory_with_config, fn_service, Service, ServiceFactory};
|
/// use actix_service::{fn_factory_with_config, fn_service, Service, ServiceFactory};
|
||||||
/// use futures_util::future::ok;
|
/// use futures_util::future::ok;
|
||||||
|
@@ -48,7 +48,7 @@ use self::ready::{err, ok, ready, Ready};
|
|||||||
/// replies. You can think about a service as a function with one argument that returns some result
|
/// replies. You can think about a service as a function with one argument that returns some result
|
||||||
/// asynchronously. Conceptually, the operation looks like this:
|
/// asynchronously. Conceptually, the operation looks like this:
|
||||||
///
|
///
|
||||||
/// ```rust,ignore
|
/// ```ignore
|
||||||
/// async fn(Request) -> Result<Response, Err>
|
/// async fn(Request) -> Result<Response, Err>
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
@@ -60,7 +60,7 @@ use self::ready::{err, ok, ready, Ready};
|
|||||||
/// simple API surfaces. This leads to simpler design of each service, improves test-ability and
|
/// simple API surfaces. This leads to simpler design of each service, improves test-ability and
|
||||||
/// makes composition easier.
|
/// makes composition easier.
|
||||||
///
|
///
|
||||||
/// ```rust,ignore
|
/// ```ignore
|
||||||
/// struct MyService;
|
/// struct MyService;
|
||||||
///
|
///
|
||||||
/// impl Service for MyService {
|
/// impl Service for MyService {
|
||||||
@@ -78,7 +78,7 @@ use self::ready::{err, ok, ready, Ready};
|
|||||||
/// Sometimes it is not necessary to implement the Service trait. For example, the above service
|
/// Sometimes it is not necessary to implement the Service trait. For example, the above service
|
||||||
/// could be rewritten as a simple function and passed to [fn_service](fn_service()).
|
/// could be rewritten as a simple function and passed to [fn_service](fn_service()).
|
||||||
///
|
///
|
||||||
/// ```rust,ignore
|
/// ```ignore
|
||||||
/// async fn my_service(req: u8) -> Result<u64, MyError>;
|
/// async fn my_service(req: u8) -> Result<u64, MyError>;
|
||||||
/// ```
|
/// ```
|
||||||
pub trait Service<Req> {
|
pub trait Service<Req> {
|
||||||
@@ -327,7 +327,9 @@ macro_rules! forward_ready {
|
|||||||
&mut self,
|
&mut self,
|
||||||
cx: &mut ::core::task::Context<'_>,
|
cx: &mut ::core::task::Context<'_>,
|
||||||
) -> ::core::task::Poll<Result<(), Self::Error>> {
|
) -> ::core::task::Poll<Result<(), Self::Error>> {
|
||||||
self.$field.poll_ready(cx)
|
self.$field
|
||||||
|
.poll_ready(cx)
|
||||||
|
.map_err(::core::convert::Into::into)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -30,7 +30,7 @@ where
|
|||||||
///
|
///
|
||||||
/// For example, timeout transform:
|
/// For example, timeout transform:
|
||||||
///
|
///
|
||||||
/// ```rust,ignore
|
/// ```ignore
|
||||||
/// pub struct Timeout<S> {
|
/// pub struct Timeout<S> {
|
||||||
/// service: S,
|
/// service: S,
|
||||||
/// timeout: Duration,
|
/// timeout: Duration,
|
||||||
@@ -45,9 +45,7 @@ where
|
|||||||
/// type Error = TimeoutError<S::Error>;
|
/// type Error = TimeoutError<S::Error>;
|
||||||
/// type Future = TimeoutServiceResponse<S>;
|
/// type Future = TimeoutServiceResponse<S>;
|
||||||
///
|
///
|
||||||
/// fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
/// actix_service::forward_ready!(service);
|
||||||
/// ready!(self.service.poll_ready(cx)).map_err(TimeoutError::Service)
|
|
||||||
/// }
|
|
||||||
///
|
///
|
||||||
/// fn call(&mut self, req: S::Request) -> Self::Future {
|
/// fn call(&mut self, req: S::Request) -> Self::Future {
|
||||||
/// TimeoutServiceResponse {
|
/// TimeoutServiceResponse {
|
||||||
@@ -69,7 +67,7 @@ where
|
|||||||
///
|
///
|
||||||
/// Factory for `Timeout` middleware from the above example could look like this:
|
/// Factory for `Timeout` middleware from the above example could look like this:
|
||||||
///
|
///
|
||||||
/// ```rust,,ignore
|
/// ```ignore
|
||||||
/// pub struct TimeoutTransform {
|
/// pub struct TimeoutTransform {
|
||||||
/// timeout: Duration,
|
/// timeout: Duration,
|
||||||
/// }
|
/// }
|
||||||
|
@@ -1,49 +0,0 @@
|
|||||||
# Changes
|
|
||||||
|
|
||||||
## [0.3.3] - 2020-07-14
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
* Update parking_lot to 0.11
|
|
||||||
|
|
||||||
## [0.3.2] - 2020-05-20
|
|
||||||
|
|
||||||
## Added
|
|
||||||
|
|
||||||
* Implement `std::error::Error` for `BlockingError` [#120]
|
|
||||||
|
|
||||||
[#120]: https://github.com/actix/actix-net/pull/120
|
|
||||||
|
|
||||||
## [0.3.1] - 2019-12-12
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
* Update parking_lot to 0.10
|
|
||||||
|
|
||||||
## [0.3.0] - 2019-12-02
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
* Expect `Result` type as a function return type
|
|
||||||
|
|
||||||
## [0.2.0] - 2019-11-21
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
* Migrate to `std::future`
|
|
||||||
|
|
||||||
## [0.1.2] - 2019-08-05
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
* Update `derive_more` to 0.15
|
|
||||||
|
|
||||||
* Update `parking_lot` to 0.9
|
|
||||||
|
|
||||||
## [0.1.1] - 2019-06-05
|
|
||||||
|
|
||||||
* Update parking_lot
|
|
||||||
|
|
||||||
## [0.1.0] - 2019-03-28
|
|
||||||
|
|
||||||
* Move threadpool to separate crate
|
|
@@ -1,27 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "actix-threadpool"
|
|
||||||
version = "0.3.3"
|
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
|
||||||
description = "Actix thread pool for sync code"
|
|
||||||
keywords = ["actix", "network", "framework", "async", "futures"]
|
|
||||||
homepage = "https://actix.rs"
|
|
||||||
repository = "https://github.com/actix/actix-net.git"
|
|
||||||
documentation = "https://docs.rs/actix-threadpool/"
|
|
||||||
categories = ["network-programming", "asynchronous"]
|
|
||||||
license = "MIT OR Apache-2.0"
|
|
||||||
exclude = [".gitignore", ".travis.yml", ".cargo/config", "appveyor.yml"]
|
|
||||||
edition = "2018"
|
|
||||||
workspace = ".."
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
name = "actix_threadpool"
|
|
||||||
path = "src/lib.rs"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
derive_more = "0.99.2"
|
|
||||||
futures-channel = "0.3.7"
|
|
||||||
parking_lot = "0.11"
|
|
||||||
lazy_static = "1.3"
|
|
||||||
log = "0.4"
|
|
||||||
num_cpus = "1.10"
|
|
||||||
threadpool = "1.7"
|
|
@@ -1 +0,0 @@
|
|||||||
../LICENSE-APACHE
|
|
@@ -1 +0,0 @@
|
|||||||
../LICENSE-MIT
|
|
@@ -1,96 +0,0 @@
|
|||||||
//! Thread pool for blocking operations
|
|
||||||
|
|
||||||
#![deny(rust_2018_idioms, nonstandard_style)]
|
|
||||||
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
|
||||||
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
|
||||||
|
|
||||||
use std::fmt;
|
|
||||||
use std::future::Future;
|
|
||||||
use std::pin::Pin;
|
|
||||||
use std::task::{Context, Poll};
|
|
||||||
|
|
||||||
use derive_more::Display;
|
|
||||||
use futures_channel::oneshot;
|
|
||||||
use parking_lot::Mutex;
|
|
||||||
use threadpool::ThreadPool;
|
|
||||||
|
|
||||||
/// Env variable for default cpu pool size.
|
|
||||||
const ENV_CPU_POOL_VAR: &str = "ACTIX_THREADPOOL";
|
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
|
||||||
pub(crate) static ref DEFAULT_POOL: Mutex<ThreadPool> = {
|
|
||||||
let num = std::env::var(ENV_CPU_POOL_VAR)
|
|
||||||
.map_err(|_| ())
|
|
||||||
.and_then(|val| {
|
|
||||||
val.parse().map_err(|_| log::warn!(
|
|
||||||
"Can not parse {} value, using default",
|
|
||||||
ENV_CPU_POOL_VAR,
|
|
||||||
))
|
|
||||||
})
|
|
||||||
.unwrap_or_else(|_| num_cpus::get() * 5);
|
|
||||||
Mutex::new(
|
|
||||||
threadpool::Builder::new()
|
|
||||||
.thread_name("actix-web".to_owned())
|
|
||||||
.num_threads(num)
|
|
||||||
.build(),
|
|
||||||
)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
thread_local! {
|
|
||||||
static POOL: ThreadPool = {
|
|
||||||
DEFAULT_POOL.lock().clone()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Blocking operation execution error
|
|
||||||
#[derive(Debug, Display)]
|
|
||||||
pub enum BlockingError<E: fmt::Debug> {
|
|
||||||
#[display(fmt = "{:?}", _0)]
|
|
||||||
Error(E),
|
|
||||||
#[display(fmt = "Thread pool is gone")]
|
|
||||||
Canceled,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<E: fmt::Debug> std::error::Error for BlockingError<E> {}
|
|
||||||
|
|
||||||
/// Execute blocking function on a thread pool, returns future that resolves
|
|
||||||
/// to result of the function execution.
|
|
||||||
pub fn run<F, I, E>(f: F) -> CpuFuture<I, E>
|
|
||||||
where
|
|
||||||
F: FnOnce() -> Result<I, E> + Send + 'static,
|
|
||||||
I: Send + 'static,
|
|
||||||
E: Send + fmt::Debug + 'static,
|
|
||||||
{
|
|
||||||
let (tx, rx) = oneshot::channel();
|
|
||||||
POOL.with(|pool| {
|
|
||||||
pool.execute(move || {
|
|
||||||
if !tx.is_canceled() {
|
|
||||||
let _ = tx.send(f());
|
|
||||||
}
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
CpuFuture { rx }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Blocking operation completion future. It resolves with results
|
|
||||||
/// of blocking function execution.
|
|
||||||
pub struct CpuFuture<I, E> {
|
|
||||||
rx: oneshot::Receiver<Result<I, E>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<I, E: fmt::Debug> Future for CpuFuture<I, E> {
|
|
||||||
type Output = Result<I, BlockingError<E>>;
|
|
||||||
|
|
||||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
|
||||||
let rx = Pin::new(&mut self.rx);
|
|
||||||
let res = match rx.poll(cx) {
|
|
||||||
Poll::Pending => return Poll::Pending,
|
|
||||||
Poll::Ready(res) => res
|
|
||||||
.map_err(|_| BlockingError::Canceled)
|
|
||||||
.and_then(|res| res.map_err(BlockingError::Error)),
|
|
||||||
};
|
|
||||||
Poll::Ready(res)
|
|
||||||
}
|
|
||||||
}
|
|
@@ -3,6 +3,12 @@
|
|||||||
## Unreleased - 2021-xx-xx
|
## Unreleased - 2021-xx-xx
|
||||||
|
|
||||||
|
|
||||||
|
## 3.0.0-beta.2 - 2021-xx-xx
|
||||||
|
* Depend on stable trust-dns packages. [#204]
|
||||||
|
|
||||||
|
[#204]: https://github.com/actix/actix-net/pull/204
|
||||||
|
|
||||||
|
|
||||||
## 3.0.0-beta.1 - 2020-12-29
|
## 3.0.0-beta.1 - 2020-12-29
|
||||||
* Move acceptors under `accept` module. [#238]
|
* Move acceptors under `accept` module. [#238]
|
||||||
* Merge `actix-connect` crate under `connect` module. [#238]
|
* Merge `actix-connect` crate under `connect` module. [#238]
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-tls"
|
name = "actix-tls"
|
||||||
version = "3.0.0-beta.1"
|
version = "3.0.0-beta.2"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "TLS acceptor and connector services for Actix ecosystem"
|
description = "TLS acceptor and connector services for Actix ecosystem"
|
||||||
keywords = ["network", "tls", "ssl", "async", "transport"]
|
keywords = ["network", "tls", "ssl", "async", "transport"]
|
||||||
@@ -46,7 +46,7 @@ uri = ["http"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
actix-codec = "0.4.0-beta.1"
|
actix-codec = "0.4.0-beta.1"
|
||||||
actix-rt = "2.0.0-beta.1"
|
actix-rt = "2.0.0-beta.1"
|
||||||
actix-service = "2.0.0-beta.1"
|
actix-service = "2.0.0-beta.2"
|
||||||
actix-utils = "3.0.0-beta.1"
|
actix-utils = "3.0.0-beta.1"
|
||||||
|
|
||||||
derive_more = "0.99.5"
|
derive_more = "0.99.5"
|
||||||
@@ -76,7 +76,7 @@ tls-native-tls = { package = "native-tls", version = "0.2", optional = true }
|
|||||||
tokio-native-tls = { version = "0.3", optional = true }
|
tokio-native-tls = { version = "0.3", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix-server = "2.0.0-beta.1"
|
actix-server = "2.0.0-beta.2"
|
||||||
bytes = "1"
|
bytes = "1"
|
||||||
env_logger = "0.8"
|
env_logger = "0.8"
|
||||||
futures-util = { version = "0.3.7", default-features = false, features = ["sink"] }
|
futures-util = { version = "0.3.7", default-features = false, features = ["sink"] }
|
||||||
|
@@ -16,7 +16,7 @@ name = "actix_tracing"
|
|||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-service = "2.0.0-beta.1"
|
actix-service = "2.0.0-beta.2"
|
||||||
|
|
||||||
futures-util = { version = "0.3.4", default-features = false }
|
futures-util = { version = "0.3.4", default-features = false }
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
|
@@ -94,7 +94,7 @@ where
|
|||||||
/// is passed in a reference to the request being handled by the service.
|
/// is passed in a reference to the request being handled by the service.
|
||||||
///
|
///
|
||||||
/// For example:
|
/// For example:
|
||||||
/// ```rust,ignore
|
/// ```ignore
|
||||||
/// let traced_service = trace(
|
/// let traced_service = trace(
|
||||||
/// web_service,
|
/// web_service,
|
||||||
/// |req: &Request| Some(span!(Level::INFO, "request", req.id))
|
/// |req: &Request| Some(span!(Level::INFO, "request", req.id))
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## Unreleased - 2020-xx-xx
|
## Unreleased - 2021-xx-xx
|
||||||
|
|
||||||
|
|
||||||
## 3.0.0-beta.1 - 2020-12-28
|
## 3.0.0-beta.1 - 2020-12-28
|
||||||
|
@@ -18,7 +18,7 @@ path = "src/lib.rs"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
actix-codec = "0.4.0-beta.1"
|
actix-codec = "0.4.0-beta.1"
|
||||||
actix-rt = "2.0.0-beta.1"
|
actix-rt = "2.0.0-beta.1"
|
||||||
actix-service = "2.0.0-beta.1"
|
actix-service = "2.0.0-beta.2"
|
||||||
|
|
||||||
futures-core = { version = "0.3.7", default-features = false }
|
futures-core = { version = "0.3.7", default-features = false }
|
||||||
futures-sink = { version = "0.3.7", default-features = false }
|
futures-sink = { version = "0.3.7", default-features = false }
|
||||||
|
@@ -149,9 +149,7 @@ where
|
|||||||
type Error = TimeoutError<S::Error>;
|
type Error = TimeoutError<S::Error>;
|
||||||
type Future = TimeoutServiceResponse<S, Req>;
|
type Future = TimeoutServiceResponse<S, Req>;
|
||||||
|
|
||||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
actix_service::forward_ready!(service);
|
||||||
self.service.poll_ready(cx).map_err(TimeoutError::Service)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn call(&mut self, request: Req) -> Self::Future {
|
fn call(&mut self, request: Req) -> Self::Future {
|
||||||
TimeoutServiceResponse {
|
TimeoutServiceResponse {
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## Unreleased - 2020-xx-xx
|
## Unreleased - 2021-xx-xx
|
||||||
|
|
||||||
|
|
||||||
## 1.0.0 - 2020-12-31
|
## 1.0.0 - 2020-12-31
|
||||||
|
@@ -24,4 +24,4 @@ serde = { version = "1.0", optional = true }
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
siphasher = "0.3"
|
ahash = { version = "0.6", default-features = false }
|
||||||
|
@@ -224,7 +224,7 @@ mod test {
|
|||||||
use alloc::borrow::ToOwned;
|
use alloc::borrow::ToOwned;
|
||||||
use core::hash::{Hash, Hasher};
|
use core::hash::{Hash, Hasher};
|
||||||
|
|
||||||
use siphasher::sip::SipHasher;
|
use ahash::AHasher;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
@@ -243,10 +243,10 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_hash() {
|
fn test_hash() {
|
||||||
let mut hasher1 = SipHasher::default();
|
let mut hasher1 = AHasher::default();
|
||||||
"str".hash(&mut hasher1);
|
"str".hash(&mut hasher1);
|
||||||
|
|
||||||
let mut hasher2 = SipHasher::default();
|
let mut hasher2 = AHasher::default();
|
||||||
let s = ByteString::from_static("str");
|
let s = ByteString::from_static("str");
|
||||||
s.hash(&mut hasher2);
|
s.hash(&mut hasher2);
|
||||||
assert_eq!(hasher1.finish(), hasher2.finish());
|
assert_eq!(hasher1.finish(), hasher2.finish());
|
||||||
|
Reference in New Issue
Block a user