diff --git a/services/shellchat/Cargo.toml b/services/shellchat/Cargo.toml index 5ddd91e5d..e4286bb19 100644 --- a/services/shellchat/Cargo.toml +++ b/services/shellchat/Cargo.toml @@ -54,6 +54,9 @@ spectrum-analyzer = "0.5.2" # used to parse net connectivity results com_rs-ref = {path = "../../imports/com_rs-ref"} +# for net testing +threadpool = "1.8.1" + # for the curve25519 tests # hardware acceleration adaptations are inserted into a fork of the main branch. rand_core = "0.5.1" diff --git a/services/shellchat/src/cmds/net_cmd.rs b/services/shellchat/src/cmds/net_cmd.rs index 39d85f2ec..4dca156c6 100644 --- a/services/shellchat/src/cmds/net_cmd.rs +++ b/services/shellchat/src/cmds/net_cmd.rs @@ -149,6 +149,46 @@ impl<'a> ShellCmdApi<'a> for NetCmd { }); write!(ret, "TCP listener started on port 80").unwrap(); } + "fountain" => { + thread::spawn({ + move || { + let tp = threadpool::ThreadPool::new(4); + loop { + let listener = std::net::TcpListener::bind("0.0.0.0:3333"); + let listener = match listener { + Ok(listener) => listener, + Err(_) => { + std::thread::sleep(std::time::Duration::from_millis(1000)); + continue; + }, + }; + + for i in listener.incoming() { + match i { + Err(error) => { + log::error!("error caught in listener.incoming(): {}", error); + }, + Ok(mut stream) => { + tp.execute(move || { + let mut count = 0; + loop { + match std::io::Write::write(&mut stream, format!("hello! {}\n", count).as_bytes()) { + Err(e) => { + log::info!("fountain write failed with error {:?}", e); + } + _ => {} + } + count += 1; + } + }); + } + } + } + } + } + }); + write!(ret, "Fountain started on port 3333").unwrap(); + } // Testing of udp is done with netcat: // to send packets run `netcat -u 6502` on a remote host, and then type some data // to receive packets, use `netcat -u -l 6502`, on the same remote host, and it should show a packet of counts received