service (#11)
All checks were successful
Release Tagging / release (push) Successful in 43s
Rust Build / Check (pull_request) Successful in 36s
Rust Build / Check (push) Successful in 44s
Rust Build / Test Suite (push) Successful in 40s
Rust Build / Rustfmt (push) Successful in 34s
Rust Build / Clippy (push) Successful in 37s
Rust Build / build (push) Successful in 1m11s
Rust Build / Test Suite (pull_request) Successful in 37s
Rust Build / Rustfmt (pull_request) Successful in 30s
Rust Build / Clippy (pull_request) Successful in 36s
Rust Build / build (pull_request) Successful in 38s
All checks were successful
Release Tagging / release (push) Successful in 43s
Rust Build / Check (pull_request) Successful in 36s
Rust Build / Check (push) Successful in 44s
Rust Build / Test Suite (push) Successful in 40s
Rust Build / Rustfmt (push) Successful in 34s
Rust Build / Clippy (push) Successful in 37s
Rust Build / build (push) Successful in 1m11s
Rust Build / Test Suite (pull_request) Successful in 37s
Rust Build / Rustfmt (pull_request) Successful in 30s
Rust Build / Clippy (pull_request) Successful in 36s
Rust Build / build (pull_request) Successful in 38s
Reviewed-on: #11 Co-authored-by: phoenix <kundeng94@gmail.com> Co-committed-by: phoenix <kundeng94@gmail.com>
This commit is contained in:
@@ -4,4 +4,5 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
tokio = { version = "1.44.1", features = ["full"] }
|
||||
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.2.0" }
|
||||
|
39
src/main.rs
39
src/main.rs
@@ -1,3 +1,38 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use std::error::Error;
|
||||
use tokio::io::AsyncReadExt;
|
||||
use tokio::net::{TcpListener, TcpStream};
|
||||
use tokio::spawn;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
let listener = TcpListener::bind("127.0.0.1:8080").await?;
|
||||
println!("API calling service listening on 127.0.0.1:8080");
|
||||
|
||||
loop {
|
||||
let (stream, addr) = listener.accept().await?;
|
||||
println!("Accepted connection from: {}", addr);
|
||||
|
||||
spawn(async move {
|
||||
if let Err(e) = handle_connection(stream).await {
|
||||
eprintln!("Error handling connection from {}: {}", addr, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async fn handle_connection(mut stream: TcpStream) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
let mut buffer = [0; 1024];
|
||||
|
||||
loop {
|
||||
let n = stream.read(&mut buffer).await?;
|
||||
|
||||
if n == 0 {
|
||||
break; // Connection closed
|
||||
}
|
||||
|
||||
let request_data = String::from_utf8_lossy(&buffer[..n]).trim().to_string();
|
||||
println!("Received request: {}", request_data);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user