generated from ewpratten/rust-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Multi-Queue support for
easy-tun
- Loading branch information
Showing
7 changed files
with
244 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
use easy_tun::Tun; | ||
use std::io::Read; | ||
|
||
use easy_tun::Tun; | ||
|
||
fn main() { | ||
// Enable logs | ||
env_logger::init(); | ||
|
||
// Bring up a TUN interface | ||
let mut tun = Tun::new("tun%d").unwrap(); | ||
let mut tun = Tun::new("tun%d", 1).unwrap(); | ||
Check warning on line 10 in libs/easy-tun/examples/print_traffic.rs GitHub Actions / Build & Test (x86_64-unknown-linux-musl, stable)
|
||
|
||
// Loop and read from the interface | ||
let mut buffer = [0u8; 1500]; | ||
loop { | ||
let length = tun.read(&mut buffer).unwrap(); | ||
let length = tun.fd(0).unwrap().read(&mut buffer).unwrap(); | ||
println!("{:?}", &buffer[..length]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use std::{io::Read, sync::Arc}; | ||
|
||
use easy_tun::Tun; | ||
|
||
fn main() { | ||
// Enable logs | ||
env_logger::init(); | ||
|
||
// Bring up a TUN interface | ||
let tun = Arc::new(Tun::new("tun%d", 5).unwrap()); | ||
|
||
// Spawn 5 threads to read from the interface | ||
let mut threads = Vec::new(); | ||
for i in 0..5 { | ||
let tun = Arc::clone(&tun); | ||
threads.push(std::thread::spawn(move || { | ||
let mut buffer = [0u8; 1500]; | ||
loop { | ||
let length = tun.fd(i).unwrap().read(&mut buffer).unwrap(); | ||
println!("Queue #{}: {:?}", i, &buffer[..length]); | ||
} | ||
})); | ||
} | ||
|
||
// Wait for all threads to finish | ||
for thread in threads { | ||
thread.join().unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
33e3dae
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Binary sizes for
x86_64-unknown-linux-musl
Channel:
stable
33e3dae
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Binary sizes for
aarch64-unknown-linux-musl
Channel:
stable