1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-08-12 12:17:08 +02:00

Compare commits

..

74 Commits

Author SHA1 Message Date
Rob Ede
d13461b337 use secure tokio version range
see RUSTSEC-2023-0001

part of actix/actix-web#2962
2023-01-10 08:56:41 +00:00
Juan Aguilar Santillana
dde38bbe06 remove unnecessary Pin in poll_recv calls (#475) 2023-01-02 13:36:46 +00:00
Rob Ede
d973d5974a fix msrv ci 2022-12-21 23:09:16 +00:00
Rob Ede
d7afd60606 workaround env-logger msrv 2022-12-21 21:17:21 +00:00
Rob Ede
7e47bf4055 prepare actix-server release 2.2.0 2022-12-21 20:37:51 +00:00
Rob Ede
05e7be337e prepare actix-rt release 2.8.0 2022-12-21 20:37:04 +00:00
Rob Ede
8d964713c9 fix futures-util version range 2022-12-21 20:36:26 +00:00
Riley
fe38312db0 asonix/tokio uring 04 (#473) 2022-12-21 11:45:31 +09:00
Yuki Okushi
2b83f08a40 Use old cargo-hack for 1.59.0 CI (#472)
* Use old cargo-hack for 1.57.0 CI

Signed-off-by: Yuki Okushi <jtitor@2k36.org>

* Upgrade MSRV to 1.59.0

Signed-off-by: Yuki Okushi <jtitor@2k36.org>

Signed-off-by: Yuki Okushi <jtitor@2k36.org>
Co-authored-by: Rob Ede <robjtede@icloud.com>
2022-11-12 14:00:33 +00:00
Rob Ede
8e9401f8e1 prepare bytestring release 1.2.1 2022-11-12 13:19:09 +00:00
VladimirBramstedt
9ede174e81 fix no_std compatibility (#471)
Co-authored-by: Yuki Okushi <jtitor@2k36.org>
2022-11-12 16:00:06 +09:00
Rob Ede
bb36e2a072 prepare bytestring release 1.2.0 2022-11-07 20:22:47 +00:00
Rob Ede
6061a44a22 slice_ref doc tweaks 2022-11-07 20:21:57 +00:00
Wang, Chi
363984ad75 Add ByteString::slice_ref (#470) 2022-11-07 20:16:46 +00:00
Rob Ede
00654aadc5 use direct tokio exports where possible 2022-10-30 20:25:13 +00:00
fakeshadow
428914e65e remove fakeshadow from author lists (#468) 2022-10-25 16:34:36 +01:00
Rob Ede
df9a9d1a1e don't install cargo-cache on 1.57 CI 2022-10-25 00:10:39 +01:00
Rob Ede
056d2cd573 workaround ci msrv issue 2022-10-24 23:44:29 +01:00
Rob Ede
68228a6cf2 update dev deps 2022-10-21 03:23:40 +01:00
Rob Ede
d5a9a6a1c5 prepare actix-utils release 3.0.1 2022-10-21 03:15:48 +01:00
Rob Ede
ade71b7bd3 address soundness footgun in poll_fn 2022-10-21 03:14:38 +01:00
Rob Ede
cb83922b29 add macos test note 2022-10-17 04:27:34 +01:00
Rob Ede
25209f5bd8 use impl-more in -tls 2022-10-17 04:14:09 +01:00
Rob Ede
c4a0f37d0c fix minimal versions for bytestring 2022-07-23 03:06:44 +01:00
Rob Ede
0e649329b9 fix minimal versions 2022-07-23 01:47:59 +01:00
Rob Ede
66756bc448 update all crates msrv to 1.57 (#464) 2022-07-23 00:51:12 +01:00
Iskandarov Lev
126ed4c2e3 normalize logs capital letter (#463)
Co-authored-by: Rob Ede <robjtede@icloud.com>
2022-07-22 20:53:06 +01:00
Yuki Okushi
283974f3e6 Make actix-codec an optional dependency (#459) 2022-06-23 17:27:36 +01:00
Yuki Okushi
bf2aa3902c Set depth of --feature-powerset on Windows CI (#460) 2022-06-12 02:17:38 +01:00
Rob Ede
71b4e55c92 prepare bytestring release 1.1.0 (#461) 2022-06-11 13:41:11 +01:00
Marcus Griep
eb5fa30ada feat: impls for Box and String conversions (#458)
Co-authored-by: Rob Ede <robjtede@icloud.com>
2022-06-11 04:22:34 +01:00
Rob Ede
49a034259f prepare local-waker release 0.1.3 2022-05-03 14:58:09 +01:00
Rob Ede
3337f63b4e prepare local-channel release 0.1.3 2022-05-03 14:56:40 +01:00
Rob Ede
86ce140249 ensure all crates include license files
closes #456
2022-05-03 14:55:49 +01:00
Guillaume Desmottes
635aebe887 actix-server: fix UNIX signal handling documentation (#455) 2022-05-03 13:37:18 +01:00
Rob Ede
4c1e581a54 add track_caller atrtibute to spawn calls (#454)
* add track_caller attribute to spawn calls

* fix ci
2022-04-25 21:05:48 +01:00
Rob Ede
dc67ba770d fmt with import grouping 2022-04-10 02:48:53 +01:00
Rob Ede
855e3f96fe prepare actix-tls release 3.0.4 2022-03-15 19:43:47 +00:00
Rob Ede
737b438f73 prepare actix-codec release 0.5.1 2022-03-15 19:43:06 +00:00
Rob Ede
0cd70b0536 use tracing for logs (#451) 2022-03-15 19:37:08 +00:00
Rob Ede
4b6a581ef3 prepare actix-server release 2.1.1 2022-03-09 01:08:35 +00:00
Rob Ede
3e132d2bc6 update tokio-uring to 0.3 (#448) 2022-03-08 23:42:52 +00:00
Rob Ede
c5d6174cec add tracing support 2022-03-08 22:13:55 +00:00
Rob Ede
77d4a69b2f update tokio-uring to 0.3 (#449) 2022-03-08 21:57:02 +00:00
Rob Ede
ae5377fd6e update readme 2022-03-08 21:12:46 +00:00
Rob Ede
bd9bda0504 fix readme msrv notes 2022-03-02 16:42:53 +00:00
Rob Ede
41ed48219d bump lower msrv to 1.49 2022-03-02 16:40:11 +00:00
fakeshadow
7804ed12eb block and wait for accept thread to exit. (#443)
Co-authored-by: Rob Ede <robjtede@icloud.com>
2022-03-02 03:52:12 +00:00
Rob Ede
2a54065fae parallel master tests using nextest 2022-02-15 14:19:00 +00:00
Rob Ede
217cbd2228 bump tokio-util to 0.7 (#446) 2022-02-15 01:47:27 +00:00
Rob Ede
d229c1e886 fix min ver check 2022-02-12 08:42:13 +00:00
Rob Ede
6792f799a6 add minimal-versions check 2022-02-12 08:37:56 +00:00
Rob Ede
72481313cc update readme 2022-01-28 22:28:24 +00:00
Rob Ede
59b629c74b fix deps badge 2022-01-28 22:17:12 +00:00
Rob Ede
7988694242 update msrv info 2022-01-28 22:15:16 +00:00
Rob Ede
b8a7741524 fix bind_addr 2022-01-28 22:13:10 +00:00
Rob Ede
5e290d76f8 prepare actix-tls release 3.0.2 2022-01-28 22:11:21 +00:00
Rob Ede
0edb64575f update tls changelog 2022-01-28 22:10:24 +00:00
Rob Ede
941f67dec9 s/e/err 2022-01-28 22:10:06 +00:00
Babur
3e624b8376 Made new constructor for the Connection type public (#439) 2022-01-28 22:09:54 +00:00
Ibraheem Ahmed
26446fdbad Replace derive_more with declarative macros (#438)
Co-authored-by: Rob Ede <robjtede@icloud.com>
2022-01-28 22:09:33 +00:00
Rob Ede
b7b7bd2cbf add actix-server readme 2022-01-19 16:14:06 +00:00
Rob Ede
637625f9b7 prepare actix-server release 2.0.0 (#437) 2022-01-19 14:57:50 +00:00
Rob Ede
b1d5d85e72 prepare actix-server release 2.0.0-rc.4 2022-01-12 14:40:06 +00:00
Rob Ede
ed2c07b304 prepare actix-rt release 2.6.0 2022-01-12 14:40:06 +00:00
Rob Ede
4fe7fec5ef update tokio-uring to 0.2.0 (#436) 2022-01-11 23:36:49 +00:00
Rob Ede
4c9ee88ec4 prepare actix-tls release 3.0.1 2022-01-11 22:17:31 +00:00
david-mcgillicuddy-moixa
9ec3cc0fe7 Replace str_split_once to lower actix-tls msrv to 1.50.0 and bump actix-net to 1.50.0 (#434) 2022-01-10 17:00:04 +00:00
Rob Ede
01e0f922de fix ci 2021-12-31 08:38:37 +00:00
Rob Ede
10d3bb6d0d only run coverage on master ci 2021-12-31 08:36:13 +00:00
Rob Ede
3ba4eafde5 prepare actix-server release 2.0.0-rc.3 2021-12-31 08:09:28 +00:00
Rob Ede
5faa98f6d2 prepare actix-rt release 2.5.1 2021-12-31 08:09:10 +00:00
Rob Ede
b552d847ed prepare actix-codec release 0.4.2 2021-12-31 08:08:14 +00:00
Rob Ede
5058e2d14e bump tokio in local-channel dev deps 2021-12-31 08:06:41 +00:00
80 changed files with 876 additions and 385 deletions

View File

@@ -14,13 +14,10 @@ ci-check = "hack --workspace --feature-powerset --exclude-features=io-uring chec
ci-check-linux = "hack --workspace --feature-powerset check --tests --examples"
# tests avoiding io-uring feature
ci-test = " hack --feature-powerset --exclude=actix-rt --exclude=actix-server --exclude-features=io-uring test --workspace --lib --tests --no-fail-fast -- --nocapture"
ci-test-rt = " hack --feature-powerset --exclude-features=io-uring test --package=actix-rt --lib --tests --no-fail-fast -- --nocapture"
ci-test-server = "hack --feature-powerset --exclude-features=io-uring test --package=actix-server --lib --tests --no-fail-fast -- --nocapture"
ci-test = "hack --feature-powerset --exclude-features=io-uring test --lib --tests --no-fail-fast -- --nocapture"
# tests avoiding io-uring feature on Windows
ci-test-win = "hack --feature-powerset --depth 2 --exclude-features=io-uring test --lib --tests --no-fail-fast -- --nocapture"
# test with io-uring feature
ci-test-rt-linux = " hack --feature-powerset test --package=actix-rt --lib --tests --no-fail-fast -- --nocapture"
ci-test-server-linux = "hack --feature-powerset test --package=actix-server --lib --tests --no-fail-fast -- --nocapture"
# test lower msrv
ci-test-lower-msrv = "hack --workspace --exclude=actix-server --exclude=actix-tls --feature-powerset test --lib --tests --no-fail-fast -- --nocapture"
ci-test-linux = "hack --feature-powerset test --lib --tests --no-fail-fast -- --nocapture"

210
.github/workflows/ci-master.yml vendored Normal file
View File

@@ -0,0 +1,210 @@
name: CI (master only)
on:
push:
branches: [master]
jobs:
build_and_test_nightly:
strategy:
fail-fast: false
matrix:
target:
- { name: Linux, os: ubuntu-latest, triple: x86_64-unknown-linux-gnu }
- { name: macOS, os: macos-latest, triple: x86_64-apple-darwin }
- { name: Windows, os: windows-latest, triple: x86_64-pc-windows-msvc }
- { name: Windows (MinGW), os: windows-latest, triple: x86_64-pc-windows-gnu }
- { name: Windows (32-bit), os: windows-latest, triple: i686-pc-windows-msvc }
version:
- nightly
name: ${{ matrix.target.name }} / ${{ matrix.version }}
runs-on: ${{ matrix.target.os }}
env:
VCPKGRS_DYNAMIC: 1
steps:
- name: Setup Routing
if: matrix.target.os == 'macos-latest'
run: sudo ifconfig lo0 alias 127.0.0.3
- uses: actions/checkout@v2
# install OpenSSL on Windows
- name: Set vcpkg root
if: matrix.target.triple == 'x86_64-pc-windows-msvc' || matrix.target.triple == 'i686-pc-windows-msvc'
run: echo "VCPKG_ROOT=$env:VCPKG_INSTALLATION_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Install OpenSSL
if: matrix.target.triple == 'x86_64-pc-windows-msvc'
run: vcpkg install openssl:x64-windows
- name: Install OpenSSL
if: matrix.target.triple == 'i686-pc-windows-msvc'
run: vcpkg install openssl:x86-windows
- name: Install ${{ matrix.version }}
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.version }}-${{ matrix.target.triple }}
profile: minimal
override: true
# - name: Install MSYS2
# if: matrix.target.triple == 'x86_64-pc-windows-gnu'
# uses: msys2/setup-msys2@v2
# - name: Install MinGW Packages
# if: matrix.target.triple == 'x86_64-pc-windows-gnu'
# run: |
# msys2 -c 'pacman -Sy --noconfirm pacman'
# msys2 -c 'pacman --noconfirm -S base-devel pkg-config'
# - name: Generate Cargo.lock
# uses: actions-rs/cargo@v1
# with: { command: generate-lockfile }
# - name: Cache Dependencies
# uses: Swatinem/rust-cache@v1.2.0
- name: Install cargo-hack
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-hack
- name: check lib
if: >
matrix.target.os != 'ubuntu-latest'
&& matrix.target.triple != 'x86_64-pc-windows-gnu'
uses: actions-rs/cargo@v1
with: { command: ci-check-lib }
- name: check lib
if: matrix.target.os == 'ubuntu-latest'
uses: actions-rs/cargo@v1
with: { command: ci-check-lib-linux }
- name: check lib
if: matrix.target.triple == 'x86_64-pc-windows-gnu'
uses: actions-rs/cargo@v1
with: { command: ci-check-min }
- name: check full
# TODO: compile OpenSSL and run tests on MinGW
if: >
matrix.target.os != 'ubuntu-latest'
&& matrix.target.triple != 'x86_64-pc-windows-gnu'
uses: actions-rs/cargo@v1
with: { command: ci-check }
- name: check all
if: matrix.target.os == 'ubuntu-latest'
uses: actions-rs/cargo@v1
with: { command: ci-check-linux }
- name: tests
if: >
matrix.target.os != 'ubuntu-latest'
&& matrix.target.triple != 'x86_64-pc-windows-gnu'
run: cargo ci-test
- name: tests
if: matrix.target.os == 'ubuntu-latest'
run: |
sudo bash -c "ulimit -Sl 512 && ulimit -Hl 512 && PATH=$PATH:/usr/share/rust/.cargo/bin && RUSTUP_TOOLCHAIN=${{ matrix.version }} cargo ci-test && RUSTUP_TOOLCHAIN=${{ matrix.version }} cargo ci-test-linux"
- name: Clear the cargo caches
run: |
cargo install cargo-cache --version 0.6.2 --no-default-features --features ci-autoclean
cargo-cache
coverage:
name: coverage
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: Generate coverage file
if: github.ref == 'refs/heads/master'
run: |
cargo install cargo-tarpaulin
cargo tarpaulin --out Xml --verbose
- name: Upload to Codecov
if: github.ref == 'refs/heads/master'
uses: codecov/codecov-action@v1
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

View File

@@ -18,9 +18,8 @@ jobs:
- { name: Windows (MinGW), os: windows-latest, triple: x86_64-pc-windows-gnu }
- { name: Windows (32-bit), os: windows-latest, triple: i686-pc-windows-msvc }
version:
- 1.52.0 # MSRV for -server and -tls
- 1.59.0
- stable
- nightly
name: ${{ matrix.target.name }} / ${{ matrix.version }}
runs-on: ${{ matrix.target.os }}
@@ -69,10 +68,29 @@ jobs:
# uses: Swatinem/rust-cache@v1.2.0
- name: Install cargo-hack
if: matrix.version != '1.59.0'
run: cargo install cargo-hack
# newer cargo-hack versions require 1.60 or above
- name: Install cargo-hack (1.59.0)
if: matrix.version == '1.59.0'
run: cargo install cargo-hack --version=0.5.21
- name: workaround MSRV issues
if: matrix.version == '1.59.0'
run: |
cargo install cargo-edit --version=0.8.0
cargo add env_logger@0.9 --dev -p=actix-tls
cargo add env_logger@0.9 --dev -p=actix-server
- name: Generate Cargo.lock
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-hack
with: { command: generate-lockfile }
- name: workaround MSRV issues
if: matrix.version != 'stable'
run: |
cargo update -p=time --precise=0.3.13 # time is only a dev dep so shouldn't affect msrv
- name: check lib
if: >
@@ -88,7 +106,7 @@ jobs:
if: matrix.target.triple == 'x86_64-pc-windows-gnu'
uses: actions-rs/cargo@v1
with: { command: ci-check-min }
- name: check full
# TODO: compile OpenSSL and run tests on MinGW
if: >
@@ -101,80 +119,24 @@ jobs:
uses: actions-rs/cargo@v1
with: { command: ci-check-linux }
- name: tests
if: matrix.target.os == 'macos-latest'
run: cargo ci-test
- name: tests
if: >
matrix.target.os != 'ubuntu-latest'
matrix.target.os == 'windows-latest'
&& matrix.target.triple != 'x86_64-pc-windows-gnu'
run: |
cargo ci-test
cargo ci-test-rt
cargo ci-test-server
run: cargo ci-test-win
- name: tests
if: matrix.target.os == 'ubuntu-latest'
run: |
sudo bash -c "ulimit -Sl 512 && ulimit -Hl 512 && PATH=$PATH:/usr/share/rust/.cargo/bin && RUSTUP_TOOLCHAIN=${{ matrix.version }} cargo ci-test && RUSTUP_TOOLCHAIN=${{ matrix.version }} cargo ci-test-rt-linux && RUSTUP_TOOLCHAIN=${{ matrix.version }} cargo ci-test-server-linux"
sudo bash -c "ulimit -Sl 512 && ulimit -Hl 512 && PATH=$PATH:/usr/share/rust/.cargo/bin && RUSTUP_TOOLCHAIN=${{ matrix.version }} cargo ci-test && RUSTUP_TOOLCHAIN=${{ matrix.version }} cargo ci-test-linux"
- name: Clear the cargo caches
if: matrix.version == 'stable' # MSRV(1.58) cargo-cache now fails to install on 1.59
run: |
cargo install cargo-cache --version 0.6.2 --no-default-features --features ci-autoclean
cargo-cache
build_and_test_lower_msrv:
name: Linux / 1.46 (lower MSRV)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install 1.46.0 # MSRV for all but -server and -tls
uses: actions-rs/toolchain@v1
with:
toolchain: 1.46.0-x86_64-unknown-linux-gnu
profile: minimal
override: true
- name: Install cargo-hack
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-hack
- name: tests
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"
- name: Clear the cargo caches
run: |
cargo install cargo-cache --version 0.6.2 --no-default-features --features ci-autoclean
cargo-cache
coverage:
name: coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Rust (nightly)
uses: actions-rs/toolchain@v1
with:
toolchain: stable-x86_64-unknown-linux-gnu
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: Generate coverage file
if: github.ref == 'refs/heads/master'
run: |
cargo install cargo-tarpaulin
cargo tarpaulin --out Xml --verbose
- name: Upload to Codecov
if: github.ref == 'refs/heads/master'
uses: codecov/codecov-action@v1
with: { file: cobertura.xml }
rustdoc:
name: rustdoc

View File

@@ -2,22 +2,25 @@
> A collection of lower-level libraries for composable network services.
![Apache 2.0 or MIT licensed](https://img.shields.io/crates/l/actix-server)
[![CI](https://github.com/actix/actix-net/actions/workflows/ci.yml/badge.svg?event=push)](https://github.com/actix/actix-net/actions/workflows/ci.yml)
[![CI](https://github.com/actix/actix-net/actions/workflows/ci.yml/badge.svg?event=push&style=flat-square)](https://github.com/actix/actix-net/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/actix/actix-net/branch/master/graph/badge.svg)](https://codecov.io/gh/actix/actix-net)
[![Chat on Discord](https://img.shields.io/discord/771444961383153695?label=chat&logo=discord)](https://discord.gg/NWpN5mmg3x)
[![Dependency Status](https://deps.rs/repo/github/actix/actix-net/status.svg)](https://deps.rs/repo/github/actix/actix-net)
## Example
See `actix-server/examples` and `actix-tls/examples` for some basic examples.
## Examples
### MSRV
This repo's Minimum Supported Rust Version (MSRV) is 1.46.0.
See example folders for [`actix-server`](./actix-server/examples) and [`actix-tls`](./actix-tls/examples).
## MSRV
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
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))
* MIT license ([LICENSE-MIT](LICENSE-MIT) or [http://opensource.org/licenses/MIT](http://opensource.org/licenses/MIT))
The crates in repo are 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))
- MIT license ([LICENSE-MIT](LICENSE-MIT) or [http://opensource.org/licenses/MIT](http://opensource.org/licenses/MIT))
at your option.

View File

@@ -1,6 +1,24 @@
# Changes
## Unreleased - 2021-xx-xx
## Unreleased - 2022-xx-xx
- Minimum supported Rust version (MSRV) is now 1.59.
## 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
- No significant changes since `0.4.1`.
## 0.4.1 - 2021-11-05

View File

@@ -1,6 +1,6 @@
[package]
name = "actix-codec"
version = "0.4.1"
version = "0.5.1"
authors = [
"Nikolay Kim <fafhrd91@gmail.com>",
"Rob Ede <robjtede@icloud.com>",
@@ -17,18 +17,18 @@ name = "actix_codec"
path = "src/lib.rs"
[dependencies]
bitflags = "1.2.1"
bitflags = "1.2"
bytes = "1"
futures-core = { version = "0.3.7", default-features = false }
futures-sink = { version = "0.3.7", default-features = false }
log = "0.4"
memchr = "2.3"
pin-project-lite = "0.2"
tokio = "1.5.1"
tokio-util = { version = "0.6", features = ["codec", "io"] }
tokio = "1.18.4"
tokio-util = { version = "0.7", features = ["codec", "io"] }
tracing = { version = "0.1.30", default-features = false, features = ["log"] }
[dev-dependencies]
criterion = { version = "0.3", features = ["html_reports"] }
criterion = { version = "0.4", features = ["html_reports"] }
tokio-test = "0.4.2"
[[bench]]

View File

@@ -193,18 +193,18 @@ impl<T, U> Framed<T, U> {
match this.codec.decode_eof(this.read_buf) {
Ok(Some(frame)) => return Poll::Ready(Some(Ok(frame))),
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) {
Ok(Some(frame)) => {
log::trace!("frame decoded from buffer");
tracing::trace!("frame decoded from buffer");
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
}
@@ -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) {
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,
};
@@ -242,10 +242,10 @@ impl<T, U> Framed<T, U> {
U: Encoder<I>,
{
let mut this = self.as_mut().project();
log::trace!("flushing framed transport");
tracing::trace!("flushing framed transport");
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))?;
@@ -264,7 +264,7 @@ impl<T, U> Framed<T, U> {
// Try flushing the underlying IO
ready!(this.io.poll_flush(cx))?;
log::trace!("framed transport flushed");
tracing::trace!("framed transport flushed");
Poll::Ready(Ok(()))
}

View File

@@ -1,8 +1,7 @@
//! Codec utilities for working with framed protocols.
//!
//! Contains adapters to go from streams of bytes, [`AsyncRead`] and
//! [`AsyncWrite`], to framed streams implementing [`Sink`] and [`Stream`].
//! Framed streams are also known as `transports`.
//! Contains adapters to go from streams of bytes, [`AsyncRead`] and [`AsyncWrite`], to framed
//! streams implementing [`Sink`] and [`Stream`]. Framed streams are also known as `transports`.
//!
//! [`Sink`]: futures_sink::Sink
//! [`Stream`]: futures_core::Stream
@@ -16,10 +15,10 @@ mod bcodec;
mod framed;
mod lines;
pub use self::bcodec::BytesCodec;
pub use self::framed::{Framed, FramedParts};
pub use self::lines::LinesCodec;
pub use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
pub use tokio_util::codec::{Decoder, Encoder};
pub use tokio_util::io::poll_read_buf;
pub use self::bcodec::BytesCodec;
pub use self::framed::{Framed, FramedParts};
pub use self::lines::LinesCodec;

View File

@@ -7,8 +7,8 @@ use super::{Decoder, Encoder};
/// 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
/// lines are not preserved.
/// Will split input up by LF or CRLF delimiters. Carriage return characters at the end of lines are
/// not preserved.
#[derive(Debug, Copy, Clone, Default)]
#[non_exhaustive]
pub struct LinesCodec;

View File

@@ -1,12 +1,16 @@
use std::{
collections::VecDeque,
io::{self, Write},
pin::Pin,
task::{
Context,
Poll::{self, Pending, Ready},
},
};
use actix_codec::*;
use bytes::Buf;
use bytes::{BufMut, BytesMut};
use bytes::{Buf as _, BufMut as _, BytesMut};
use futures_sink::Sink;
use std::collections::VecDeque;
use std::io::{self, Write};
use std::pin::Pin;
use std::task::Poll::{Pending, Ready};
use std::task::{Context, Poll};
use tokio_test::{assert_ready, task};
macro_rules! bilateral {
@@ -50,7 +54,7 @@ impl Write for Bilateral {
assert_eq!(&data[..], &src[..data.len()]);
Ok(data.len())
}
Some(Err(e)) => Err(e),
Some(Err(err)) => Err(err),
None => panic!("unexpected write; {:?}", src),
}
}
@@ -67,13 +71,13 @@ impl AsyncWrite for Bilateral {
buf: &[u8],
) -> Poll<Result<usize, io::Error>> {
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),
}
}
fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
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),
}
}
@@ -99,8 +103,8 @@ impl AsyncRead for Bilateral {
buf.put_slice(&data);
Ready(Ok(()))
}
Some(Err(ref e)) if e.kind() == WouldBlock => Pending,
Some(Err(e)) => Ready(Err(e)),
Some(Err(ref err)) if err.kind() == WouldBlock => Pending,
Some(Err(err)) => Ready(Err(err)),
None => Ready(Ok(())),
}
}

View File

@@ -1,6 +1,7 @@
# Changes
## Unreleased - 2021-xx-xx
## Unreleased - 2022-xx-xx
- Minimum supported Rust version (MSRV) is now 1.59.
## 0.2.3 - 2021-10-19

View File

@@ -16,12 +16,12 @@ edition = "2018"
proc-macro = true
[dependencies]
quote = "1.0.3"
syn = { version = "^1", features = ["full"] }
quote = "1"
syn = { version = "1", features = ["full"] }
[dev-dependencies]
actix-rt = "2.0.0"
actix-rt = "2"
futures-util = { version = "0.3.7", default-features = false }
futures-util = { version = "0.3.17", default-features = false }
rustversion = "1"
trybuild = "1"

View File

@@ -1,6 +1,31 @@
# Changes
## Unreleased - 2021-xx-xx
## Unreleased - 2022-xx-xx
## 2.8.0 - 2022-12-21
- Add `#[track_caller]` attribute to `spawn` functions and methods. [#454]
- Update `tokio-uring` dependency to `0.4`. [#473]
- Minimum supported Rust version (MSRV) is now 1.59.
[#454]: https://github.com/actix/actix-net/pull/454
[#473]: https://github.com/actix/actix-net/pull/473
## 2.7.0 - 2022-03-08
- Update `tokio-uring` dependency to `0.3`. [#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
- Update `tokio-uring` dependency to `0.2`. [#436]
[#436]: https://github.com/actix/actix-net/pull/436
## 2.5.1 - 2021-12-31
- Expose `System::with_tokio_rt` and `Arbiter::with_tokio_rt`. [#430]
[#430]: https://github.com/actix/actix-net/pull/430

View File

@@ -1,10 +1,9 @@
[package]
name = "actix-rt"
version = "2.5.0"
version = "2.8.0"
authors = [
"Nikolay Kim <fafhrd91@gmail.com>",
"Rob Ede <robjtede@icloud.com>",
"fakeshadow <24548779@qq.com>",
]
description = "Tokio-based single-threaded async runtime for the Actix ecosystem"
keywords = ["async", "futures", "io", "runtime"]
@@ -27,11 +26,12 @@ io-uring = ["tokio-uring"]
actix-macros = { version = "0.2.3", optional = true }
futures-core = { version = "0.3", default-features = false }
tokio = { version = "1.5.1", features = ["rt", "net", "parking_lot", "signal", "sync", "time"] }
tokio = { version = "1.18.4", features = ["rt", "net", "parking_lot", "signal", "sync", "time"] }
# runtime for `io-uring` feature
[target.'cfg(target_os = "linux")'.dependencies]
tokio-uring = { version = "0.1", optional = true }
tokio-uring = { version = "0.4", optional = true }
[dev-dependencies]
tokio = { version = "1.5.1", features = ["full"] }
hyper = { version = "0.14", default-features = false, features = ["server", "tcp", "http1"] }
tokio = { version = "1.18.4", features = ["full"] }
hyper = { version = "0.14.10", default-features = false, features = ["server", "tcp", "http1"] }

View File

@@ -3,11 +3,11 @@
> Tokio-based single-threaded async runtime for the Actix ecosystem.
[![crates.io](https://img.shields.io/crates/v/actix-rt?label=latest)](https://crates.io/crates/actix-rt)
[![Documentation](https://docs.rs/actix-rt/badge.svg?version=2.5.0)](https://docs.rs/actix-rt/2.5.0)
[![Documentation](https://docs.rs/actix-rt/badge.svg?version=2.8.0)](https://docs.rs/actix-rt/2.8.0)
[![Version](https://img.shields.io/badge/rustc-1.46+-ab6000.svg)](https://blog.rust-lang.org/2020/03/12/Rust-1.46.html)
![MIT or Apache 2.0 licensed](https://img.shields.io/crates/l/actix-rt.svg)
<br />
[![dependency status](https://deps.rs/crate/actix-rt/2.5.0/status.svg)](https://deps.rs/crate/actix-rt/2.5.0)
[![dependency status](https://deps.rs/crate/actix-rt/2.8.0/status.svg)](https://deps.rs/crate/actix-rt/2.8.0)
![Download](https://img.shields.io/crates/d/actix-rt.svg)
[![Chat on Discord](https://img.shields.io/discord/771444961383153695?label=chat&logo=discord)](https://discord.gg/WghFtEH6Hb)

View File

@@ -1,7 +1,9 @@
use hyper::service::{make_service_fn, service_fn};
use hyper::{Body, Request, Response, Server};
use std::convert::Infallible;
use std::net::SocketAddr;
use std::{convert::Infallible, net::SocketAddr};
use hyper::{
service::{make_service_fn, service_fn},
Body, Request, Response, Server,
};
async fn handle(_req: Request<Body>) -> Result<Response<Body>, Infallible> {
Ok(Response::new(Body::from("Hello World")))
@@ -21,8 +23,8 @@ fn main() {
let server =
Server::bind(&SocketAddr::from(([127, 0, 0, 1], 3000))).serve(make_service);
if let Err(e) = server.await {
eprintln!("server error: {}", e);
if let Err(err) = server.await {
eprintln!("server error: {}", err);
}
})
}

View File

@@ -260,6 +260,7 @@ impl Arbiter {
/// If you require a result, include a response channel in the future.
///
/// Returns true if future was sent successfully and false if the Arbiter has died.
#[track_caller]
pub fn spawn<Fut>(&self, future: Fut) -> bool
where
Fut: Future<Output = ()> + Send + 'static,
@@ -275,6 +276,7 @@ impl Arbiter {
/// channel in the function.
///
/// Returns true if function was sent successfully and false if the Arbiter has died.
#[track_caller]
pub fn spawn_fn<F>(&self, f: F) -> bool
where
F: FnOnce() + Send + 'static,
@@ -301,7 +303,7 @@ impl Future for ArbiterRunner {
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
// process all items currently buffered in channel
loop {
match ready!(Pin::new(&mut self.rx).poll_recv(cx)) {
match ready!(self.rx.poll_recv(cx)) {
// channel closed; no more messages can be received
None => return Poll::Ready(()),

View File

@@ -51,13 +51,10 @@ compile_error!("io_uring is a linux only feature.");
use std::future::Future;
use tokio::task::JoinHandle;
// 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;
#[cfg(feature = "macros")]
pub use actix_macros::test;
@@ -65,12 +62,13 @@ mod arbiter;
mod runtime;
mod system;
pub use tokio::pin;
use tokio::task::JoinHandle;
pub use self::arbiter::{Arbiter, ArbiterHandle};
pub use self::runtime::Runtime;
pub use self::system::{System, SystemRunner};
pub use tokio::pin;
pub mod signal {
//! Asynchronous signal handling (Tokio re-exports).
@@ -95,7 +93,6 @@ pub mod net {
use tokio::io::{AsyncRead, AsyncWrite, Interest};
pub use tokio::net::UdpSocket;
pub use tokio::net::{TcpListener, TcpSocket, TcpStream};
#[cfg(unix)]
pub use tokio::net::{UnixDatagram, UnixListener, UnixStream};
@@ -198,6 +195,7 @@ pub mod task {
/// assert!(handle.await.unwrap_err().is_cancelled());
/// # });
/// ```
#[track_caller]
#[inline]
pub fn spawn<Fut>(f: Fut) -> JoinHandle<Fut::Output>
where

View File

@@ -53,6 +53,7 @@ impl Runtime {
/// # Panics
/// This function panics if the spawn fails. Failure occurs if the executor is currently at
/// capacity and is unable to spawn a new future.
#[track_caller]
pub fn spawn<F>(&self, future: F) -> JoinHandle<F::Output>
where
F: Future + 'static,
@@ -73,6 +74,7 @@ impl Runtime {
///
/// The caller is responsible for ensuring that other spawned futures complete execution by
/// calling `block_on` or `run`.
#[track_caller]
pub fn block_on<F>(&self, f: F) -> F::Output
where
F: Future,

View File

@@ -204,6 +204,7 @@ impl SystemRunner {
}
/// Runs the provided future, blocking the current thread until the future completes.
#[track_caller]
#[inline]
pub fn block_on<F: Future>(&self, fut: F) -> F::Output {
self.rt.block_on(fut)
@@ -291,7 +292,7 @@ impl Future for SystemController {
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
// process all items currently buffered in channel
loop {
match ready!(Pin::new(&mut self.cmd_rx).poll_recv(cx)) {
match ready!(self.cmd_rx.poll_recv(cx)) {
// channel closed; no more messages can be received
None => return Poll::Ready(()),

View File

@@ -4,7 +4,6 @@ use std::{
};
use actix_rt::{task::JoinError, Arbiter, System};
#[cfg(not(feature = "io-uring"))]
use {
std::{sync::mpsc::channel, thread},

View File

@@ -1,6 +1,40 @@
# Changes
## Unreleased - 2021-xx-xx
## Unreleased - 2022-xx-xx
## 2.2.0 - 2022-12-21
- Minimum supported Rust version (MSRV) is now 1.59.
- Update `tokio-uring` dependency to `0.4`. [#473]
[#473]: https://github.com/actix/actix-net/pull/473
## 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`. [#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
- Update `tokio-uring` dependency to `0.2`. [#436]
[#436]: https://github.com/actix/actix-net/pull/436
## 2.0.0-rc.3 - 2021-12-31
- No significant changes since `2.0.0-rc.2`.
## 2.0.0-rc.2 - 2021-12-27

View File

@@ -1,9 +1,8 @@
[package]
name = "actix-server"
version = "2.0.0-rc.2"
version = "2.2.0"
authors = [
"Nikolay Kim <fafhrd91@gmail.com>",
"fakeshadow <24548779@qq.com>",
"Rob Ede <robjtede@icloud.com>",
"Ali MJ Al-Nasrawy <alimjalnasrawy@gmail.com>",
]
@@ -24,26 +23,27 @@ default = []
io-uring = ["tokio-uring", "actix-rt/io-uring"]
[dependencies]
actix-rt = { version = "2.4.0", default-features = false }
actix-service = "2.0.0"
actix-utils = "3.0.0"
actix-rt = { version = "2.8", default-features = false }
actix-service = "2"
actix-utils = "3"
futures-core = { version = "0.3.7", default-features = false, features = ["alloc"] }
futures-util = { version = "0.3.7", default-features = false, features = ["alloc"] }
log = "0.4"
futures-core = { version = "0.3.17", default-features = false, features = ["alloc"] }
futures-util = { version = "0.3.17", default-features = false, features = ["alloc"] }
mio = { version = "0.8", features = ["os-poll", "net"] }
num_cpus = "1.13"
socket2 = "0.4.2"
tokio = { version = "1.5.1", features = ["sync"] }
tokio = { version = "1.18.4", features = ["sync"] }
tracing = { version = "0.1.30", default-features = false, features = ["log"] }
# runtime for io-uring feature
tokio-uring = { version = "0.1", optional = true }
# runtime for `io-uring` feature
[target.'cfg(target_os = "linux")'.dependencies]
tokio-uring = { version = "0.4", optional = true }
[dev-dependencies]
actix-codec = "0.4.0"
actix-rt = "2.4.0"
actix-codec = "0.5"
actix-rt = "2.8"
bytes = "1"
env_logger = "0.9"
futures-util = { version = "0.3.7", default-features = false, features = ["sink", "async-await-macro"] }
tokio = { version = "1.5.1", features = ["io-util", "rt-multi-thread", "macros", "fs"] }
env_logger = "0.10"
futures-util = { version = "0.3.17", default-features = false, features = ["sink", "async-await-macro"] }
tokio = { version = "1.18.4", features = ["io-util", "rt-multi-thread", "macros", "fs"] }

15
actix-server/README.md Normal file
View File

@@ -0,0 +1,15 @@
# actix-server
> General purpose TCP server built for the Actix ecosystem.
[![crates.io](https://img.shields.io/crates/v/actix-server?label=latest)](https://crates.io/crates/actix-server)
[![Documentation](https://docs.rs/actix-server/badge.svg?version=2.2.0)](https://docs.rs/actix-server/2.2.0)
[![Version](https://img.shields.io/badge/rustc-1.52+-ab6000.svg)](https://blog.rust-lang.org/2021/05/06/Rust-1.52.0.html)
![License](https://img.shields.io/crates/l/actix-server.svg)
[![Dependency Status](https://deps.rs/crate/actix-server/2.2.0/status.svg)](https://deps.rs/crate/actix-server/2.2.0)
![Download](https://img.shields.io/crates/d/actix-server.svg)
[![Chat on Discord](https://img.shields.io/discord/771444961383153695?label=chat&logo=discord)](https://discord.gg/NWpN5mmg3x)
## Resources
- [Library Documentation](https://docs.rs/actix-server)
- [Examples](/actix-server/examples)

View File

@@ -21,7 +21,7 @@ async fn run() -> io::Result<()> {
env_logger::init_from_env(env_logger::Env::default().default_filter_or("info"));
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
// 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
match framed.next().await {
Some(Ok(line)) => {
match File::open(line).await {
match File::open(&line).await {
Ok(mut file) => {
tracing::info!("reading file: {}", &line);
// read file into String buffer
let mut buf = String::new();
file.read_to_string(&mut buf).await?;
@@ -52,7 +54,7 @@ async fn run() -> io::Result<()> {
break;
}
Err(err) => {
log::error!("{}", err);
tracing::error!("{}", err);
framed
.send("File not found or not readable. Try again.")
.await?;
@@ -72,7 +74,7 @@ async fn run() -> io::Result<()> {
// close connection after file has been copied to TCP stream
Ok(())
})
.map_err(|err| log::error!("Service Error: {:?}", err))
.map_err(|err| tracing::error!("service error: {:?}", err))
})?
.workers(2)
.run()

View File

@@ -22,7 +22,6 @@ use actix_server::Server;
use actix_service::{fn_service, ServiceFactoryExt as _};
use bytes::BytesMut;
use futures_util::future::ok;
use log::{error, info};
use tokio::io::{AsyncReadExt as _, AsyncWriteExt as _};
async fn run() -> io::Result<()> {
@@ -31,7 +30,7 @@ async fn run() -> io::Result<()> {
let count = Arc::new(AtomicUsize::new(0));
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
// 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
Ok(bytes_read) => {
info!("[{}] read {} bytes", num, bytes_read);
tracing::info!("[{}] read {} bytes", num, bytes_read);
stream.write_all(&buf[size..]).await.unwrap();
size += bytes_read;
}
// stream error; bail from loop with error
Err(err) => {
error!("Stream Error: {:?}", err);
tracing::error!("stream error: {:?}", err);
return Err(());
}
}
@@ -75,10 +74,10 @@ async fn run() -> io::Result<()> {
Ok((buf.freeze(), size))
}
})
.map_err(|err| error!("Service Error: {:?}", err))
.map_err(|err| tracing::error!("service error: {:?}", err))
.and_then(move |(_, size)| {
let num = num2.load(Ordering::SeqCst);
info!("[{}] total bytes read: {}", num, size);
tracing::info!("[{}] total bytes read: {}", num, size);
ok(size)
})
})?

View File

@@ -1,8 +1,8 @@
use std::{io, thread, time::Duration};
use actix_rt::time::Instant;
use log::{debug, error, info};
use mio::{Interest, Poll, Token as MioToken};
use tracing::{debug, error, info};
use crate::{
availability::Availability,
@@ -24,7 +24,7 @@ struct ServerSocketInfo {
timeout: Option<actix_rt::time::Instant>,
}
/// poll instance of the server.
/// Poll instance of the server.
pub(crate) struct Accept {
poll: Poll,
waker_queue: WakerQueue,
@@ -41,7 +41,7 @@ impl Accept {
pub(crate) fn start(
sockets: Vec<(usize, MioListener)>,
builder: &ServerBuilder,
) -> io::Result<(WakerQueue, Vec<WorkerHandleServer>)> {
) -> io::Result<(WakerQueue, Vec<WorkerHandleServer>, thread::JoinHandle<()>)> {
let handle_server = ServerHandle::new(builder.cmd_tx.clone());
// construct poll instance and its waker
@@ -73,12 +73,12 @@ impl Accept {
handle_server,
)?;
thread::Builder::new()
let accept_handle = thread::Builder::new()
.name("actix-server acceptor".to_owned())
.spawn(move || accept.poll_with(&mut sockets))
.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(
@@ -127,10 +127,10 @@ impl Accept {
let mut events = mio::Events::with_capacity(256);
loop {
if let Err(e) = self.poll.poll(&mut events, self.timeout) {
match e.kind() {
if let Err(err) = self.poll.poll(&mut events, self.timeout) {
match err.kind() {
io::ErrorKind::Interrupted => {}
_ => panic!("Poll error: {}", e),
_ => panic!("Poll error: {}", err),
}
}
@@ -140,7 +140,7 @@ impl Accept {
WAKER_TOKEN => {
let exit = self.handle_waker(sockets);
if exit {
info!("Accept thread stopped");
info!("accept thread stopped");
return;
}
}
@@ -161,11 +161,13 @@ impl Accept {
// a loop that would try to drain the command channel. It's yet unknown
// if it's necessary/good practice to actively drain the waker queue.
loop {
// take guard with every iteration so no new interest can be added
// until the current task is done.
// Take guard with every iteration so no new interests can be added until the current
// task is done. Take care not to take the guard again inside this loop.
let mut guard = self.waker_queue.guard();
#[allow(clippy::significant_drop_in_scrutinee)]
match guard.pop_front() {
// worker notify it becomes available.
// Worker notified it became available.
Some(WakerInterest::WorkerAvailable(idx)) => {
drop(guard);
@@ -176,7 +178,7 @@ impl Accept {
}
}
// a new worker thread is made and it's handle would be added to Accept
// A new worker thread has been created so store its handle.
Some(WakerInterest::Worker(handle)) => {
drop(guard);
@@ -297,16 +299,16 @@ impl Accept {
fn register_logged(&self, info: &mut ServerSocketInfo) {
match self.register(info) {
Ok(_) => debug!("Resume accepting connections on {}", info.lst.local_addr()),
Err(e) => error!("Can not register server socket {}", e),
Ok(_) => debug!("resume accepting connections on {}", info.lst.local_addr()),
Err(err) => error!("can not register server socket {}", err),
}
}
fn deregister_logged(&self, info: &mut ServerSocketInfo) {
match self.poll.registry().deregister(&mut info.lst) {
Ok(_) => debug!("Paused accepting connections on {}", info.lst.local_addr()),
Err(e) => {
error!("Can not deregister server socket {}", e)
Ok(_) => debug!("paused accepting connections on {}", info.lst.local_addr()),
Err(err) => {
error!("can not deregister server socket {}", err)
}
}
}
@@ -350,7 +352,7 @@ impl Accept {
self.remove_next();
if self.handles.is_empty() {
error!("No workers");
error!("no workers");
// All workers are gone and Conn is nowhere to be sent.
// Treat this situation as Ok and drop Conn.
return Ok(());
@@ -396,10 +398,10 @@ impl Accept {
let conn = Conn { io, token };
self.accept_one(conn);
}
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => return,
Err(ref e) if connection_error(e) => continue,
Err(e) => {
error!("Error accepting connection: {}", e);
Err(ref err) if err.kind() == io::ErrorKind::WouldBlock => return,
Err(ref err) if connection_error(err) => continue,
Err(err) => {
error!("error accepting connection: {}", err);
// deregister listener temporary
self.deregister_logged(info);

View File

@@ -1,8 +1,8 @@
use std::{io, time::Duration};
use actix_rt::net::TcpStream;
use log::{info, trace};
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
use tracing::{info, trace};
use crate::{
server::ServerCommand,
@@ -197,7 +197,7 @@ impl ServerBuilder {
if self.sockets.is_empty() {
panic!("Server should have at least one bound socket");
} else {
info!("Starting {} workers", self.threads);
info!("starting {} workers", self.threads);
Server::new(self)
}
}
@@ -220,10 +220,10 @@ impl ServerBuilder {
{
// The path must not exist when we try to bind.
// 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.
if e.kind() != std::io::ErrorKind::NotFound {
return Err(e);
if err.kind() != std::io::ErrorKind::NotFound {
return Err(err);
}
}
@@ -264,22 +264,23 @@ pub(super) fn bind_addr<S: ToSocketAddrs>(
addr: S,
backlog: u32,
) -> io::Result<Vec<MioTcpListener>> {
let mut err = None;
let mut opt_err = None;
let mut success = false;
let mut sockets = Vec::new();
for addr in addr.to_socket_addrs()? {
match create_mio_tcp_listener(addr, backlog) {
Ok(lst) => {
success = true;
sockets.push(lst);
}
Err(e) => err = Some(e),
Err(err) => opt_err = Some(err),
}
}
if success {
Ok(sockets)
} else if let Some(err) = err.take() {
} else if let Some(err) = opt_err.take() {
Err(err)
} else {
Err(io::Error::new(

View File

@@ -63,10 +63,10 @@ impl<T> Future for JoinAll<T> {
#[cfg(test)]
mod test {
use super::*;
use actix_utils::future::ready;
use super::*;
#[actix_rt::test]
async fn test_join_all() {
let futs = vec![ready(Ok(1)), ready(Err(3)), ready(Ok(9))];

View File

@@ -22,10 +22,9 @@ pub use self::builder::ServerBuilder;
pub use self::handle::ServerHandle;
pub use self::server::Server;
pub use self::service::ServerServiceFactory;
pub use self::test_server::TestServer;
#[doc(hidden)]
pub use self::socket::FromStream;
pub use self::test_server::TestServer;
/// Start server building process
#[doc(hidden)]

View File

@@ -3,14 +3,15 @@ use std::{
io, mem,
pin::Pin,
task::{Context, Poll},
thread,
time::Duration,
};
use actix_rt::{time::sleep, System};
use futures_core::{future::BoxFuture, Stream};
use futures_util::stream::StreamExt as _;
use log::{error, info};
use tokio::sync::{mpsc::UnboundedReceiver, oneshot};
use tracing::{error, info};
use crate::{
accept::Accept,
@@ -65,7 +66,7 @@ pub(crate) enum ServerCommand {
/// server has fully shut down.
///
/// # Shutdown Signals
/// On UNIX systems, `SIGQUIT` will start a graceful shutdown and `SIGTERM` or `SIGINT` will start a
/// On UNIX systems, `SIGTERM` will start a graceful shutdown and `SIGQUIT` or `SIGINT` will start a
/// forced shutdown. On Windows, a Ctrl-C signal will start a forced shutdown.
///
/// A graceful shutdown will wait for all workers to stop first.
@@ -158,6 +159,7 @@ impl Future for Server {
pub struct ServerInner {
worker_handles: Vec<WorkerHandleServer>,
accept_handle: Option<thread::JoinHandle<()>>,
worker_config: ServerWorkerConfig,
services: Vec<Box<dyn InternalServiceFactory>>,
waker_queue: WakerQueue,
@@ -198,14 +200,14 @@ impl ServerInner {
for (_, name, lst) in &builder.sockets {
info!(
r#"Starting service: "{}", workers: {}, listening on: {}"#,
r#"starting service: "{}", workers: {}, listening on: {}"#,
name,
builder.threads,
lst.local_addr()
);
}
let (waker_queue, worker_handles) = Accept::start(sockets, &builder)?;
let (waker_queue, worker_handles, accept_handle) = Accept::start(sockets, &builder)?;
let mux = ServerEventMultiplexer {
signal_fut: (builder.listen_os_signals).then(Signals::new),
@@ -214,6 +216,7 @@ impl ServerInner {
let server = ServerInner {
waker_queue,
accept_handle: Some(accept_handle),
worker_handles,
worker_config: builder.worker_config,
services: builder.factories,
@@ -243,7 +246,8 @@ impl ServerInner {
} => {
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);
// send stop signal to workers
@@ -258,6 +262,13 @@ impl ServerInner {
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 {
let _ = tx.send(());
}
@@ -272,7 +283,7 @@ impl ServerInner {
// TODO: maybe just return with warning log if not found ?
assert!(self.worker_handles.iter().any(|wrk| wrk.idx == idx));
error!("Worker {} has died; restarting", idx);
error!("worker {} has died; restarting", idx);
let factories = self
.services
@@ -352,6 +363,6 @@ impl Stream for ServerEventMultiplexer {
}
}
Pin::new(&mut this.cmd_rx).poll_recv(cx)
this.cmd_rx.poll_recv(cx)
}
}

View File

@@ -7,7 +7,7 @@ use std::{
use actix_service::{Service, ServiceFactory as BaseServiceFactory};
use actix_utils::future::{ready, Ready};
use futures_core::future::LocalBoxFuture;
use log::error;
use tracing::error;
use crate::{
socket::{FromStream, MioStream},
@@ -77,8 +77,8 @@ where
});
Ok(())
}
Err(e) => {
error!("Can not convert to an async tcp stream: {}", e);
Err(err) => {
error!("can not convert to an async TCP stream: {}", err);
Err(())
}
})

View File

@@ -5,7 +5,7 @@ use std::{
task::{Context, Poll},
};
use log::trace;
use tracing::trace;
/// Types of process signals.
// #[allow(dead_code)]
@@ -69,8 +69,8 @@ impl Signals {
unix::signal(*kind)
.map(|tokio_sig| (*sig, tokio_sig))
.map_err(|e| {
log::error!(
"Can not initialize stream handler for {:?} err: {}",
tracing::error!(
"can not initialize stream handler for {:?} err: {}",
sig,
e
)
@@ -96,7 +96,7 @@ impl Future for Signals {
#[cfg(unix)]
{
for (sig, fut) in self.signals.iter_mut() {
if Pin::new(fut).poll_recv(cx).is_ready() {
if fut.poll_recv(cx).is_ready() {
trace!("{} received", sig);
return Poll::Ready(*sig);
}

View File

@@ -6,7 +6,6 @@ use std::{fmt, io};
use actix_rt::net::TcpStream;
pub(crate) use mio::net::TcpListener as MioTcpListener;
use mio::{event::Source, Interest, Registry, Token};
#[cfg(unix)]
pub(crate) use {
mio::net::UnixListener as MioUnixListener,

View File

@@ -17,11 +17,11 @@ use actix_rt::{
Arbiter, ArbiterHandle, System,
};
use futures_core::{future::LocalBoxFuture, ready};
use log::{error, info, trace};
use tokio::sync::{
mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender},
oneshot,
};
use tracing::{error, info, trace};
use crate::{
service::{BoxedServerService, InternalServiceFactory},
@@ -337,7 +337,7 @@ impl ServerWorker {
Ok((token, svc)) => services.push((idx, token, svc)),
Err(err) => {
error!("Can not start worker: {:?}", err);
error!("can not start worker: {:?}", err);
return Err(io::Error::new(
io::ErrorKind::Other,
format!("can not start server service {}", idx),
@@ -436,7 +436,7 @@ impl ServerWorker {
Ok((token, svc)) => services.push((idx, token, svc)),
Err(err) => {
error!("Can not start worker: {:?}", err);
error!("can not start worker: {:?}", err);
Arbiter::current().stop();
factory_tx
.send(Err(io::Error::new(
@@ -476,7 +476,7 @@ impl ServerWorker {
fn restart_service(&mut self, idx: usize, factory_id: usize) {
let factory = &self.factories[factory_id];
trace!("Service {:?} failed, restarting", factory.name(idx));
trace!("service {:?} failed, restarting", factory.name(idx));
self.services[idx].status = WorkerServiceStatus::Restarting;
self.state = WorkerState::Restarting(Restart {
factory_id,
@@ -508,7 +508,7 @@ impl ServerWorker {
Poll::Ready(Ok(_)) => {
if srv.status == WorkerServiceStatus::Unavailable {
trace!(
"Service {:?} is available",
"service {:?} is available",
self.factories[srv.factory_idx].name(idx)
);
srv.status = WorkerServiceStatus::Available;
@@ -519,7 +519,7 @@ impl ServerWorker {
if srv.status == WorkerServiceStatus::Available {
trace!(
"Service {:?} is unavailable",
"service {:?} is unavailable",
self.factories[srv.factory_idx].name(idx)
);
srv.status = WorkerServiceStatus::Unavailable;
@@ -527,7 +527,7 @@ impl ServerWorker {
}
Poll::Ready(Err(_)) => {
error!(
"Service {:?} readiness check returned error, restarting",
"service {:?} readiness check returned error, restarting",
self.factories[srv.factory_idx].name(idx)
);
srv.status = WorkerServiceStatus::Failed;
@@ -585,16 +585,14 @@ impl Future for ServerWorker {
let this = self.as_mut().get_mut();
// `StopWorker` message handler
if let Poll::Ready(Some(Stop { graceful, tx })) =
Pin::new(&mut this.stop_rx).poll_recv(cx)
{
if let Poll::Ready(Some(Stop { graceful, tx })) = this.stop_rx.poll_recv(cx) {
let num = this.counter.total();
if num == 0 {
info!("Shutting down idle worker");
info!("shutting down idle worker");
let _ = tx.send(true);
return Poll::Ready(());
} else if graceful {
info!("Graceful worker shutdown; finishing {} connections", num);
info!("graceful worker shutdown; finishing {} connections", num);
this.shutdown(false);
this.state = WorkerState::Shutdown(Shutdown {
@@ -603,7 +601,7 @@ impl Future for ServerWorker {
tx,
});
} else {
info!("Force shutdown worker, closing {} connections", num);
info!("force shutdown worker, closing {} connections", num);
this.shutdown(true);
let _ = tx.send(false);
@@ -638,7 +636,7 @@ impl Future for ServerWorker {
assert_eq!(token, token_new);
trace!(
"Service {:?} has been restarted",
"service {:?} has been restarted",
this.factories[factory_id].name(token)
);
@@ -649,7 +647,7 @@ impl Future for ServerWorker {
}
WorkerState::Shutdown(ref mut shutdown) => {
// drop all pending connections in rx channel.
while let Poll::Ready(Some(conn)) = Pin::new(&mut this.conn_rx).poll_recv(cx) {
while let Poll::Ready(Some(conn)) = this.conn_rx.poll_recv(cx) {
// WorkerCounterGuard is needed as Accept thread has incremented counter.
// It's guard's job to decrement the counter together with drop of Conn.
let guard = this.counter.guard();
@@ -685,7 +683,7 @@ impl Future for ServerWorker {
match this.check_readiness(cx) {
Ok(true) => {}
Ok(false) => {
trace!("Worker is unavailable");
trace!("worker is unavailable");
this.state = WorkerState::Unavailable;
return self.poll(cx);
}
@@ -696,7 +694,7 @@ impl Future for ServerWorker {
}
// handle incoming io stream
match ready!(Pin::new(&mut this.conn_rx).poll_recv(cx)) {
match ready!(this.conn_rx.poll_recv(cx)) {
Some(msg) => {
let guard = this.counter.guard();
let _ = this.services[msg.token].service.call((guard, msg.io));

View File

@@ -186,9 +186,9 @@ fn test_start() {
#[actix_rt::test]
async fn test_max_concurrent_connections() {
// Note:
// A tcp listener would accept connects based on it's backlog setting.
// A TCP listener would accept connects based on it's backlog setting.
//
// The limit test on the other hand is only for concurrent tcp stream limiting a work
// The limit test on the other hand is only for concurrent TCP stream limiting a work
// thread accept.
use tokio::io::AsyncWriteExt;
@@ -254,6 +254,7 @@ async fn test_max_concurrent_connections() {
h.join().unwrap().unwrap();
}
// TODO: race-y failures detected due to integer underflow when calling Counter::total
#[actix_rt::test]
async fn test_service_restart() {
use std::task::{Context, Poll};

View File

@@ -1,6 +1,7 @@
# Changes
## Unreleased - 2021-xx-xx
## Unreleased - 2022-xx-xx
- Minimum supported Rust version (MSRV) is now 1.59.
## 2.0.2 - 2021-12-18

View File

@@ -4,7 +4,6 @@ version = "2.0.2"
authors = [
"Nikolay Kim <fafhrd91@gmail.com>",
"Rob Ede <robjtede@icloud.com>",
"fakeshadow <24548779@qq.com>",
]
description = "Service trait and combinators for representing asynchronous request/response operations."
keywords = ["network", "framework", "async", "futures", "service"]
@@ -18,11 +17,11 @@ name = "actix_service"
path = "src/lib.rs"
[dependencies]
futures-core = { version = "0.3.7", default-features = false }
futures-core = { version = "0.3.17", default-features = false }
paste = "1"
pin-project-lite = "0.2"
[dev-dependencies]
actix-rt = "2.0.0"
actix-utils = "3.0.0"
futures-util = { version = "0.3.7", default-features = false }
actix-rt = "2"
actix-utils = "3"
futures-util = { version = "0.3.17", default-features = false }

View File

@@ -394,9 +394,10 @@ mod tests {
#[actix_rt::test]
async fn test_auto_impl_send() {
use crate::{map_config, ServiceExt, ServiceFactoryExt};
use alloc::rc::Rc;
use crate::{map_config, ServiceExt, ServiceFactoryExt};
let srv_1 = fn_service(|_: Rc<u8>| ok::<_, Rc<u8>>(Rc::new(0u8)));
let fac_1 = fn_factory_with_config(|_: Rc<u8>| {

View File

@@ -38,10 +38,9 @@ pub use self::apply_cfg::{apply_cfg, apply_cfg_factory};
pub use self::ext::{ServiceExt, ServiceFactoryExt, TransformExt};
pub use self::fn_service::{fn_factory, fn_factory_with_config, fn_service};
pub use self::map_config::{map_config, unit_config};
pub use self::transform::{apply, ApplyTransform, Transform};
#[allow(unused_imports)]
use self::ready::{err, ok, ready, Ready};
pub use self::transform::{apply, ApplyTransform, Transform};
/// An asynchronous operation from `Request` to a `Response`.
///

View File

@@ -25,6 +25,8 @@
/// }
/// }
/// ```
///
/// [`forward_ready!`]: crate::forward_ready
#[macro_export]
macro_rules! always_ready {
() => {

View File

@@ -97,7 +97,7 @@ where
match this.fut.poll(cx) {
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,
}
}

View File

@@ -1,10 +1,31 @@
# Changes
## Unreleased - 2021-xx-xx
## Unreleased - 2022-xx-xx
- Minimum supported Rust version (MSRV) is now 1.59.
## 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
- No significant changes since `3.0.0`.
## 3.0.0 - 2021-12-26
* No significant changes since `3.0.0-rc.2`.
- No significant changes since `3.0.0-rc.2`.
## 3.0.0-rc.2 - 2021-12-10
@@ -12,6 +33,7 @@
[#429]: https://github.com/actix/actix-net/pull/429
## 3.0.0-rc.1 - 2021-11-29
### Added
- Derive `Debug` for `connect::Connection`. [#422]
@@ -117,7 +139,7 @@
[#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]
[#204]: https://github.com/actix/actix-net/pull/204

View File

@@ -1,6 +1,6 @@
[package]
name = "actix-tls"
version = "3.0.0"
version = "3.0.4"
authors = [
"Nikolay Kim <fafhrd91@gmail.com>",
"Rob Ede <robjtede@icloud.com>",
@@ -42,16 +42,16 @@ native-tls = ["tokio-native-tls"]
uri = ["http"]
[dependencies]
actix-codec = "0.4.0"
actix-rt = { version = "2.2.0", default-features = false }
actix-service = "2.0.0"
actix-utils = "3.0.0"
actix-service = "2"
actix-utils = "3"
derive_more = "0.99.5"
futures-core = { version = "0.3.7", default-features = false, features = ["alloc"] }
log = "0.4"
impl-more = "0.1"
pin-project-lite = "0.2.7"
tokio-util = { version = "0.6.3", default-features = false }
tokio = "1.18.4"
tokio-util = "0.7"
tracing = { version = "0.1.30", default-features = false, features = ["log"] }
# uri
http = { version = "0.2.3", optional = true }
@@ -68,16 +68,17 @@ webpki-roots = { version = "0.22", optional = true }
tokio-native-tls = { version = "0.3", optional = true }
[dev-dependencies]
actix-rt = "2.2.0"
actix-server = "2.0.0-rc.2"
actix-codec = "0.5"
actix-rt = "2.2"
actix-server = "2"
bytes = "1"
env_logger = "0.9"
futures-util = { version = "0.3.7", default-features = false, features = ["sink"] }
env_logger = "0.10"
futures-util = { version = "0.3.17", default-features = false, features = ["sink"] }
log = "0.4"
rcgen = "0.8"
rustls-pemfile = "0.2.1"
rcgen = "0.10"
rustls-pemfile = "1"
tokio-rustls = { version = "0.23", features = ["dangerous_configuration"] }
trust-dns-resolver = "0.20.0"
trust-dns-resolver = "0.22"
[[example]]
name = "accept-rustls"

View File

@@ -15,8 +15,9 @@
//! http --verify=false https://127.0.0.1:8443
//! ```
// this use only exists because of how we have organised the crate
// it is not necessary for your actual code
#[rustfmt::skip]
// this `use` is only exists because of how we have organised the crate
// it is not necessary for your actual code; you should import from `rustls` directly
use tokio_rustls::rustls;
use std::{
@@ -34,14 +35,13 @@ use actix_server::Server;
use actix_service::ServiceFactoryExt as _;
use actix_tls::accept::rustls::{Acceptor as RustlsAcceptor, TlsStream};
use futures_util::future::ok;
use log::info;
use rustls::{server::ServerConfig, Certificate, PrivateKey};
use rustls_pemfile::{certs, rsa_private_keys};
use tracing::info;
#[actix_rt::main]
async fn main() -> io::Result<()> {
env::set_var("RUST_LOG", "info");
env_logger::init();
env_logger::init_from_env(env_logger::Env::default().default_filter_or("info"));
// Load TLS key and cert files
let cert_file = &mut BufReader::new(File::open("./examples/cert.pem").unwrap());

View File

@@ -2,11 +2,12 @@
use std::{
convert::Infallible,
error::Error,
fmt,
sync::atomic::{AtomicUsize, Ordering},
};
use actix_utils::counter::Counter;
use derive_more::{Display, Error};
#[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.
///
/// 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,
/// using [`into_service_error`](Self::into_service_error).
#[derive(Debug, Display, Error)]
/// which can be cast to your own service type, inferred or otherwise, using [`into_service_error`].
///
/// [`into_service_error`]: Self::into_service_error
#[derive(Debug)]
pub enum TlsError<TlsErr, SvcErr> {
/// TLS handshake has timed-out.
#[display(fmt = "TLS handshake has timed-out")]
Timeout,
/// Wraps TLS service errors.
#[display(fmt = "TLS handshake error")]
Tls(TlsErr),
/// Wraps service errors.
#[display(fmt = "Service error")]
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> {
/// Casts the infallible service error type returned from acceptors into caller's type.
///

View File

@@ -10,7 +10,6 @@ use std::{
time::Duration,
};
use actix_codec::{AsyncRead, AsyncWrite, ReadBuf};
use actix_rt::{
net::{ActixStream, Ready},
time::timeout,
@@ -20,8 +19,8 @@ use actix_utils::{
counter::Counter,
future::{ready, Ready as FutReady},
};
use derive_more::{Deref, DerefMut, From};
use futures_core::future::LocalBoxFuture;
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
use tokio_native_tls::{native_tls::Error, TlsAcceptor};
use super::{TlsError, DEFAULT_TLS_HANDSHAKE_TIMEOUT, MAX_CONN_COUNTER};
@@ -33,9 +32,11 @@ pub mod reexports {
}
/// 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>);
impl_more::impl_from!(<IO> in tokio_native_tls::TlsStream<IO> => TlsStream<IO>);
impl_more::impl_deref_and_mut!(<IO> in TlsStream<IO> => tokio_native_tls::TlsStream<IO>);
impl<IO: ActixStream> AsyncRead for TlsStream<IO> {
fn poll_read(
self: Pin<&mut Self>,

View File

@@ -11,7 +11,6 @@ use std::{
time::Duration,
};
use actix_codec::{AsyncRead, AsyncWrite, ReadBuf};
use actix_rt::{
net::{ActixStream, Ready},
time::{sleep, Sleep},
@@ -21,9 +20,9 @@ use actix_utils::{
counter::{Counter, CounterGuard},
future::{ready, Ready as FutReady},
};
use derive_more::{Deref, DerefMut, From};
use openssl::ssl::{Error, Ssl, SslAcceptor};
use pin_project_lite::pin_project;
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
use super::{TlsError, DEFAULT_TLS_HANDSHAKE_TIMEOUT, MAX_CONN_COUNTER};
@@ -36,9 +35,11 @@ pub mod reexports {
}
/// Wraps an `openssl` based async TLS stream in order to implement [`ActixStream`].
#[derive(Deref, DerefMut, From)]
pub struct TlsStream<IO>(tokio_openssl::SslStream<IO>);
impl_more::impl_from!(<IO> in tokio_openssl::SslStream<IO> => TlsStream<IO>);
impl_more::impl_deref_and_mut!(<IO> in TlsStream<IO> => tokio_openssl::SslStream<IO>);
impl<IO: ActixStream> AsyncRead for TlsStream<IO> {
fn poll_read(
self: Pin<&mut Self>,

View File

@@ -12,7 +12,6 @@ use std::{
time::Duration,
};
use actix_codec::{AsyncRead, AsyncWrite, ReadBuf};
use actix_rt::{
net::{ActixStream, Ready},
time::{sleep, Sleep},
@@ -22,8 +21,8 @@ use actix_utils::{
counter::{Counter, CounterGuard},
future::{ready, Ready as FutReady},
};
use derive_more::{Deref, DerefMut, From};
use pin_project_lite::pin_project;
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
use tokio_rustls::rustls::ServerConfig;
use tokio_rustls::{Accept, TlsAcceptor};
@@ -36,9 +35,11 @@ pub mod reexports {
}
/// 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>);
impl_more::impl_from!(<IO> in tokio_rustls::server::TlsStream<IO> => TlsStream<IO>);
impl_more::impl_deref_and_mut!(<IO> in TlsStream<IO> => tokio_rustls::server::TlsStream<IO>);
impl<IO: ActixStream> AsyncRead for TlsStream<IO> {
fn poll_read(
self: Pin<&mut Self>,

View File

@@ -1,20 +1,17 @@
use derive_more::{Deref, DerefMut};
use super::Host;
/// Wraps underlying I/O and the connection request that initiated it.
#[derive(Debug, Deref, DerefMut)]
#[derive(Debug)]
pub struct Connection<R, IO> {
pub(crate) req: R,
#[deref]
#[deref_mut]
pub(crate) io: IO,
}
impl_more::impl_deref_and_mut!(<R, IO> in Connection<R, IO> => io: IO);
impl<R, IO> Connection<R, IO> {
/// 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 }
}
}

View File

@@ -1,30 +1,38 @@
use std::{error::Error, io};
use derive_more::Display;
use std::{error::Error, fmt, io};
/// Errors that can result from using a connector service.
#[derive(Debug, Display)]
#[derive(Debug)]
pub enum ConnectError {
/// Failed to resolve the hostname
#[display(fmt = "Failed resolving hostname")]
/// Failed to resolve the hostname.
Resolver(Box<dyn std::error::Error>),
/// No DNS records
#[display(fmt = "No DNS records found for the input")]
/// No DNS records.
NoRecords,
/// Invalid input
/// Invalid input.
InvalidInput,
/// Unresolved host name
#[display(fmt = "Connector received `Connect` method with unresolved host")]
/// Unresolved host name.
Unresolved,
/// Connection IO error
#[display(fmt = "{}", _0)]
/// Connection 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 {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {

View File

@@ -8,11 +8,11 @@ use actix_rt::net::ActixStream;
use actix_service::{Service, ServiceFactory};
use actix_utils::future::{ok, Ready};
use futures_core::future::LocalBoxFuture;
use log::trace;
use tokio_native_tls::{
native_tls::TlsConnector as NativeTlsConnector, TlsConnector as AsyncNativeTlsConnector,
TlsStream as AsyncTlsStream,
};
use tracing::trace;
use crate::connect::{Connection, Host};
@@ -20,7 +20,6 @@ pub mod reexports {
//! Re-exports from `native-tls` and `tokio-native-tls` that are useful for connectors.
pub use tokio_native_tls::native_tls::TlsConnector;
pub use tokio_native_tls::TlsStream as AsyncTlsStream;
}
@@ -75,16 +74,16 @@ where
let connector = self.connector.clone();
Box::pin(async move {
trace!("SSL Handshake start for: {:?}", stream.hostname());
trace!("TLS handshake start for: {:?}", stream.hostname());
connector
.connect(stream.hostname(), io)
.await
.map(|res| {
trace!("SSL Handshake success: {:?}", stream.hostname());
trace!("TLS handshake success: {:?}", stream.hostname());
stream.replace_io(res).1
})
.map_err(|e| {
trace!("SSL Handshake error: {:?}", e);
trace!("TLS handshake error: {:?}", e);
io::Error::new(io::ErrorKind::Other, format!("{}", e))
})
})

View File

@@ -13,9 +13,9 @@ use actix_rt::net::ActixStream;
use actix_service::{Service, ServiceFactory};
use actix_utils::future::{ok, Ready};
use futures_core::ready;
use log::trace;
use openssl::ssl::SslConnector;
use tokio_openssl::SslStream as AsyncSslStream;
use tracing::trace;
use crate::connect::{Connection, Host};
@@ -25,7 +25,6 @@ pub mod reexports {
pub use openssl::ssl::{
Error, HandshakeError, SslConnector, SslConnectorBuilder, SslMethod,
};
pub use tokio_openssl::SslStream as AsyncSslStream;
}
@@ -98,7 +97,8 @@ where
actix_service::always_ready!();
fn call(&self, stream: Connection<R, IO>) -> Self::Future {
trace!("SSL Handshake start for: {:?}", stream.hostname());
trace!("TLS handshake start for: {:?}", stream.hostname());
let (io, stream) = stream.replace_io(());
let host = stream.hostname();
@@ -138,12 +138,15 @@ where
match ready!(Pin::new(this.io.as_mut().unwrap()).poll_connect(cx)) {
Ok(_) => {
let stream = this.stream.take().unwrap();
trace!("SSL Handshake success: {:?}", stream.hostname());
trace!("TLS handshake success: {:?}", stream.hostname());
Poll::Ready(Ok(stream.replace_io(this.io.take().unwrap()).1))
}
Err(e) => {
trace!("SSL Handshake error: {:?}", e);
Poll::Ready(Err(io::Error::new(io::ErrorKind::Other, format!("{}", e))))
Err(err) => {
trace!("TLS handshake error: {:?}", err);
Poll::Ready(Err(io::Error::new(
io::ErrorKind::Other,
format!("{}", err),
)))
}
}
}

View File

@@ -12,7 +12,7 @@ use actix_rt::task::{spawn_blocking, JoinHandle};
use actix_service::{Service, ServiceFactory};
use actix_utils::future::{ok, Ready};
use futures_core::{future::LocalBoxFuture, ready};
use log::trace;
use tracing::trace;
use super::{ConnectError, ConnectInfo, Host, Resolve};
@@ -164,8 +164,8 @@ impl<R: Host> Future for ResolverFut<R> {
Self::LookUp(fut, req) => {
let res = match ready!(Pin::new(fut).poll(cx)) {
Ok(Ok(res)) => Ok(res),
Ok(Err(e)) => Err(ConnectError::Resolver(Box::new(e))),
Err(e) => Err(ConnectError::Io(e.into())),
Ok(Err(err)) => Err(ConnectError::Resolver(Box::new(err))),
Err(err) => Err(ConnectError::Io(err.into())),
};
let req = req.take().unwrap();

View File

@@ -15,10 +15,10 @@ use actix_rt::net::ActixStream;
use actix_service::{Service, ServiceFactory};
use actix_utils::future::{ok, Ready};
use futures_core::ready;
use log::trace;
use tokio_rustls::rustls::{client::ServerName, OwnedTrustAnchor, RootCertStore};
use tokio_rustls::{client::TlsStream as AsyncTlsStream, rustls::ClientConfig};
use tokio_rustls::{Connect as RustlsConnect, TlsConnector as RustlsTlsConnector};
use tracing::trace;
use webpki_roots::TLS_SERVER_ROOTS;
use crate::connect::{Connection, Host};
@@ -26,10 +26,8 @@ use crate::connect::{Connection, Host};
pub mod reexports {
//! Re-exports from `rustls` and `webpki_roots` that are useful for connectors.
pub use tokio_rustls::rustls::ClientConfig;
pub use tokio_rustls::client::TlsStream as AsyncTlsStream;
pub use tokio_rustls::rustls::ClientConfig;
pub use webpki_roots::TLS_SERVER_ROOTS;
}
@@ -103,7 +101,7 @@ where
actix_service::always_ready!();
fn call(&self, connection: Connection<R, IO>) -> Self::Future {
trace!("SSL Handshake start for: {:?}", connection.hostname());
trace!("TLS handshake start for: {:?}", connection.hostname());
let (stream, connection) = connection.replace_io(());
match ServerName::try_from(connection.hostname()) {
@@ -142,7 +140,7 @@ where
Self::Future { connect, connection } => {
let stream = ready!(Pin::new(connect).poll(cx))?;
let connection = connection.take().unwrap();
trace!("SSL Handshake success: {:?}", connection.hostname());
trace!("TLS handshake success: {:?}", connection.hostname());
Poll::Ready(Ok(connection.replace_io(stream).1))
}
}

View File

@@ -15,8 +15,8 @@ use actix_rt::net::{TcpSocket, TcpStream};
use actix_service::{Service, ServiceFactory};
use actix_utils::future::{ok, Ready};
use futures_core::ready;
use log::{error, trace};
use tokio_util::sync::ReusableBoxFuture;
use tracing::{error, trace};
use super::{connect_addrs::ConnectAddrs, error::ConnectError, ConnectInfo, Connection, Host};
@@ -79,7 +79,7 @@ pub enum TcpConnectorFut<R> {
port: u16,
local_addr: Option<IpAddr>,
addrs: Option<VecDeque<SocketAddr>>,
stream: ReusableBoxFuture<Result<TcpStream, io::Error>>,
stream: ReusableBoxFuture<'static, Result<TcpStream, io::Error>>,
},
Error(Option<ConnectError>),
@@ -114,8 +114,8 @@ impl<R: Host> TcpConnectorFut<R> {
stream: ReusableBoxFuture::new(connect(addr, local_addr)),
},
// when resolver returns multiple socket addr for request they would be popped from
// front end of queue and returns with the first successful tcp connection.
// When resolver returns multiple socket addr for request they would be popped from
// front end of queue and returns with the first successful TCP connection.
ConnectAddrs::Multi(mut addrs) => {
let addr = addrs.pop_front().unwrap();

View File

@@ -51,13 +51,13 @@ fn openssl_acceptor(cert: String, key: String) -> tls_openssl::ssl::SslAcceptor
mod danger {
use std::time::SystemTime;
use super::*;
use tokio_rustls::rustls::{
self,
client::{ServerCertVerified, ServerCertVerifier},
};
use super::*;
pub struct NoCertificateVerification;
impl ServerCertVerifier for NoCertificateVerification {

View File

@@ -9,11 +9,10 @@ use actix_codec::{BytesCodec, Framed};
use actix_rt::net::TcpStream;
use actix_server::TestServer;
use actix_service::{fn_service, Service, ServiceFactory};
use actix_tls::connect::{ConnectError, ConnectInfo, Connection, Connector, Host};
use bytes::Bytes;
use futures_util::sink::SinkExt;
use actix_tls::connect::{ConnectError, ConnectInfo, Connection, Connector, Host};
#[cfg(feature = "openssl")]
#[actix_rt::test]
async fn test_string() {
@@ -144,6 +143,9 @@ async fn test_local_addr() {
})
});
// if you've arrived here because of a failing test on macOS run this in your terminal:
// sudo ifconfig lo0 alias 127.0.0.3
let conn = Connector::default().service();
let local = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 3));

View File

@@ -8,11 +8,10 @@ use std::{
use actix_rt::net::TcpStream;
use actix_server::TestServer;
use actix_service::{fn_service, Service, ServiceFactory};
use futures_core::future::LocalBoxFuture;
use actix_tls::connect::{
ConnectError, ConnectInfo, Connection, Connector, Host, Resolve, Resolver,
};
use futures_core::future::LocalBoxFuture;
#[actix_rt::test]
async fn custom_resolver() {

View File

@@ -1,5 +1,8 @@
# Changes
## [0.1.0] - 2020-01-15
## Unreleased - 2022-xx-xx
- Minimum supported Rust version (MSRV) is now 1.59.
## 0.1.0 - 2020-01-15
- Initial release

View File

@@ -16,12 +16,12 @@ name = "actix_tracing"
path = "src/lib.rs"
[dependencies]
actix-service = "2.0.0"
actix-utils = "3.0.0"
actix-service = "2"
actix-utils = "3"
tracing = "0.1"
tracing = "0.1.35"
tracing-futures = "0.2"
[dev_dependencies]
actix-rt = "2.0.0"
actix-rt = "2"
slab = "0.4"

View File

@@ -118,8 +118,6 @@ where
#[cfg(test)]
mod test {
use super::*;
use std::cell::RefCell;
use std::collections::{BTreeMap, BTreeSet};
use std::sync::{Arc, RwLock};
@@ -128,6 +126,8 @@ mod test {
use slab::Slab;
use tracing::{span, Event, Level, Metadata, Subscriber};
use super::*;
thread_local! {
static SPAN: RefCell<Vec<span::Id>> = RefCell::new(Vec::new());
}

View File

@@ -1,6 +1,11 @@
# Changes
## Unreleased - 2021-xx-xx
## Unreleased - 2022-xx-xx
- Minimum supported Rust version (MSRV) is now 1.59.
## 3.0.1 - 2022-10-21
- Minimum supported Rust version (MSRV) is now 1.57.
## 3.0.0 - 2021-04-16

View File

@@ -1,6 +1,6 @@
[package]
name = "actix-utils"
version = "3.0.0"
version = "3.0.1"
authors = [
"Nikolay Kim <fafhrd91@gmail.com>",
"Rob Ede <robjtede@icloud.com>",
@@ -21,6 +21,6 @@ pin-project-lite = "0.2"
local-waker = "0.1"
[dev-dependencies]
actix-rt = "2.0.0"
futures-util = { version = "0.3.7", default-features = false }
actix-rt = "2"
futures-util = { version = "0.3.17", default-features = false }
static_assertions = "1.1"

View File

@@ -1,4 +1,4 @@
//! Asynchronous values.
//! Helpers for constructing futures.
mod either;
mod poll_fn;

View File

@@ -8,6 +8,31 @@ use core::{
};
/// Creates a future driven by the provided function that receives a task context.
///
/// # Examples
/// ```
/// # use std::task::Poll;
/// # use actix_utils::future::poll_fn;
/// # async fn test_poll_fn() {
/// let res = poll_fn(|_| Poll::Ready(42)).await;
/// assert_eq!(res, 42);
///
/// let mut i = 5;
/// let res = poll_fn(|cx| {
/// i -= 1;
///
/// if i > 0 {
/// cx.waker().wake_by_ref();
/// Poll::Pending
/// } else {
/// Poll::Ready(42)
/// }
/// })
/// .await;
/// assert_eq!(res, 42);
/// # }
/// # actix_rt::Runtime::new().unwrap().block_on(test_poll_fn());
/// ```
#[inline]
pub fn poll_fn<F, T>(f: F) -> PollFn<F>
where
@@ -16,13 +41,11 @@ where
PollFn { f }
}
/// A Future driven by the inner function.
/// Future for the [`poll_fn`] function.
pub struct PollFn<F> {
f: F,
}
impl<F> Unpin for PollFn<F> {}
impl<F> fmt::Debug for PollFn<F> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("PollFn").finish()
@@ -36,15 +59,22 @@ where
type Output = T;
#[inline]
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
(self.f)(cx)
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
// SAFETY: we are not moving out of the pinned field
// see https://github.com/rust-lang/rust/pull/102737
(unsafe { &mut self.get_unchecked_mut().f })(cx)
}
}
#[cfg(test)]
mod tests {
use std::marker::PhantomPinned;
use super::*;
static_assertions::assert_impl_all!(PollFn<()>: Unpin);
static_assertions::assert_not_impl_all!(PollFn<PhantomPinned>: Unpin);
#[actix_rt::test]
async fn test_poll_fn() {
let res = poll_fn(|_| Poll::Ready(42)).await;
@@ -64,4 +94,29 @@ mod tests {
.await;
assert_eq!(res, 42);
}
// following soundness tests taken from https://github.com/tokio-rs/tokio/pull/5087
#[allow(dead_code)]
fn require_send<T: Send>(_t: &T) {}
#[allow(dead_code)]
fn require_sync<T: Sync>(_t: &T) {}
trait AmbiguousIfUnpin<A> {
fn some_item(&self) {}
}
impl<T: ?Sized> AmbiguousIfUnpin<()> for T {}
impl<T: ?Sized + Unpin> AmbiguousIfUnpin<[u8; 0]> for T {}
const _: fn() = || {
let pinned = std::marker::PhantomPinned;
let f = poll_fn(move |_| {
// Use `pinned` to take ownership of it.
let _ = &pinned;
std::task::Poll::Pending::<()>
});
require_send(&f);
require_sync(&f);
AmbiguousIfUnpin::some_item(&f);
};
}

View File

@@ -1,4 +1,4 @@
//! When MSRV is 1.48, replace with `core::future::Ready` and `core::future::ready()`.
//! When `core::future::Ready` has a `into_inner()` method, this can be deprecated.
use core::{
future::Future,
@@ -6,7 +6,7 @@ use core::{
task::{Context, Poll},
};
/// Future for the [`ready`](ready()) function.
/// Future for the [`ready`] function.
///
/// Panic will occur if polled more than once.
///

View File

@@ -1,6 +1,28 @@
# Changes
## Unreleased - 2021-xx-xx
## Unreleased - 2022-xx-xx
- Minimum supported Rust version (MSRV) is now 1.59.
## 1.2.1 - 2022-11-12
- Fix `#[no_std]` compatibility. [#471]
[#471]: https://github.com/actix/actix-net/pull/471
## 1.2.0 - 2022-11-07
- Add `ByteString::slice_ref` which can safely slice a `ByteString` into a new one with zero copy. [#470]
- Minimum supported Rust version (MSRV) is now 1.57.
[#470]: https://github.com/actix/actix-net/pull/470
## 1.1.0 - 2022-06-11
- Implement `From<Box<str>>` for `ByteString`. [#458]
- Implement `Into<String>` for `ByteString`. [#458]
- Minimum supported Rust version (MSRV) is now 1.49.
[#458]: https://github.com/actix/actix-net/pull/458
## 1.0.0 - 2020-12-31

View File

@@ -1,6 +1,6 @@
[package]
name = "bytestring"
version = "1.0.0"
version = "1.2.1"
authors = [
"Nikolay Kim <fafhrd91@gmail.com>",
"Rob Ede <robjtede@icloud.com>",
@@ -18,11 +18,11 @@ name = "bytestring"
path = "src/lib.rs"
[dependencies]
bytes = "1"
bytes = { version = "1.2", default-features = false }
serde = { version = "1.0", optional = true }
[dev-dependencies]
ahash = { version = "0.7.6", default-features = false }
ahash = { version = "0.8", default-features = false }
serde_json = "1.0"
static_assertions = "1.1"
rustversion = "1"

View File

@@ -6,7 +6,11 @@
extern crate alloc;
use alloc::{string::String, vec::Vec};
use alloc::{
boxed::Box,
string::{String, ToString},
vec::Vec,
};
use core::{borrow, convert::TryFrom, fmt, hash, ops, str};
use bytes::Bytes;
@@ -46,6 +50,33 @@ impl ByteString {
pub const unsafe fn from_bytes_unchecked(src: Bytes) -> ByteString {
Self(src)
}
/// Returns a byte string that is equivalent to the given `subset`.
///
/// When processing a `ByteString` buffer with other tools, one often gets a `&str` which is in
/// fact a slice of the `ByteString`; i.e., a subset of it. This function turns that `&str` into
/// another `ByteString`, as if one had sliced the `ByteString` with the offsets that correspond
/// to `subset`.
///
/// Corresponds to [`Bytes::slice_ref`].
///
/// This operation is `O(1)`.
///
/// # Panics
/// Requires that the given `subset` str is in fact contained within the `ByteString` buffer;
/// otherwise this function will panic.
///
/// # Examples
/// ```
/// # use bytestring::ByteString;
/// let string = ByteString::from_static(" foo ");
/// let subset = string.trim();
/// let substring = string.slice_ref(subset);
/// assert_eq!(substring, "foo");
/// ```
pub fn slice_ref(&self, subset: &str) -> Self {
Self(self.0.slice_ref(subset.as_bytes()))
}
}
impl PartialEq<str> for ByteString {
@@ -68,7 +99,7 @@ impl AsRef<[u8]> for ByteString {
impl AsRef<str> for ByteString {
fn as_ref(&self) -> &str {
&*self
self
}
}
@@ -92,7 +123,7 @@ impl ops::Deref for ByteString {
impl borrow::Borrow<str> for ByteString {
fn borrow(&self) -> &str {
&*self
self
}
}
@@ -110,6 +141,20 @@ impl From<&str> for ByteString {
}
}
impl From<Box<str>> for ByteString {
#[inline]
fn from(value: Box<str>) -> Self {
Self(Bytes::from(value.into_boxed_bytes()))
}
}
impl From<ByteString> for String {
#[inline]
fn from(value: ByteString) -> Self {
value.to_string()
}
}
impl TryFrom<&[u8]> for ByteString {
type Error = str::Utf8Error;
@@ -219,11 +264,11 @@ mod serde {
#[cfg(test)]
mod serde_impl_tests {
use super::*;
use serde::de::DeserializeOwned;
use static_assertions::assert_impl_all;
use super::*;
assert_impl_all!(ByteString: Serialize, DeserializeOwned);
}
}
@@ -331,4 +376,10 @@ mod test {
let s = serde_json::to_string(&ByteString::from_static("nice bytes")).unwrap();
assert_eq!(s, r#""nice bytes""#);
}
#[test]
#[should_panic]
fn test_slice_ref_catches_not_a_subset() {
ByteString::from_static("foo bar").slice_ref("foo");
}
}

View File

@@ -1 +1 @@
msrv = "1.48"
msrv = "1.59"

View File

@@ -1,6 +1,11 @@
# Changes
## Unreleased - 2021-xx-xx
## Unreleased - 2022-xx-xx
- Minimum supported Rust version (MSRV) is now 1.59.
## 0.1.3 - 2022-05-03
- Minimum supported Rust version (MSRV) is now 1.49.
## 0.1.2 - 2021-04-01

View File

@@ -1,6 +1,6 @@
[package]
name = "local-channel"
version = "0.1.2"
version = "0.1.3"
description = "A non-threadsafe multi-producer, single-consumer, futures-aware, FIFO queue"
authors = [
"Nikolay Kim <fafhrd91@gmail.com>",
@@ -12,10 +12,10 @@ license = "MIT OR Apache-2.0"
edition = "2018"
[dependencies]
futures-core = { version = "0.3.7", default-features = false }
futures-sink = { version = "0.3.7", default-features = false }
futures-util = { version = "0.3.7", default-features = false }
futures-core = "0.3.17"
futures-sink = "0.3.17"
futures-util = { version = "0.3.17", default-features = false }
local-waker = "0.1"
[dev-dependencies]
tokio = { version = "1.5.1", features = ["rt", "macros"] }
tokio = { version = "1.18.4", features = ["rt", "macros"] }

View File

@@ -0,0 +1 @@
../LICENSE-APACHE

1
local-channel/LICENSE-MIT Symbolic link
View File

@@ -0,0 +1 @@
../LICENSE-MIT

View File

@@ -1,6 +1,11 @@
# Changes
## Unreleased - 2021-xx-xx
## Unreleased - 2022-xx-xx
- Minimum supported Rust version (MSRV) is now 1.59.
## 0.1.3 - 2022-05-03
- Minimum supported Rust version (MSRV) is now 1.49.
## 0.1.2 - 2021-12-18

View File

@@ -1,13 +1,13 @@
[package]
name = "local-waker"
version = "0.1.2"
version = "0.1.3"
description = "A synchronization primitive for thread-local task wakeup"
authors = [
"Nikolay Kim <fafhrd91@gmail.com>",
"Rob Ede <robjtede@icloud.com>",
]
keywords = ["waker", "local", "futures", "no-std"]
repository = "https://github.com/actix/actix-net.git"
keywords = ["waker", "local", "futures", "no-std"]
categories = ["asynchronous", "no-std"]
license = "MIT OR Apache-2.0"
edition = "2018"

1
local-waker/LICENSE-APACHE Symbolic link
View File

@@ -0,0 +1 @@
../LICENSE-APACHE

1
local-waker/LICENSE-MIT Symbolic link
View File

@@ -0,0 +1 @@
../LICENSE-MIT

View File

@@ -1,2 +1,2 @@
max_width = 96
reorder_imports = true
group_imports = "StdExternalCrate"