forked from yutiansut/qatrader-rs
-
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.
- Loading branch information
Showing
16 changed files
with
291 additions
and
211 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,36 @@ | ||
pub mod qaasynctest; | ||
|
||
use tokio::net::TcpListener; | ||
use tokio::prelude::*; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let addr = "127.0.0.1:8080".parse()?; | ||
let mut listener = TcpListener::bind(&addr).unwrap(); | ||
|
||
loop { | ||
let (mut socket, _) = listener.accept().await?; | ||
|
||
tokio::spawn(async move { | ||
let mut buf = [0; 1024]; | ||
|
||
// In a loop, read data from the socket and write the data back. | ||
loop { | ||
let n = match socket.read(&mut buf).await { | ||
// socket closed | ||
Ok(n) if n == 0 => return, | ||
Ok(n) => n, | ||
Err(e) => { | ||
println!("failed to read from socket; err = {:?}", e); | ||
return; | ||
} | ||
}; | ||
|
||
// Write the data back | ||
if let Err(e) = socket.write_all(&buf[0..n]).await { | ||
println!("failed to write to socket; err = {:?}", e); | ||
return; | ||
} | ||
} | ||
}); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.