mirror of
https://github.com/fafhrd91/actix-net
synced 2025-08-14 10:00:31 +02:00
Compare commits
26 Commits
server-v2.
...
codec-v0.5
Author | SHA1 | Date | |
---|---|---|---|
|
855e3f96fe | ||
|
737b438f73 | ||
|
0cd70b0536 | ||
|
4b6a581ef3 | ||
|
3e132d2bc6 | ||
|
c5d6174cec | ||
|
77d4a69b2f | ||
|
ae5377fd6e | ||
|
bd9bda0504 | ||
|
41ed48219d | ||
|
7804ed12eb | ||
|
2a54065fae | ||
|
217cbd2228 | ||
|
d229c1e886 | ||
|
6792f799a6 | ||
|
72481313cc | ||
|
59b629c74b | ||
|
7988694242 | ||
|
b8a7741524 | ||
|
5e290d76f8 | ||
|
0edb64575f | ||
|
941f67dec9 | ||
|
3e624b8376 | ||
|
26446fdbad | ||
|
b7b7bd2cbf | ||
|
637625f9b7 |
70
.github/workflows/ci-master.yml
vendored
70
.github/workflows/ci-master.yml
vendored
@@ -124,7 +124,7 @@ jobs:
|
|||||||
- name: Install Rust (nightly)
|
- name: Install Rust (nightly)
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: stable-x86_64-unknown-linux-gnu
|
toolchain: nightly
|
||||||
profile: minimal
|
profile: minimal
|
||||||
override: true
|
override: true
|
||||||
|
|
||||||
@@ -143,3 +143,71 @@ jobs:
|
|||||||
if: github.ref == 'refs/heads/master'
|
if: github.ref == 'refs/heads/master'
|
||||||
uses: codecov/codecov-action@v1
|
uses: codecov/codecov-action@v1
|
||||||
with: { file: cobertura.xml }
|
with: { file: cobertura.xml }
|
||||||
|
|
||||||
|
minimal-versions:
|
||||||
|
name: minimal versions
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Install Rust (nightly)
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: nightly
|
||||||
|
profile: minimal
|
||||||
|
override: true
|
||||||
|
|
||||||
|
- name: Generate Cargo.lock
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with: { command: generate-lockfile }
|
||||||
|
- name: Cache Dependencies
|
||||||
|
uses: Swatinem/rust-cache@v1.3.0
|
||||||
|
|
||||||
|
- name: Install cargo-minimal-versions
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: install
|
||||||
|
args: cargo-minimal-versions
|
||||||
|
|
||||||
|
- name: Install cargo-hack
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: install
|
||||||
|
args: cargo-hack
|
||||||
|
|
||||||
|
- name: Check With Minimal Versions
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: minimal-versions
|
||||||
|
args: check
|
||||||
|
|
||||||
|
nextest:
|
||||||
|
name: nextest
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Install Rust
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
profile: minimal
|
||||||
|
override: true
|
||||||
|
|
||||||
|
- name: Generate Cargo.lock
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with: { command: generate-lockfile }
|
||||||
|
- name: Cache Dependencies
|
||||||
|
uses: Swatinem/rust-cache@v1.3.0
|
||||||
|
|
||||||
|
- name: Install cargo-nextest
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: install
|
||||||
|
args: cargo-nextest
|
||||||
|
|
||||||
|
- name: Test with cargo-nextest
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: nextest
|
||||||
|
args: run
|
||||||
|
18
.github/workflows/ci.yml
vendored
18
.github/workflows/ci.yml
vendored
@@ -119,15 +119,15 @@ jobs:
|
|||||||
cargo-cache
|
cargo-cache
|
||||||
|
|
||||||
build_and_test_lower_msrv:
|
build_and_test_lower_msrv:
|
||||||
name: Linux / 1.46 (lower MSRV)
|
name: Linux / 1.49 (lower MSRV)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Install 1.46.0 # MSRV for all but -server and -tls
|
- name: Install 1.49.0 # MSRV for all but -server and -tls
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.46.0-x86_64-unknown-linux-gnu
|
toolchain: 1.49.0-x86_64-unknown-linux-gnu
|
||||||
profile: minimal
|
profile: minimal
|
||||||
override: true
|
override: true
|
||||||
|
|
||||||
@@ -137,9 +137,19 @@ jobs:
|
|||||||
command: install
|
command: install
|
||||||
args: cargo-hack
|
args: cargo-hack
|
||||||
|
|
||||||
|
- name: Generate Cargo.lock
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with: { command: generate-lockfile }
|
||||||
|
|
||||||
|
- name: Tweak lockfile
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: update
|
||||||
|
args: -p=rustls --precise=0.20.2
|
||||||
|
|
||||||
- name: tests
|
- name: tests
|
||||||
run: |
|
run: |
|
||||||
sudo bash -c "ulimit -Sl 512 && ulimit -Hl 512 && PATH=$PATH:/usr/share/rust/.cargo/bin && RUSTUP_TOOLCHAIN=1.46 cargo ci-test-lower-msrv"
|
sudo bash -c "ulimit -Sl 512 && ulimit -Hl 512 && PATH=$PATH:/usr/share/rust/.cargo/bin && RUSTUP_TOOLCHAIN=1.49 cargo ci-test-lower-msrv"
|
||||||
|
|
||||||
- name: Clear the cargo caches
|
- name: Clear the cargo caches
|
||||||
run: |
|
run: |
|
||||||
|
12
README.md
12
README.md
@@ -2,18 +2,18 @@
|
|||||||
|
|
||||||
> A collection of lower-level libraries for composable network services.
|
> A collection of lower-level libraries for composable network services.
|
||||||
|
|
||||||
[](https://github.com/actix/actix-net/actions/workflows/ci.yml)
|
[](https://github.com/actix/actix-net/actions/workflows/ci.yml)
|
||||||
[](https://codecov.io/gh/actix/actix-net)
|
[](https://codecov.io/gh/actix/actix-net)
|
||||||
[](https://discord.gg/NWpN5mmg3x)
|
[](https://discord.gg/NWpN5mmg3x)
|
||||||
[](https://deps.rs/repo/github/actix/actix-extras)
|
[](https://deps.rs/repo/github/actix/actix-net)
|
||||||
|
|
||||||
## Example
|
## Examples
|
||||||
|
|
||||||
See `actix-server/examples` and `actix-tls/examples` for some basic examples.
|
See example folders for [`actix-server`](./actix-server/examples) and [`actix-tls`](./actix-tls/examples).
|
||||||
|
|
||||||
### MSRV
|
## MSRV
|
||||||
|
|
||||||
This repo's Minimum Supported Rust Version (MSRV) is 1.46.0.
|
Most crates in this repo's have a Minimum Supported Rust Version (MSRV) of 1.49.0. Only `actix-tls` and `actix-server` have MSRV of 1.54.0. As a policy, we permit MSRV increases in non-breaking releases.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
@@ -1,6 +1,19 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## Unreleased - 2021-xx-xx
|
## Unreleased - 2022-xx-xx
|
||||||
|
|
||||||
|
|
||||||
|
## 0.5.1 - 2022-03-15
|
||||||
|
- Logs emitted now use the `tracing` crate with `log` compatibility. [#451]
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.49.
|
||||||
|
|
||||||
|
[#451]: https://github.com/actix/actix-net/pull/451
|
||||||
|
|
||||||
|
|
||||||
|
## 0.5.0 - 2022-02-15
|
||||||
|
- Updated `tokio-util` dependency to `0.7.0`. [#446]
|
||||||
|
|
||||||
|
[#446]: https://github.com/actix/actix-net/pull/446
|
||||||
|
|
||||||
|
|
||||||
## 0.4.2 - 2021-12-31
|
## 0.4.2 - 2021-12-31
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-codec"
|
name = "actix-codec"
|
||||||
version = "0.4.2"
|
version = "0.5.1"
|
||||||
authors = [
|
authors = [
|
||||||
"Nikolay Kim <fafhrd91@gmail.com>",
|
"Nikolay Kim <fafhrd91@gmail.com>",
|
||||||
"Rob Ede <robjtede@icloud.com>",
|
"Rob Ede <robjtede@icloud.com>",
|
||||||
@@ -17,15 +17,15 @@ name = "actix_codec"
|
|||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitflags = "1.2.1"
|
bitflags = "1.2"
|
||||||
bytes = "1"
|
bytes = "1"
|
||||||
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 }
|
||||||
log = "0.4"
|
|
||||||
memchr = "2.3"
|
memchr = "2.3"
|
||||||
pin-project-lite = "0.2"
|
pin-project-lite = "0.2"
|
||||||
tokio = "1.13.1"
|
tokio = "1.13.1"
|
||||||
tokio-util = { version = "0.6", features = ["codec", "io"] }
|
tokio-util = { version = "0.7", features = ["codec", "io"] }
|
||||||
|
tracing = { version = "0.1.30", default-features = false, features = ["log"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
criterion = { version = "0.3", features = ["html_reports"] }
|
criterion = { version = "0.3", features = ["html_reports"] }
|
||||||
|
@@ -193,18 +193,18 @@ impl<T, U> Framed<T, U> {
|
|||||||
match this.codec.decode_eof(this.read_buf) {
|
match this.codec.decode_eof(this.read_buf) {
|
||||||
Ok(Some(frame)) => return Poll::Ready(Some(Ok(frame))),
|
Ok(Some(frame)) => return Poll::Ready(Some(Ok(frame))),
|
||||||
Ok(None) => return Poll::Ready(None),
|
Ok(None) => return Poll::Ready(None),
|
||||||
Err(e) => return Poll::Ready(Some(Err(e))),
|
Err(err) => return Poll::Ready(Some(Err(err))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log::trace!("attempting to decode a frame");
|
tracing::trace!("attempting to decode a frame");
|
||||||
|
|
||||||
match this.codec.decode(this.read_buf) {
|
match this.codec.decode(this.read_buf) {
|
||||||
Ok(Some(frame)) => {
|
Ok(Some(frame)) => {
|
||||||
log::trace!("frame decoded from buffer");
|
tracing::trace!("frame decoded from buffer");
|
||||||
return Poll::Ready(Some(Ok(frame)));
|
return Poll::Ready(Some(Ok(frame)));
|
||||||
}
|
}
|
||||||
Err(e) => return Poll::Ready(Some(Err(e))),
|
Err(err) => return Poll::Ready(Some(Err(err))),
|
||||||
_ => (), // Need more data
|
_ => (), // Need more data
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,7 +221,7 @@ impl<T, U> Framed<T, U> {
|
|||||||
|
|
||||||
let cnt = match tokio_util::io::poll_read_buf(this.io, cx, this.read_buf) {
|
let cnt = match tokio_util::io::poll_read_buf(this.io, cx, this.read_buf) {
|
||||||
Poll::Pending => return Poll::Pending,
|
Poll::Pending => return Poll::Pending,
|
||||||
Poll::Ready(Err(e)) => return Poll::Ready(Some(Err(e.into()))),
|
Poll::Ready(Err(err)) => return Poll::Ready(Some(Err(err.into()))),
|
||||||
Poll::Ready(Ok(cnt)) => cnt,
|
Poll::Ready(Ok(cnt)) => cnt,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -242,10 +242,10 @@ impl<T, U> Framed<T, U> {
|
|||||||
U: Encoder<I>,
|
U: Encoder<I>,
|
||||||
{
|
{
|
||||||
let mut this = self.as_mut().project();
|
let mut this = self.as_mut().project();
|
||||||
log::trace!("flushing framed transport");
|
tracing::trace!("flushing framed transport");
|
||||||
|
|
||||||
while !this.write_buf.is_empty() {
|
while !this.write_buf.is_empty() {
|
||||||
log::trace!("writing; remaining={}", this.write_buf.len());
|
tracing::trace!("writing; remaining={}", this.write_buf.len());
|
||||||
|
|
||||||
let n = ready!(this.io.as_mut().poll_write(cx, this.write_buf))?;
|
let n = ready!(this.io.as_mut().poll_write(cx, this.write_buf))?;
|
||||||
|
|
||||||
@@ -264,7 +264,7 @@ impl<T, U> Framed<T, U> {
|
|||||||
// Try flushing the underlying IO
|
// Try flushing the underlying IO
|
||||||
ready!(this.io.poll_flush(cx))?;
|
ready!(this.io.poll_flush(cx))?;
|
||||||
|
|
||||||
log::trace!("framed transport flushed");
|
tracing::trace!("framed transport flushed");
|
||||||
Poll::Ready(Ok(()))
|
Poll::Ready(Ok(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -7,8 +7,8 @@ use super::{Decoder, Encoder};
|
|||||||
|
|
||||||
/// Lines codec. Reads/writes line delimited strings.
|
/// Lines codec. Reads/writes line delimited strings.
|
||||||
///
|
///
|
||||||
/// Will split input up by LF or CRLF delimiters. I.e. carriage return characters at the end of
|
/// Will split input up by LF or CRLF delimiters. Carriage return characters at the end of lines are
|
||||||
/// lines are not preserved.
|
/// not preserved.
|
||||||
#[derive(Debug, Copy, Clone, Default)]
|
#[derive(Debug, Copy, Clone, Default)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub struct LinesCodec;
|
pub struct LinesCodec;
|
||||||
|
@@ -50,7 +50,7 @@ impl Write for Bilateral {
|
|||||||
assert_eq!(&data[..], &src[..data.len()]);
|
assert_eq!(&data[..], &src[..data.len()]);
|
||||||
Ok(data.len())
|
Ok(data.len())
|
||||||
}
|
}
|
||||||
Some(Err(e)) => Err(e),
|
Some(Err(err)) => Err(err),
|
||||||
None => panic!("unexpected write; {:?}", src),
|
None => panic!("unexpected write; {:?}", src),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,13 +67,13 @@ impl AsyncWrite for Bilateral {
|
|||||||
buf: &[u8],
|
buf: &[u8],
|
||||||
) -> Poll<Result<usize, io::Error>> {
|
) -> Poll<Result<usize, io::Error>> {
|
||||||
match Pin::get_mut(self).write(buf) {
|
match Pin::get_mut(self).write(buf) {
|
||||||
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => Pending,
|
Err(ref err) if err.kind() == io::ErrorKind::WouldBlock => Pending,
|
||||||
other => Ready(other),
|
other => Ready(other),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
|
fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
|
||||||
match Pin::get_mut(self).flush() {
|
match Pin::get_mut(self).flush() {
|
||||||
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => Pending,
|
Err(ref err) if err.kind() == io::ErrorKind::WouldBlock => Pending,
|
||||||
other => Ready(other),
|
other => Ready(other),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,8 +99,8 @@ impl AsyncRead for Bilateral {
|
|||||||
buf.put_slice(&data);
|
buf.put_slice(&data);
|
||||||
Ready(Ok(()))
|
Ready(Ok(()))
|
||||||
}
|
}
|
||||||
Some(Err(ref e)) if e.kind() == WouldBlock => Pending,
|
Some(Err(ref err)) if err.kind() == WouldBlock => Pending,
|
||||||
Some(Err(e)) => Ready(Err(e)),
|
Some(Err(err)) => Ready(Err(err)),
|
||||||
None => Ready(Ok(())),
|
None => Ready(Ok(())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## Unreleased - 2021-xx-xx
|
## Unreleased - 2022-xx-xx
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.49.
|
||||||
|
|
||||||
|
|
||||||
## 0.2.3 - 2021-10-19
|
## 0.2.3 - 2021-10-19
|
||||||
|
@@ -1,6 +1,13 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## Unreleased - 2021-xx-xx
|
## Unreleased - 2022-xx-xx
|
||||||
|
|
||||||
|
|
||||||
|
## 2.7.0 - 2022-03-08
|
||||||
|
- Update `tokio-uring` dependency to `0.3.0`. [#448]
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.49.
|
||||||
|
|
||||||
|
[#448]: https://github.com/actix/actix-net/pull/448
|
||||||
|
|
||||||
|
|
||||||
## 2.6.0 - 2022-01-12
|
## 2.6.0 - 2022-01-12
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-rt"
|
name = "actix-rt"
|
||||||
version = "2.6.0"
|
version = "2.7.0"
|
||||||
authors = [
|
authors = [
|
||||||
"Nikolay Kim <fafhrd91@gmail.com>",
|
"Nikolay Kim <fafhrd91@gmail.com>",
|
||||||
"Rob Ede <robjtede@icloud.com>",
|
"Rob Ede <robjtede@icloud.com>",
|
||||||
@@ -29,10 +29,10 @@ actix-macros = { version = "0.2.3", optional = true }
|
|||||||
futures-core = { version = "0.3", default-features = false }
|
futures-core = { version = "0.3", default-features = false }
|
||||||
tokio = { version = "1.13.1", features = ["rt", "net", "parking_lot", "signal", "sync", "time"] }
|
tokio = { version = "1.13.1", features = ["rt", "net", "parking_lot", "signal", "sync", "time"] }
|
||||||
|
|
||||||
# runtime for io-uring feature
|
# runtime for `io-uring` feature
|
||||||
[target.'cfg(target_os = "linux")'.dependencies]
|
[target.'cfg(target_os = "linux")'.dependencies]
|
||||||
tokio-uring = { version = "0.2", optional = true }
|
tokio-uring = { version = "0.3", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tokio = { version = "1.13.1", features = ["full"] }
|
tokio = { version = "1.13.1", features = ["full"] }
|
||||||
hyper = { version = "0.14", default-features = false, features = ["server", "tcp", "http1"] }
|
hyper = { version = "0.14.10", default-features = false, features = ["server", "tcp", "http1"] }
|
||||||
|
@@ -3,11 +3,11 @@
|
|||||||
> Tokio-based single-threaded async runtime for the Actix ecosystem.
|
> Tokio-based single-threaded async runtime for the Actix ecosystem.
|
||||||
|
|
||||||
[](https://crates.io/crates/actix-rt)
|
[](https://crates.io/crates/actix-rt)
|
||||||
[](https://docs.rs/actix-rt/2.6.0)
|
[](https://docs.rs/actix-rt/2.7.0)
|
||||||
[](https://blog.rust-lang.org/2020/03/12/Rust-1.46.html)
|
[](https://blog.rust-lang.org/2020/03/12/Rust-1.46.html)
|
||||||

|

|
||||||
<br />
|
<br />
|
||||||
[](https://deps.rs/crate/actix-rt/2.6.0)
|
[](https://deps.rs/crate/actix-rt/2.7.0)
|
||||||

|

|
||||||
[](https://discord.gg/WghFtEH6Hb)
|
[](https://discord.gg/WghFtEH6Hb)
|
||||||
|
|
||||||
|
@@ -21,8 +21,8 @@ fn main() {
|
|||||||
let server =
|
let server =
|
||||||
Server::bind(&SocketAddr::from(([127, 0, 0, 1], 3000))).serve(make_service);
|
Server::bind(&SocketAddr::from(([127, 0, 0, 1], 3000))).serve(make_service);
|
||||||
|
|
||||||
if let Err(e) = server.await {
|
if let Err(err) = server.await {
|
||||||
eprintln!("server error: {}", e);
|
eprintln!("server error: {}", err);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,23 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## Unreleased - 2021-xx-xx
|
## Unreleased - 2022-xx-xx
|
||||||
|
|
||||||
|
|
||||||
|
## 2.1.1 - 2022-03-09
|
||||||
|
- No significant changes since `2.1.0`.
|
||||||
|
|
||||||
|
|
||||||
|
## 2.1.0 - 2022-03-08
|
||||||
|
- Update `tokio-uring` dependency to `0.3.0`. [#448]
|
||||||
|
- Logs emitted now use the `tracing` crate with `log` compatibility. [#448]
|
||||||
|
- Wait for accept thread to stop before sending completion signal. [#443]
|
||||||
|
|
||||||
|
[#443]: https://github.com/actix/actix-net/pull/443
|
||||||
|
[#448]: https://github.com/actix/actix-net/pull/448
|
||||||
|
|
||||||
|
|
||||||
|
## 2.0.0 - 2022-01-19
|
||||||
|
- No significant changes since `2.0.0-rc.4`.
|
||||||
|
|
||||||
|
|
||||||
## 2.0.0-rc.4 - 2022-01-12
|
## 2.0.0-rc.4 - 2022-01-12
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-server"
|
name = "actix-server"
|
||||||
version = "2.0.0-rc.4"
|
version = "2.1.1"
|
||||||
authors = [
|
authors = [
|
||||||
"Nikolay Kim <fafhrd91@gmail.com>",
|
"Nikolay Kim <fafhrd91@gmail.com>",
|
||||||
"fakeshadow <24548779@qq.com>",
|
"fakeshadow <24548779@qq.com>",
|
||||||
@@ -24,24 +24,24 @@ default = []
|
|||||||
io-uring = ["tokio-uring", "actix-rt/io-uring"]
|
io-uring = ["tokio-uring", "actix-rt/io-uring"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-rt = { version = "2.6.0", default-features = false }
|
actix-rt = { version = "2.7", default-features = false }
|
||||||
actix-service = "2.0.0"
|
actix-service = "2"
|
||||||
actix-utils = "3.0.0"
|
actix-utils = "3"
|
||||||
|
|
||||||
futures-core = { version = "0.3.7", default-features = false, features = ["alloc"] }
|
futures-core = { version = "0.3.7", default-features = false, features = ["alloc"] }
|
||||||
futures-util = { version = "0.3.7", default-features = false, features = ["alloc"] }
|
futures-util = { version = "0.3.7", default-features = false, features = ["alloc"] }
|
||||||
log = "0.4"
|
|
||||||
mio = { version = "0.8", features = ["os-poll", "net"] }
|
mio = { version = "0.8", features = ["os-poll", "net"] }
|
||||||
num_cpus = "1.13"
|
num_cpus = "1.13"
|
||||||
socket2 = "0.4.2"
|
socket2 = "0.4.2"
|
||||||
tokio = { version = "1.13.1", features = ["sync"] }
|
tokio = { version = "1.13.1", features = ["sync"] }
|
||||||
|
tracing = { version = "0.1.30", default-features = false, features = ["log"] }
|
||||||
|
|
||||||
# runtime for io-uring feature
|
# runtime for `io-uring` feature
|
||||||
[target.'cfg(target_os = "linux")'.dependencies]
|
[target.'cfg(target_os = "linux")'.dependencies]
|
||||||
tokio-uring = { version = "0.2", optional = true }
|
tokio-uring = { version = "0.3", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix-codec = "0.4.2"
|
actix-codec = "0.5.0"
|
||||||
actix-rt = "2.6.0"
|
actix-rt = "2.6.0"
|
||||||
|
|
||||||
bytes = "1"
|
bytes = "1"
|
||||||
|
15
actix-server/README.md
Normal file
15
actix-server/README.md
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# actix-server
|
||||||
|
|
||||||
|
> General purpose TCP server built for the Actix ecosystem.
|
||||||
|
|
||||||
|
[](https://crates.io/crates/actix-server)
|
||||||
|
[](https://docs.rs/actix-server/2.1.1)
|
||||||
|
[](https://blog.rust-lang.org/2021/05/06/Rust-1.52.0.html)
|
||||||
|

|
||||||
|
[](https://deps.rs/crate/actix-server/2.1.1)
|
||||||
|

|
||||||
|
[](https://discord.gg/NWpN5mmg3x)
|
||||||
|
|
||||||
|
## Resources
|
||||||
|
- [Library Documentation](https://docs.rs/actix-server)
|
||||||
|
- [Examples](/actix-server/examples)
|
@@ -21,7 +21,7 @@ async fn run() -> io::Result<()> {
|
|||||||
env_logger::init_from_env(env_logger::Env::default().default_filter_or("info"));
|
env_logger::init_from_env(env_logger::Env::default().default_filter_or("info"));
|
||||||
|
|
||||||
let addr = ("127.0.0.1", 8080);
|
let addr = ("127.0.0.1", 8080);
|
||||||
log::info!("starting server on port: {}", &addr.0);
|
tracing::info!("starting server on port: {}", &addr.0);
|
||||||
|
|
||||||
// Bind socket address and start worker(s). By default, the server uses the number of physical
|
// Bind socket address and start worker(s). By default, the server uses the number of physical
|
||||||
// CPU cores as the worker count. For this reason, the closure passed to bind needs to return
|
// CPU cores as the worker count. For this reason, the closure passed to bind needs to return
|
||||||
@@ -39,8 +39,10 @@ async fn run() -> io::Result<()> {
|
|||||||
// wait for next line
|
// wait for next line
|
||||||
match framed.next().await {
|
match framed.next().await {
|
||||||
Some(Ok(line)) => {
|
Some(Ok(line)) => {
|
||||||
match File::open(line).await {
|
match File::open(&line).await {
|
||||||
Ok(mut file) => {
|
Ok(mut file) => {
|
||||||
|
tracing::info!("reading file: {}", &line);
|
||||||
|
|
||||||
// read file into String buffer
|
// read file into String buffer
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
file.read_to_string(&mut buf).await?;
|
file.read_to_string(&mut buf).await?;
|
||||||
@@ -52,7 +54,7 @@ async fn run() -> io::Result<()> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::error!("{}", err);
|
tracing::error!("{}", err);
|
||||||
framed
|
framed
|
||||||
.send("File not found or not readable. Try again.")
|
.send("File not found or not readable. Try again.")
|
||||||
.await?;
|
.await?;
|
||||||
@@ -72,7 +74,7 @@ async fn run() -> io::Result<()> {
|
|||||||
// close connection after file has been copied to TCP stream
|
// close connection after file has been copied to TCP stream
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.map_err(|err| log::error!("Service Error: {:?}", err))
|
.map_err(|err| tracing::error!("Service Error: {:?}", err))
|
||||||
})?
|
})?
|
||||||
.workers(2)
|
.workers(2)
|
||||||
.run()
|
.run()
|
||||||
|
@@ -22,7 +22,6 @@ use actix_server::Server;
|
|||||||
use actix_service::{fn_service, ServiceFactoryExt as _};
|
use actix_service::{fn_service, ServiceFactoryExt as _};
|
||||||
use bytes::BytesMut;
|
use bytes::BytesMut;
|
||||||
use futures_util::future::ok;
|
use futures_util::future::ok;
|
||||||
use log::{error, info};
|
|
||||||
use tokio::io::{AsyncReadExt as _, AsyncWriteExt as _};
|
use tokio::io::{AsyncReadExt as _, AsyncWriteExt as _};
|
||||||
|
|
||||||
async fn run() -> io::Result<()> {
|
async fn run() -> io::Result<()> {
|
||||||
@@ -31,7 +30,7 @@ async fn run() -> io::Result<()> {
|
|||||||
let count = Arc::new(AtomicUsize::new(0));
|
let count = Arc::new(AtomicUsize::new(0));
|
||||||
|
|
||||||
let addr = ("127.0.0.1", 8080);
|
let addr = ("127.0.0.1", 8080);
|
||||||
info!("starting server on port: {}", &addr.0);
|
tracing::info!("starting server on port: {}", &addr.0);
|
||||||
|
|
||||||
// Bind socket address and start worker(s). By default, the server uses the number of physical
|
// Bind socket address and start worker(s). By default, the server uses the number of physical
|
||||||
// CPU cores as the worker count. For this reason, the closure passed to bind needs to return
|
// CPU cores as the worker count. For this reason, the closure passed to bind needs to return
|
||||||
@@ -58,14 +57,14 @@ async fn run() -> io::Result<()> {
|
|||||||
|
|
||||||
// more bytes to process
|
// more bytes to process
|
||||||
Ok(bytes_read) => {
|
Ok(bytes_read) => {
|
||||||
info!("[{}] read {} bytes", num, bytes_read);
|
tracing::info!("[{}] read {} bytes", num, bytes_read);
|
||||||
stream.write_all(&buf[size..]).await.unwrap();
|
stream.write_all(&buf[size..]).await.unwrap();
|
||||||
size += bytes_read;
|
size += bytes_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
// stream error; bail from loop with error
|
// stream error; bail from loop with error
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("Stream Error: {:?}", err);
|
tracing::error!("Stream Error: {:?}", err);
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,10 +74,10 @@ async fn run() -> io::Result<()> {
|
|||||||
Ok((buf.freeze(), size))
|
Ok((buf.freeze(), size))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.map_err(|err| error!("Service Error: {:?}", err))
|
.map_err(|err| tracing::error!("Service Error: {:?}", err))
|
||||||
.and_then(move |(_, size)| {
|
.and_then(move |(_, size)| {
|
||||||
let num = num2.load(Ordering::SeqCst);
|
let num = num2.load(Ordering::SeqCst);
|
||||||
info!("[{}] total bytes read: {}", num, size);
|
tracing::info!("[{}] total bytes read: {}", num, size);
|
||||||
ok(size)
|
ok(size)
|
||||||
})
|
})
|
||||||
})?
|
})?
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
use std::{io, thread, time::Duration};
|
use std::{io, thread, time::Duration};
|
||||||
|
|
||||||
use actix_rt::time::Instant;
|
use actix_rt::time::Instant;
|
||||||
use log::{debug, error, info};
|
|
||||||
use mio::{Interest, Poll, Token as MioToken};
|
use mio::{Interest, Poll, Token as MioToken};
|
||||||
|
use tracing::{debug, error, info};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
availability::Availability,
|
availability::Availability,
|
||||||
@@ -41,7 +41,7 @@ impl Accept {
|
|||||||
pub(crate) fn start(
|
pub(crate) fn start(
|
||||||
sockets: Vec<(usize, MioListener)>,
|
sockets: Vec<(usize, MioListener)>,
|
||||||
builder: &ServerBuilder,
|
builder: &ServerBuilder,
|
||||||
) -> io::Result<(WakerQueue, Vec<WorkerHandleServer>)> {
|
) -> io::Result<(WakerQueue, Vec<WorkerHandleServer>, thread::JoinHandle<()>)> {
|
||||||
let handle_server = ServerHandle::new(builder.cmd_tx.clone());
|
let handle_server = ServerHandle::new(builder.cmd_tx.clone());
|
||||||
|
|
||||||
// construct poll instance and its waker
|
// construct poll instance and its waker
|
||||||
@@ -73,12 +73,12 @@ impl Accept {
|
|||||||
handle_server,
|
handle_server,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
thread::Builder::new()
|
let accept_handle = thread::Builder::new()
|
||||||
.name("actix-server acceptor".to_owned())
|
.name("actix-server acceptor".to_owned())
|
||||||
.spawn(move || accept.poll_with(&mut sockets))
|
.spawn(move || accept.poll_with(&mut sockets))
|
||||||
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?;
|
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?;
|
||||||
|
|
||||||
Ok((waker_queue, handles_server))
|
Ok((waker_queue, handles_server, accept_handle))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_with_sockets(
|
fn new_with_sockets(
|
||||||
@@ -127,10 +127,10 @@ impl Accept {
|
|||||||
let mut events = mio::Events::with_capacity(256);
|
let mut events = mio::Events::with_capacity(256);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if let Err(e) = self.poll.poll(&mut events, self.timeout) {
|
if let Err(err) = self.poll.poll(&mut events, self.timeout) {
|
||||||
match e.kind() {
|
match err.kind() {
|
||||||
io::ErrorKind::Interrupted => {}
|
io::ErrorKind::Interrupted => {}
|
||||||
_ => panic!("Poll error: {}", e),
|
_ => panic!("Poll error: {}", err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,15 +298,15 @@ impl Accept {
|
|||||||
fn register_logged(&self, info: &mut ServerSocketInfo) {
|
fn register_logged(&self, info: &mut ServerSocketInfo) {
|
||||||
match self.register(info) {
|
match self.register(info) {
|
||||||
Ok(_) => debug!("Resume accepting connections on {}", info.lst.local_addr()),
|
Ok(_) => debug!("Resume accepting connections on {}", info.lst.local_addr()),
|
||||||
Err(e) => error!("Can not register server socket {}", e),
|
Err(err) => error!("Can not register server socket {}", err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deregister_logged(&self, info: &mut ServerSocketInfo) {
|
fn deregister_logged(&self, info: &mut ServerSocketInfo) {
|
||||||
match self.poll.registry().deregister(&mut info.lst) {
|
match self.poll.registry().deregister(&mut info.lst) {
|
||||||
Ok(_) => debug!("Paused accepting connections on {}", info.lst.local_addr()),
|
Ok(_) => debug!("Paused accepting connections on {}", info.lst.local_addr()),
|
||||||
Err(e) => {
|
Err(err) => {
|
||||||
error!("Can not deregister server socket {}", e)
|
error!("Can not deregister server socket {}", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -396,10 +396,10 @@ impl Accept {
|
|||||||
let conn = Conn { io, token };
|
let conn = Conn { io, token };
|
||||||
self.accept_one(conn);
|
self.accept_one(conn);
|
||||||
}
|
}
|
||||||
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => return,
|
Err(ref err) if err.kind() == io::ErrorKind::WouldBlock => return,
|
||||||
Err(ref e) if connection_error(e) => continue,
|
Err(ref err) if connection_error(err) => continue,
|
||||||
Err(e) => {
|
Err(err) => {
|
||||||
error!("Error accepting connection: {}", e);
|
error!("Error accepting connection: {}", err);
|
||||||
|
|
||||||
// deregister listener temporary
|
// deregister listener temporary
|
||||||
self.deregister_logged(info);
|
self.deregister_logged(info);
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
use std::{io, time::Duration};
|
use std::{io, time::Duration};
|
||||||
|
|
||||||
use actix_rt::net::TcpStream;
|
use actix_rt::net::TcpStream;
|
||||||
use log::{info, trace};
|
|
||||||
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
|
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
|
||||||
|
use tracing::{info, trace};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
server::ServerCommand,
|
server::ServerCommand,
|
||||||
@@ -220,10 +220,10 @@ impl ServerBuilder {
|
|||||||
{
|
{
|
||||||
// The path must not exist when we try to bind.
|
// The path must not exist when we try to bind.
|
||||||
// Try to remove it to avoid bind error.
|
// Try to remove it to avoid bind error.
|
||||||
if let Err(e) = std::fs::remove_file(addr.as_ref()) {
|
if let Err(err) = std::fs::remove_file(addr.as_ref()) {
|
||||||
// NotFound is expected and not an issue. Anything else is.
|
// NotFound is expected and not an issue. Anything else is.
|
||||||
if e.kind() != std::io::ErrorKind::NotFound {
|
if err.kind() != std::io::ErrorKind::NotFound {
|
||||||
return Err(e);
|
return Err(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,22 +264,23 @@ pub(super) fn bind_addr<S: ToSocketAddrs>(
|
|||||||
addr: S,
|
addr: S,
|
||||||
backlog: u32,
|
backlog: u32,
|
||||||
) -> io::Result<Vec<MioTcpListener>> {
|
) -> io::Result<Vec<MioTcpListener>> {
|
||||||
let mut err = None;
|
let mut opt_err = None;
|
||||||
let mut success = false;
|
let mut success = false;
|
||||||
let mut sockets = Vec::new();
|
let mut sockets = Vec::new();
|
||||||
|
|
||||||
for addr in addr.to_socket_addrs()? {
|
for addr in addr.to_socket_addrs()? {
|
||||||
match create_mio_tcp_listener(addr, backlog) {
|
match create_mio_tcp_listener(addr, backlog) {
|
||||||
Ok(lst) => {
|
Ok(lst) => {
|
||||||
success = true;
|
success = true;
|
||||||
sockets.push(lst);
|
sockets.push(lst);
|
||||||
}
|
}
|
||||||
Err(e) => err = Some(e),
|
Err(err) => opt_err = Some(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if success {
|
if success {
|
||||||
Ok(sockets)
|
Ok(sockets)
|
||||||
} else if let Some(err) = err.take() {
|
} else if let Some(err) = opt_err.take() {
|
||||||
Err(err)
|
Err(err)
|
||||||
} else {
|
} else {
|
||||||
Err(io::Error::new(
|
Err(io::Error::new(
|
||||||
|
@@ -3,14 +3,15 @@ use std::{
|
|||||||
io, mem,
|
io, mem,
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
|
thread,
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
use actix_rt::{time::sleep, System};
|
use actix_rt::{time::sleep, System};
|
||||||
use futures_core::{future::BoxFuture, Stream};
|
use futures_core::{future::BoxFuture, Stream};
|
||||||
use futures_util::stream::StreamExt as _;
|
use futures_util::stream::StreamExt as _;
|
||||||
use log::{error, info};
|
|
||||||
use tokio::sync::{mpsc::UnboundedReceiver, oneshot};
|
use tokio::sync::{mpsc::UnboundedReceiver, oneshot};
|
||||||
|
use tracing::{error, info};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
accept::Accept,
|
accept::Accept,
|
||||||
@@ -158,6 +159,7 @@ impl Future for Server {
|
|||||||
|
|
||||||
pub struct ServerInner {
|
pub struct ServerInner {
|
||||||
worker_handles: Vec<WorkerHandleServer>,
|
worker_handles: Vec<WorkerHandleServer>,
|
||||||
|
accept_handle: Option<thread::JoinHandle<()>>,
|
||||||
worker_config: ServerWorkerConfig,
|
worker_config: ServerWorkerConfig,
|
||||||
services: Vec<Box<dyn InternalServiceFactory>>,
|
services: Vec<Box<dyn InternalServiceFactory>>,
|
||||||
waker_queue: WakerQueue,
|
waker_queue: WakerQueue,
|
||||||
@@ -205,7 +207,7 @@ impl ServerInner {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let (waker_queue, worker_handles) = Accept::start(sockets, &builder)?;
|
let (waker_queue, worker_handles, accept_handle) = Accept::start(sockets, &builder)?;
|
||||||
|
|
||||||
let mux = ServerEventMultiplexer {
|
let mux = ServerEventMultiplexer {
|
||||||
signal_fut: (builder.listen_os_signals).then(Signals::new),
|
signal_fut: (builder.listen_os_signals).then(Signals::new),
|
||||||
@@ -214,6 +216,7 @@ impl ServerInner {
|
|||||||
|
|
||||||
let server = ServerInner {
|
let server = ServerInner {
|
||||||
waker_queue,
|
waker_queue,
|
||||||
|
accept_handle: Some(accept_handle),
|
||||||
worker_handles,
|
worker_handles,
|
||||||
worker_config: builder.worker_config,
|
worker_config: builder.worker_config,
|
||||||
services: builder.factories,
|
services: builder.factories,
|
||||||
@@ -243,7 +246,8 @@ impl ServerInner {
|
|||||||
} => {
|
} => {
|
||||||
self.stopping = true;
|
self.stopping = true;
|
||||||
|
|
||||||
// stop accept thread
|
// Signal accept thread to stop.
|
||||||
|
// Signal is non-blocking; we wait for thread to stop later.
|
||||||
self.waker_queue.wake(WakerInterest::Stop);
|
self.waker_queue.wake(WakerInterest::Stop);
|
||||||
|
|
||||||
// send stop signal to workers
|
// send stop signal to workers
|
||||||
@@ -258,6 +262,13 @@ impl ServerInner {
|
|||||||
let _ = join_all(workers_stop).await;
|
let _ = join_all(workers_stop).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// wait for accept thread stop
|
||||||
|
self.accept_handle
|
||||||
|
.take()
|
||||||
|
.unwrap()
|
||||||
|
.join()
|
||||||
|
.expect("Accept thread must not panic in any case");
|
||||||
|
|
||||||
if let Some(tx) = completion {
|
if let Some(tx) = completion {
|
||||||
let _ = tx.send(());
|
let _ = tx.send(());
|
||||||
}
|
}
|
||||||
|
@@ -7,7 +7,7 @@ use std::{
|
|||||||
use actix_service::{Service, ServiceFactory as BaseServiceFactory};
|
use actix_service::{Service, ServiceFactory as BaseServiceFactory};
|
||||||
use actix_utils::future::{ready, Ready};
|
use actix_utils::future::{ready, Ready};
|
||||||
use futures_core::future::LocalBoxFuture;
|
use futures_core::future::LocalBoxFuture;
|
||||||
use log::error;
|
use tracing::error;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
socket::{FromStream, MioStream},
|
socket::{FromStream, MioStream},
|
||||||
@@ -77,8 +77,8 @@ where
|
|||||||
});
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(err) => {
|
||||||
error!("Can not convert to an async tcp stream: {}", e);
|
error!("Can not convert to an async tcp stream: {}", err);
|
||||||
Err(())
|
Err(())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@@ -5,7 +5,7 @@ use std::{
|
|||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
};
|
};
|
||||||
|
|
||||||
use log::trace;
|
use tracing::trace;
|
||||||
|
|
||||||
/// Types of process signals.
|
/// Types of process signals.
|
||||||
// #[allow(dead_code)]
|
// #[allow(dead_code)]
|
||||||
@@ -69,7 +69,7 @@ impl Signals {
|
|||||||
unix::signal(*kind)
|
unix::signal(*kind)
|
||||||
.map(|tokio_sig| (*sig, tokio_sig))
|
.map(|tokio_sig| (*sig, tokio_sig))
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
log::error!(
|
tracing::error!(
|
||||||
"Can not initialize stream handler for {:?} err: {}",
|
"Can not initialize stream handler for {:?} err: {}",
|
||||||
sig,
|
sig,
|
||||||
e
|
e
|
||||||
|
@@ -17,11 +17,11 @@ use actix_rt::{
|
|||||||
Arbiter, ArbiterHandle, System,
|
Arbiter, ArbiterHandle, System,
|
||||||
};
|
};
|
||||||
use futures_core::{future::LocalBoxFuture, ready};
|
use futures_core::{future::LocalBoxFuture, ready};
|
||||||
use log::{error, info, trace};
|
|
||||||
use tokio::sync::{
|
use tokio::sync::{
|
||||||
mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender},
|
mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender},
|
||||||
oneshot,
|
oneshot,
|
||||||
};
|
};
|
||||||
|
use tracing::{error, info, trace};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
service::{BoxedServerService, InternalServiceFactory},
|
service::{BoxedServerService, InternalServiceFactory},
|
||||||
|
@@ -254,6 +254,7 @@ async fn test_max_concurrent_connections() {
|
|||||||
h.join().unwrap().unwrap();
|
h.join().unwrap().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: race-y failures detected due to integer underflow when calling Counter::total
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_service_restart() {
|
async fn test_service_restart() {
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## Unreleased - 2021-xx-xx
|
## Unreleased - 2022-xx-xx
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.49.
|
||||||
|
|
||||||
|
|
||||||
## 2.0.2 - 2021-12-18
|
## 2.0.2 - 2021-12-18
|
||||||
|
@@ -97,7 +97,7 @@ where
|
|||||||
|
|
||||||
match this.fut.poll(cx) {
|
match this.fut.poll(cx) {
|
||||||
Poll::Ready(Ok(resp)) => Poll::Ready(Ok((this.f)(resp))),
|
Poll::Ready(Ok(resp)) => Poll::Ready(Ok((this.f)(resp))),
|
||||||
Poll::Ready(Err(e)) => Poll::Ready(Err(e)),
|
Poll::Ready(Err(err)) => Poll::Ready(Err(err)),
|
||||||
Poll::Pending => Poll::Pending,
|
Poll::Pending => Poll::Pending,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,22 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## Unreleased - 2021-xx-xx
|
## Unreleased - 2022-xx-xx
|
||||||
|
|
||||||
|
|
||||||
|
## 3.0.4 - 2022-03-15
|
||||||
|
- Logs emitted now use the `tracing` crate with `log` compatibility. [#451]
|
||||||
|
|
||||||
|
[#451]: https://github.com/actix/actix-net/pull/451
|
||||||
|
|
||||||
|
|
||||||
|
## 3.0.3 - 2022-02-15
|
||||||
|
- No significant changes since `3.0.2`.
|
||||||
|
|
||||||
|
|
||||||
|
## 3.0.2 - 2022-01-28
|
||||||
|
- Expose `connect::Connection::new`. [#439]
|
||||||
|
|
||||||
|
[#439]: https://github.com/actix/actix-net/pull/439
|
||||||
|
|
||||||
|
|
||||||
## 3.0.1 - 2022-01-11
|
## 3.0.1 - 2022-01-11
|
||||||
@@ -16,6 +32,7 @@
|
|||||||
|
|
||||||
[#429]: https://github.com/actix/actix-net/pull/429
|
[#429]: https://github.com/actix/actix-net/pull/429
|
||||||
|
|
||||||
|
|
||||||
## 3.0.0-rc.1 - 2021-11-29
|
## 3.0.0-rc.1 - 2021-11-29
|
||||||
### Added
|
### Added
|
||||||
- Derive `Debug` for `connect::Connection`. [#422]
|
- Derive `Debug` for `connect::Connection`. [#422]
|
||||||
@@ -121,7 +138,7 @@
|
|||||||
[#273]: https://github.com/actix/actix-net/pull/273
|
[#273]: https://github.com/actix/actix-net/pull/273
|
||||||
|
|
||||||
|
|
||||||
## 3.0.0-beta.2 - 2021-xx-xx
|
## 3.0.0-beta.2 - 2022-xx-xx
|
||||||
- Depend on stable trust-dns packages. [#204]
|
- Depend on stable trust-dns packages. [#204]
|
||||||
|
|
||||||
[#204]: https://github.com/actix/actix-net/pull/204
|
[#204]: https://github.com/actix/actix-net/pull/204
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-tls"
|
name = "actix-tls"
|
||||||
version = "3.0.1"
|
version = "3.0.4"
|
||||||
authors = [
|
authors = [
|
||||||
"Nikolay Kim <fafhrd91@gmail.com>",
|
"Nikolay Kim <fafhrd91@gmail.com>",
|
||||||
"Rob Ede <robjtede@icloud.com>",
|
"Rob Ede <robjtede@icloud.com>",
|
||||||
@@ -42,16 +42,15 @@ native-tls = ["tokio-native-tls"]
|
|||||||
uri = ["http"]
|
uri = ["http"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-codec = "0.4.2"
|
actix-codec = "0.5.0"
|
||||||
actix-rt = { version = "2.2.0", default-features = false }
|
actix-rt = { version = "2.2.0", default-features = false }
|
||||||
actix-service = "2.0.0"
|
actix-service = "2.0.0"
|
||||||
actix-utils = "3.0.0"
|
actix-utils = "3.0.0"
|
||||||
|
|
||||||
derive_more = "0.99.5"
|
|
||||||
futures-core = { version = "0.3.7", default-features = false, features = ["alloc"] }
|
futures-core = { version = "0.3.7", default-features = false, features = ["alloc"] }
|
||||||
log = "0.4"
|
|
||||||
pin-project-lite = "0.2.7"
|
pin-project-lite = "0.2.7"
|
||||||
tokio-util = { version = "0.6.3", default-features = false }
|
tokio-util = "0.7"
|
||||||
|
tracing = { version = "0.1.30", default-features = false, features = ["log"] }
|
||||||
|
|
||||||
# uri
|
# uri
|
||||||
http = { version = "0.2.3", optional = true }
|
http = { version = "0.2.3", optional = true }
|
||||||
@@ -69,7 +68,7 @@ tokio-native-tls = { version = "0.3", optional = true }
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix-rt = "2.2.0"
|
actix-rt = "2.2.0"
|
||||||
actix-server = "2.0.0-rc.4"
|
actix-server = "2.0.0"
|
||||||
bytes = "1"
|
bytes = "1"
|
||||||
env_logger = "0.9"
|
env_logger = "0.9"
|
||||||
futures-util = { version = "0.3.7", default-features = false, features = ["sink"] }
|
futures-util = { version = "0.3.7", default-features = false, features = ["sink"] }
|
||||||
|
@@ -34,9 +34,9 @@ use actix_server::Server;
|
|||||||
use actix_service::ServiceFactoryExt as _;
|
use actix_service::ServiceFactoryExt as _;
|
||||||
use actix_tls::accept::rustls::{Acceptor as RustlsAcceptor, TlsStream};
|
use actix_tls::accept::rustls::{Acceptor as RustlsAcceptor, TlsStream};
|
||||||
use futures_util::future::ok;
|
use futures_util::future::ok;
|
||||||
use log::info;
|
|
||||||
use rustls::{server::ServerConfig, Certificate, PrivateKey};
|
use rustls::{server::ServerConfig, Certificate, PrivateKey};
|
||||||
use rustls_pemfile::{certs, rsa_private_keys};
|
use rustls_pemfile::{certs, rsa_private_keys};
|
||||||
|
use tracing::info;
|
||||||
|
|
||||||
#[actix_rt::main]
|
#[actix_rt::main]
|
||||||
async fn main() -> io::Result<()> {
|
async fn main() -> io::Result<()> {
|
||||||
|
@@ -2,11 +2,12 @@
|
|||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
convert::Infallible,
|
convert::Infallible,
|
||||||
|
error::Error,
|
||||||
|
fmt,
|
||||||
sync::atomic::{AtomicUsize, Ordering},
|
sync::atomic::{AtomicUsize, Ordering},
|
||||||
};
|
};
|
||||||
|
|
||||||
use actix_utils::counter::Counter;
|
use actix_utils::counter::Counter;
|
||||||
use derive_more::{Display, Error};
|
|
||||||
|
|
||||||
#[cfg(feature = "openssl")]
|
#[cfg(feature = "openssl")]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "openssl")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "openssl")))]
|
||||||
@@ -43,23 +44,45 @@ pub fn max_concurrent_tls_connect(num: usize) {
|
|||||||
/// TLS handshake error, TLS timeout, or inner service error.
|
/// TLS handshake error, TLS timeout, or inner service error.
|
||||||
///
|
///
|
||||||
/// All TLS acceptors from this crate will return the `SvcErr` type parameter as [`Infallible`],
|
/// All TLS acceptors from this crate will return the `SvcErr` type parameter as [`Infallible`],
|
||||||
/// which can be cast to your own service type, inferred or otherwise,
|
/// which can be cast to your own service type, inferred or otherwise, using [`into_service_error`].
|
||||||
/// using [`into_service_error`](Self::into_service_error).
|
///
|
||||||
#[derive(Debug, Display, Error)]
|
/// [`into_service_error`]: Self::into_service_error
|
||||||
|
#[derive(Debug)]
|
||||||
pub enum TlsError<TlsErr, SvcErr> {
|
pub enum TlsError<TlsErr, SvcErr> {
|
||||||
/// TLS handshake has timed-out.
|
/// TLS handshake has timed-out.
|
||||||
#[display(fmt = "TLS handshake has timed-out")]
|
|
||||||
Timeout,
|
Timeout,
|
||||||
|
|
||||||
/// Wraps TLS service errors.
|
/// Wraps TLS service errors.
|
||||||
#[display(fmt = "TLS handshake error")]
|
|
||||||
Tls(TlsErr),
|
Tls(TlsErr),
|
||||||
|
|
||||||
/// Wraps service errors.
|
/// Wraps service errors.
|
||||||
#[display(fmt = "Service error")]
|
|
||||||
Service(SvcErr),
|
Service(SvcErr),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<TlsErr, SvcErr> fmt::Display for TlsError<TlsErr, SvcErr> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::Timeout => f.write_str("TLS handshake has timed-out"),
|
||||||
|
Self::Tls(_) => f.write_str("TLS handshake error"),
|
||||||
|
Self::Service(_) => f.write_str("Service error"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<TlsErr, SvcErr> Error for TlsError<TlsErr, SvcErr>
|
||||||
|
where
|
||||||
|
TlsErr: Error + 'static,
|
||||||
|
SvcErr: Error + 'static,
|
||||||
|
{
|
||||||
|
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
||||||
|
match self {
|
||||||
|
TlsError::Tls(err) => Some(err),
|
||||||
|
TlsError::Service(err) => Some(err),
|
||||||
|
TlsError::Timeout => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<TlsErr> TlsError<TlsErr, Infallible> {
|
impl<TlsErr> TlsError<TlsErr, Infallible> {
|
||||||
/// Casts the infallible service error type returned from acceptors into caller's type.
|
/// Casts the infallible service error type returned from acceptors into caller's type.
|
||||||
///
|
///
|
||||||
|
@@ -20,11 +20,11 @@ use actix_utils::{
|
|||||||
counter::Counter,
|
counter::Counter,
|
||||||
future::{ready, Ready as FutReady},
|
future::{ready, Ready as FutReady},
|
||||||
};
|
};
|
||||||
use derive_more::{Deref, DerefMut, From};
|
|
||||||
use futures_core::future::LocalBoxFuture;
|
use futures_core::future::LocalBoxFuture;
|
||||||
use tokio_native_tls::{native_tls::Error, TlsAcceptor};
|
use tokio_native_tls::{native_tls::Error, TlsAcceptor};
|
||||||
|
|
||||||
use super::{TlsError, DEFAULT_TLS_HANDSHAKE_TIMEOUT, MAX_CONN_COUNTER};
|
use super::{TlsError, DEFAULT_TLS_HANDSHAKE_TIMEOUT, MAX_CONN_COUNTER};
|
||||||
|
use crate::impl_more;
|
||||||
|
|
||||||
pub mod reexports {
|
pub mod reexports {
|
||||||
//! Re-exports from `native-tls` that are useful for acceptors.
|
//! Re-exports from `native-tls` that are useful for acceptors.
|
||||||
@@ -33,9 +33,12 @@ pub mod reexports {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Wraps a `native-tls` based async TLS stream in order to implement [`ActixStream`].
|
/// Wraps a `native-tls` based async TLS stream in order to implement [`ActixStream`].
|
||||||
#[derive(Deref, DerefMut, From)]
|
|
||||||
pub struct TlsStream<IO>(tokio_native_tls::TlsStream<IO>);
|
pub struct TlsStream<IO>(tokio_native_tls::TlsStream<IO>);
|
||||||
|
|
||||||
|
impl_more::from! { tokio_native_tls::TlsStream<IO> => TlsStream<IO> }
|
||||||
|
impl_more::deref! { TlsStream<IO> => 0: tokio_native_tls::TlsStream<IO> }
|
||||||
|
impl_more::deref_mut! { TlsStream<IO> => 0 }
|
||||||
|
|
||||||
impl<IO: ActixStream> AsyncRead for TlsStream<IO> {
|
impl<IO: ActixStream> AsyncRead for TlsStream<IO> {
|
||||||
fn poll_read(
|
fn poll_read(
|
||||||
self: Pin<&mut Self>,
|
self: Pin<&mut Self>,
|
||||||
|
@@ -21,11 +21,11 @@ use actix_utils::{
|
|||||||
counter::{Counter, CounterGuard},
|
counter::{Counter, CounterGuard},
|
||||||
future::{ready, Ready as FutReady},
|
future::{ready, Ready as FutReady},
|
||||||
};
|
};
|
||||||
use derive_more::{Deref, DerefMut, From};
|
|
||||||
use openssl::ssl::{Error, Ssl, SslAcceptor};
|
use openssl::ssl::{Error, Ssl, SslAcceptor};
|
||||||
use pin_project_lite::pin_project;
|
use pin_project_lite::pin_project;
|
||||||
|
|
||||||
use super::{TlsError, DEFAULT_TLS_HANDSHAKE_TIMEOUT, MAX_CONN_COUNTER};
|
use super::{TlsError, DEFAULT_TLS_HANDSHAKE_TIMEOUT, MAX_CONN_COUNTER};
|
||||||
|
use crate::impl_more;
|
||||||
|
|
||||||
pub mod reexports {
|
pub mod reexports {
|
||||||
//! Re-exports from `openssl` that are useful for acceptors.
|
//! Re-exports from `openssl` that are useful for acceptors.
|
||||||
@@ -36,9 +36,12 @@ pub mod reexports {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Wraps an `openssl` based async TLS stream in order to implement [`ActixStream`].
|
/// Wraps an `openssl` based async TLS stream in order to implement [`ActixStream`].
|
||||||
#[derive(Deref, DerefMut, From)]
|
|
||||||
pub struct TlsStream<IO>(tokio_openssl::SslStream<IO>);
|
pub struct TlsStream<IO>(tokio_openssl::SslStream<IO>);
|
||||||
|
|
||||||
|
impl_more::from! { tokio_openssl::SslStream<IO> => TlsStream<IO> }
|
||||||
|
impl_more::deref! { TlsStream<IO> => 0: tokio_openssl::SslStream<IO> }
|
||||||
|
impl_more::deref_mut! { TlsStream<IO> => 0 }
|
||||||
|
|
||||||
impl<IO: ActixStream> AsyncRead for TlsStream<IO> {
|
impl<IO: ActixStream> AsyncRead for TlsStream<IO> {
|
||||||
fn poll_read(
|
fn poll_read(
|
||||||
self: Pin<&mut Self>,
|
self: Pin<&mut Self>,
|
||||||
|
@@ -22,12 +22,12 @@ use actix_utils::{
|
|||||||
counter::{Counter, CounterGuard},
|
counter::{Counter, CounterGuard},
|
||||||
future::{ready, Ready as FutReady},
|
future::{ready, Ready as FutReady},
|
||||||
};
|
};
|
||||||
use derive_more::{Deref, DerefMut, From};
|
|
||||||
use pin_project_lite::pin_project;
|
use pin_project_lite::pin_project;
|
||||||
use tokio_rustls::rustls::ServerConfig;
|
use tokio_rustls::rustls::ServerConfig;
|
||||||
use tokio_rustls::{Accept, TlsAcceptor};
|
use tokio_rustls::{Accept, TlsAcceptor};
|
||||||
|
|
||||||
use super::{TlsError, DEFAULT_TLS_HANDSHAKE_TIMEOUT, MAX_CONN_COUNTER};
|
use super::{TlsError, DEFAULT_TLS_HANDSHAKE_TIMEOUT, MAX_CONN_COUNTER};
|
||||||
|
use crate::impl_more;
|
||||||
|
|
||||||
pub mod reexports {
|
pub mod reexports {
|
||||||
//! Re-exports from `rustls` that are useful for acceptors.
|
//! Re-exports from `rustls` that are useful for acceptors.
|
||||||
@@ -36,9 +36,12 @@ pub mod reexports {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Wraps a `rustls` based async TLS stream in order to implement [`ActixStream`].
|
/// Wraps a `rustls` based async TLS stream in order to implement [`ActixStream`].
|
||||||
#[derive(Deref, DerefMut, From)]
|
|
||||||
pub struct TlsStream<IO>(tokio_rustls::server::TlsStream<IO>);
|
pub struct TlsStream<IO>(tokio_rustls::server::TlsStream<IO>);
|
||||||
|
|
||||||
|
impl_more::from! { tokio_rustls::server::TlsStream<IO> => TlsStream<IO> }
|
||||||
|
impl_more::deref! { TlsStream<IO> => 0: tokio_rustls::server::TlsStream<IO> }
|
||||||
|
impl_more::deref_mut! { TlsStream<IO> => 0 }
|
||||||
|
|
||||||
impl<IO: ActixStream> AsyncRead for TlsStream<IO> {
|
impl<IO: ActixStream> AsyncRead for TlsStream<IO> {
|
||||||
fn poll_read(
|
fn poll_read(
|
||||||
self: Pin<&mut Self>,
|
self: Pin<&mut Self>,
|
||||||
|
@@ -1,20 +1,19 @@
|
|||||||
use derive_more::{Deref, DerefMut};
|
|
||||||
|
|
||||||
use super::Host;
|
use super::Host;
|
||||||
|
use crate::impl_more;
|
||||||
|
|
||||||
/// Wraps underlying I/O and the connection request that initiated it.
|
/// Wraps underlying I/O and the connection request that initiated it.
|
||||||
#[derive(Debug, Deref, DerefMut)]
|
#[derive(Debug)]
|
||||||
pub struct Connection<R, IO> {
|
pub struct Connection<R, IO> {
|
||||||
pub(crate) req: R,
|
pub(crate) req: R,
|
||||||
|
|
||||||
#[deref]
|
|
||||||
#[deref_mut]
|
|
||||||
pub(crate) io: IO,
|
pub(crate) io: IO,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl_more::deref! { Connection<R, IO> => io: IO }
|
||||||
|
impl_more::deref_mut! { Connection<R, IO> => io }
|
||||||
|
|
||||||
impl<R, IO> Connection<R, IO> {
|
impl<R, IO> Connection<R, IO> {
|
||||||
/// Construct new `Connection` from request and IO parts.
|
/// Construct new `Connection` from request and IO parts.
|
||||||
pub(crate) fn new(req: R, io: IO) -> Self {
|
pub fn new(req: R, io: IO) -> Self {
|
||||||
Self { req, io }
|
Self { req, io }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,30 +1,38 @@
|
|||||||
use std::{error::Error, io};
|
use std::{error::Error, fmt, io};
|
||||||
|
|
||||||
use derive_more::Display;
|
|
||||||
|
|
||||||
/// Errors that can result from using a connector service.
|
/// Errors that can result from using a connector service.
|
||||||
#[derive(Debug, Display)]
|
#[derive(Debug)]
|
||||||
pub enum ConnectError {
|
pub enum ConnectError {
|
||||||
/// Failed to resolve the hostname
|
/// Failed to resolve the hostname.
|
||||||
#[display(fmt = "Failed resolving hostname")]
|
|
||||||
Resolver(Box<dyn std::error::Error>),
|
Resolver(Box<dyn std::error::Error>),
|
||||||
|
|
||||||
/// No DNS records
|
/// No DNS records.
|
||||||
#[display(fmt = "No DNS records found for the input")]
|
|
||||||
NoRecords,
|
NoRecords,
|
||||||
|
|
||||||
/// Invalid input
|
/// Invalid input.
|
||||||
InvalidInput,
|
InvalidInput,
|
||||||
|
|
||||||
/// Unresolved host name
|
/// Unresolved host name.
|
||||||
#[display(fmt = "Connector received `Connect` method with unresolved host")]
|
|
||||||
Unresolved,
|
Unresolved,
|
||||||
|
|
||||||
/// Connection IO error
|
/// Connection IO error.
|
||||||
#[display(fmt = "{}", _0)]
|
|
||||||
Io(io::Error),
|
Io(io::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for ConnectError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::NoRecords => f.write_str("No DNS records found for the input"),
|
||||||
|
Self::InvalidInput => f.write_str("Invalid input"),
|
||||||
|
Self::Unresolved => {
|
||||||
|
f.write_str("Connector received `Connect` method with unresolved host")
|
||||||
|
}
|
||||||
|
Self::Resolver(_) => f.write_str("Failed to resolve hostname"),
|
||||||
|
Self::Io(_) => f.write_str("I/O error"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Error for ConnectError {
|
impl Error for ConnectError {
|
||||||
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
||||||
match self {
|
match self {
|
||||||
|
@@ -8,11 +8,11 @@ use actix_rt::net::ActixStream;
|
|||||||
use actix_service::{Service, ServiceFactory};
|
use actix_service::{Service, ServiceFactory};
|
||||||
use actix_utils::future::{ok, Ready};
|
use actix_utils::future::{ok, Ready};
|
||||||
use futures_core::future::LocalBoxFuture;
|
use futures_core::future::LocalBoxFuture;
|
||||||
use log::trace;
|
|
||||||
use tokio_native_tls::{
|
use tokio_native_tls::{
|
||||||
native_tls::TlsConnector as NativeTlsConnector, TlsConnector as AsyncNativeTlsConnector,
|
native_tls::TlsConnector as NativeTlsConnector, TlsConnector as AsyncNativeTlsConnector,
|
||||||
TlsStream as AsyncTlsStream,
|
TlsStream as AsyncTlsStream,
|
||||||
};
|
};
|
||||||
|
use tracing::trace;
|
||||||
|
|
||||||
use crate::connect::{Connection, Host};
|
use crate::connect::{Connection, Host};
|
||||||
|
|
||||||
|
@@ -13,9 +13,9 @@ use actix_rt::net::ActixStream;
|
|||||||
use actix_service::{Service, ServiceFactory};
|
use actix_service::{Service, ServiceFactory};
|
||||||
use actix_utils::future::{ok, Ready};
|
use actix_utils::future::{ok, Ready};
|
||||||
use futures_core::ready;
|
use futures_core::ready;
|
||||||
use log::trace;
|
|
||||||
use openssl::ssl::SslConnector;
|
use openssl::ssl::SslConnector;
|
||||||
use tokio_openssl::SslStream as AsyncSslStream;
|
use tokio_openssl::SslStream as AsyncSslStream;
|
||||||
|
use tracing::trace;
|
||||||
|
|
||||||
use crate::connect::{Connection, Host};
|
use crate::connect::{Connection, Host};
|
||||||
|
|
||||||
@@ -141,9 +141,12 @@ where
|
|||||||
trace!("SSL Handshake success: {:?}", stream.hostname());
|
trace!("SSL Handshake success: {:?}", stream.hostname());
|
||||||
Poll::Ready(Ok(stream.replace_io(this.io.take().unwrap()).1))
|
Poll::Ready(Ok(stream.replace_io(this.io.take().unwrap()).1))
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(err) => {
|
||||||
trace!("SSL Handshake error: {:?}", e);
|
trace!("SSL Handshake error: {:?}", err);
|
||||||
Poll::Ready(Err(io::Error::new(io::ErrorKind::Other, format!("{}", e))))
|
Poll::Ready(Err(io::Error::new(
|
||||||
|
io::ErrorKind::Other,
|
||||||
|
format!("{}", err),
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,7 +12,7 @@ use actix_rt::task::{spawn_blocking, JoinHandle};
|
|||||||
use actix_service::{Service, ServiceFactory};
|
use actix_service::{Service, ServiceFactory};
|
||||||
use actix_utils::future::{ok, Ready};
|
use actix_utils::future::{ok, Ready};
|
||||||
use futures_core::{future::LocalBoxFuture, ready};
|
use futures_core::{future::LocalBoxFuture, ready};
|
||||||
use log::trace;
|
use tracing::trace;
|
||||||
|
|
||||||
use super::{ConnectError, ConnectInfo, Host, Resolve};
|
use super::{ConnectError, ConnectInfo, Host, Resolve};
|
||||||
|
|
||||||
@@ -164,8 +164,8 @@ impl<R: Host> Future for ResolverFut<R> {
|
|||||||
Self::LookUp(fut, req) => {
|
Self::LookUp(fut, req) => {
|
||||||
let res = match ready!(Pin::new(fut).poll(cx)) {
|
let res = match ready!(Pin::new(fut).poll(cx)) {
|
||||||
Ok(Ok(res)) => Ok(res),
|
Ok(Ok(res)) => Ok(res),
|
||||||
Ok(Err(e)) => Err(ConnectError::Resolver(Box::new(e))),
|
Ok(Err(err)) => Err(ConnectError::Resolver(Box::new(err))),
|
||||||
Err(e) => Err(ConnectError::Io(e.into())),
|
Err(err) => Err(ConnectError::Io(err.into())),
|
||||||
};
|
};
|
||||||
|
|
||||||
let req = req.take().unwrap();
|
let req = req.take().unwrap();
|
||||||
|
@@ -15,10 +15,10 @@ use actix_rt::net::ActixStream;
|
|||||||
use actix_service::{Service, ServiceFactory};
|
use actix_service::{Service, ServiceFactory};
|
||||||
use actix_utils::future::{ok, Ready};
|
use actix_utils::future::{ok, Ready};
|
||||||
use futures_core::ready;
|
use futures_core::ready;
|
||||||
use log::trace;
|
|
||||||
use tokio_rustls::rustls::{client::ServerName, OwnedTrustAnchor, RootCertStore};
|
use tokio_rustls::rustls::{client::ServerName, OwnedTrustAnchor, RootCertStore};
|
||||||
use tokio_rustls::{client::TlsStream as AsyncTlsStream, rustls::ClientConfig};
|
use tokio_rustls::{client::TlsStream as AsyncTlsStream, rustls::ClientConfig};
|
||||||
use tokio_rustls::{Connect as RustlsConnect, TlsConnector as RustlsTlsConnector};
|
use tokio_rustls::{Connect as RustlsConnect, TlsConnector as RustlsTlsConnector};
|
||||||
|
use tracing::trace;
|
||||||
use webpki_roots::TLS_SERVER_ROOTS;
|
use webpki_roots::TLS_SERVER_ROOTS;
|
||||||
|
|
||||||
use crate::connect::{Connection, Host};
|
use crate::connect::{Connection, Host};
|
||||||
|
@@ -15,8 +15,8 @@ use actix_rt::net::{TcpSocket, TcpStream};
|
|||||||
use actix_service::{Service, ServiceFactory};
|
use actix_service::{Service, ServiceFactory};
|
||||||
use actix_utils::future::{ok, Ready};
|
use actix_utils::future::{ok, Ready};
|
||||||
use futures_core::ready;
|
use futures_core::ready;
|
||||||
use log::{error, trace};
|
|
||||||
use tokio_util::sync::ReusableBoxFuture;
|
use tokio_util::sync::ReusableBoxFuture;
|
||||||
|
use tracing::{error, trace};
|
||||||
|
|
||||||
use super::{connect_addrs::ConnectAddrs, error::ConnectError, ConnectInfo, Connection, Host};
|
use super::{connect_addrs::ConnectAddrs, error::ConnectError, ConnectInfo, Connection, Host};
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ pub enum TcpConnectorFut<R> {
|
|||||||
port: u16,
|
port: u16,
|
||||||
local_addr: Option<IpAddr>,
|
local_addr: Option<IpAddr>,
|
||||||
addrs: Option<VecDeque<SocketAddr>>,
|
addrs: Option<VecDeque<SocketAddr>>,
|
||||||
stream: ReusableBoxFuture<Result<TcpStream, io::Error>>,
|
stream: ReusableBoxFuture<'static, Result<TcpStream, io::Error>>,
|
||||||
},
|
},
|
||||||
|
|
||||||
Error(Option<ConnectError>),
|
Error(Option<ConnectError>),
|
||||||
|
40
actix-tls/src/impl_more.rs
Normal file
40
actix-tls/src/impl_more.rs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/// A helper to implement `Deref` for a type.
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! deref {
|
||||||
|
($ty:ident $(<$($generic:ident),*>)? => $field:tt: $target:ty) => {
|
||||||
|
impl $(<$($generic),*>)? ::core::ops::Deref for $ty $(<$($generic),*>)? {
|
||||||
|
type Target = $target;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.$field
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A helper to implement `DerefMut` for a type.
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! deref_mut {
|
||||||
|
($ty:ident $(<$($generic:ident),*>)? => $field:tt) => {
|
||||||
|
impl $(<$($generic),*>)? ::core::ops::DerefMut for $ty $(<$($generic),*>)? {
|
||||||
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
|
&mut self.$field
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A helper to implement `From` for a unit struct.
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! from {
|
||||||
|
($from:ty => $ty:ident $(<$($generic:ident),*>)?) => {
|
||||||
|
impl $(<$($generic),*>)? ::core::convert::From<$from> for $ty $(<$($generic),*>)? {
|
||||||
|
fn from(from: $from) -> Self {
|
||||||
|
Self(from)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unused_imports)]
|
||||||
|
pub(crate) use crate::{deref, deref_mut, from};
|
@@ -18,3 +18,5 @@ pub mod accept;
|
|||||||
#[cfg(feature = "connect")]
|
#[cfg(feature = "connect")]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "connect")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "connect")))]
|
||||||
pub mod connect;
|
pub mod connect;
|
||||||
|
|
||||||
|
mod impl_more;
|
||||||
|
@@ -1,5 +1,8 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## [0.1.0] - 2020-01-15
|
## Unreleased - 2022-xx-xx
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.49.
|
||||||
|
|
||||||
|
|
||||||
|
## 0.1.0 - 2020-01-15
|
||||||
- Initial release
|
- Initial release
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## Unreleased - 2021-xx-xx
|
## Unreleased - 2022-xx-xx
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.49.
|
||||||
|
|
||||||
|
|
||||||
## 3.0.0 - 2021-04-16
|
## 3.0.0 - 2021-04-16
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## Unreleased - 2021-xx-xx
|
## Unreleased - 2022-xx-xx
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.49.
|
||||||
|
|
||||||
|
|
||||||
## 1.0.0 - 2020-12-31
|
## 1.0.0 - 2020-12-31
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## Unreleased - 2021-xx-xx
|
## Unreleased - 2022-xx-xx
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.49.
|
||||||
|
|
||||||
|
|
||||||
## 0.1.2 - 2021-04-01
|
## 0.1.2 - 2021-04-01
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## Unreleased - 2021-xx-xx
|
## Unreleased - 2022-xx-xx
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.49.
|
||||||
|
|
||||||
|
|
||||||
## 0.1.2 - 2021-12-18
|
## 0.1.2 - 2021-12-18
|
||||||
|
Reference in New Issue
Block a user