-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
97 additions
and
0 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 |
---|---|---|
|
@@ -5,6 +5,7 @@ members = [ | |
"xtask", | ||
] | ||
exclude = [ | ||
"extras/bench-server", | ||
"extras/esp-wifishark", | ||
] | ||
resolver = "2" | ||
|
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 @@ | ||
/target |
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,8 @@ | ||
[package] | ||
name = "bench-server" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
pretty_env_logger = "0.5.0" | ||
log = "0.4.0" |
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,87 @@ | ||
use std::io::{Read, Write}; | ||
use std::net::{TcpListener, TcpStream}; | ||
use std::thread::spawn; | ||
use std::time::Duration; | ||
|
||
use log::info; | ||
|
||
fn main() { | ||
pretty_env_logger::init(); | ||
spawn(|| rx_listen()); | ||
spawn(|| rxtx_listen()); | ||
tx_listen(); | ||
} | ||
|
||
fn tx_listen() { | ||
let listener = TcpListener::bind("0.0.0.0:4321").unwrap(); | ||
loop { | ||
let (socket, addr) = listener.accept().unwrap(); | ||
info!("tx: received connection from: {}", addr); | ||
spawn(|| tx_conn(socket)); | ||
} | ||
} | ||
|
||
fn tx_conn(mut socket: TcpStream) { | ||
socket.set_read_timeout(Some(Duration::from_secs(30))).unwrap(); | ||
socket.set_write_timeout(Some(Duration::from_secs(30))).unwrap(); | ||
|
||
let buf = [0; 1024]; | ||
loop { | ||
if let Err(e) = socket.write_all(&buf) { | ||
info!("tx: failed to write to socket; err = {:?}", e); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
fn rx_listen() { | ||
let listener = TcpListener::bind("0.0.0.0:4322").unwrap(); | ||
loop { | ||
let (socket, addr) = listener.accept().unwrap(); | ||
info!("rx: received connection from: {}", addr); | ||
spawn(|| rx_conn(socket)); | ||
} | ||
} | ||
|
||
fn rx_conn(mut socket: TcpStream) { | ||
socket.set_read_timeout(Some(Duration::from_secs(30))).unwrap(); | ||
socket.set_write_timeout(Some(Duration::from_secs(30))).unwrap(); | ||
|
||
let mut buf = [0; 1024]; | ||
loop { | ||
if let Err(e) = socket.read_exact(&mut buf) { | ||
info!("rx: failed to read from socket; err = {:?}", e); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
fn rxtx_listen() { | ||
let listener = TcpListener::bind("0.0.0.0:4323").unwrap(); | ||
loop { | ||
let (socket, addr) = listener.accept().unwrap(); | ||
info!("rxtx: received connection from: {}", addr); | ||
spawn(|| rxtx_conn(socket)); | ||
} | ||
} | ||
|
||
fn rxtx_conn(mut socket: TcpStream) { | ||
socket.set_read_timeout(Some(Duration::from_secs(30))).unwrap(); | ||
socket.set_write_timeout(Some(Duration::from_secs(30))).unwrap(); | ||
|
||
let mut buf = [0; 1024]; | ||
loop { | ||
match socket.read(&mut buf) { | ||
Ok(n) => { | ||
if let Err(e) = socket.write_all(&buf[..n]) { | ||
info!("rxtx: failed to write to socket; err = {:?}", e); | ||
return; | ||
} | ||
} | ||
Err(e) => { | ||
info!("rxtx: failed to read from socket; err = {:?}", e); | ||
return; | ||
} | ||
} | ||
} | ||
} |