Skip to content

Commit

Permalink
async implement
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrlive committed Aug 30, 2024
1 parent 634a711 commit 8de6120
Show file tree
Hide file tree
Showing 10 changed files with 532 additions and 65 deletions.
40 changes: 16 additions & 24 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

name: CI
on: [push, pull_request]

Expand All @@ -11,7 +10,7 @@ jobs:
matrix:
rust: [stable, beta, nightly]
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4
- name: Build & Test
if: ${{ !cancelled() }}
run: |
Expand All @@ -25,7 +24,7 @@ jobs:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4
- name: Rustfmt Check
run: |
rustup update stable && rustup default stable && rustup component add rustfmt
Expand All @@ -35,30 +34,23 @@ jobs:
name: Clippy Check & Build
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add clippy
- uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-features -- -D warnings
- uses: actions-rs/cargo@v1
with:
command: build
args: --examples --all-features
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: run clippy and check
shell: bash
run: |
cargo clippy --all-features -- -D warnings
cargo check -- -D warnings
- name: build examples
shell: bash
run: |
cargo build --examples
cargo build --examples --all-features
semver:
name: Check semver
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: obi1kenobi/cargo-semver-checks-action@v2
12 changes: 11 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ targets = [

[features]
default = []
# default = ["verify_binary_signature", "panic_on_unsent_packets"]
# default = ["verify_binary_signature", "panic_on_unsent_packets", "async"]
async = ["async-task", "blocking", "futures"]
panic_on_unsent_packets = []
verify_binary_signature = []

[dependencies]
async-task = { version = "4", optional = true }
blocking = { version = "1", optional = true }
c2rust-bitfields = "0.18"
futures = { version = "0.3", optional = true }
libloading = "0.8"
log = "0.4"
thiserror = "1"
Expand Down Expand Up @@ -59,3 +63,9 @@ packet = "0.1"
pcap-file = "2"
serde_json = "1"
subprocess = "0.2"
tokio = { version = "1", features = ["full"] }

[[example]]
name = "udp-echo-async"
path = "examples/udp-echo-async.rs"
required-features = ["async"]
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,19 @@ wintun's internal ring buffer.

- `verify_binary_signature`: Verifies the signature of the wintun dll file before loading it.

## TODO:
- Add async support
Requires hooking into a windows specific reactor and registering read interest on wintun's read
handle. Asyncify other slow operations via tokio::spawn_blocking. As always, PR's are welcome!

- `async`: Enables async support for the library.
Just add `async` feature to your `Cargo.toml`:
```toml
[dependencies]
wintun-bindings = { version = "0.1", features = ["async"] }
```
And simply transform your `Session` into an `AsyncSession`:
```rust
// ...
let session = Arc::new(adapter.start_session(MAX_RING_CAPACITY)?);
let mut reader_session = AsyncSession::from(session.clone());
let mut writer_session: AsyncSession = session.clone().into();
// ...
```

License: MIT
Loading

0 comments on commit 8de6120

Please sign in to comment.