Renaming
This commit is contained in:
parent
4b517ae5a5
commit
795dc9ae5c
6 changed files with 80 additions and 0 deletions
1
problem_00/.dockerignore
Normal file
1
problem_00/.dockerignore
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
/target/
|
||||||
1
problem_00/.gitignore
vendored
Normal file
1
problem_00/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
/target/
|
||||||
9
problem_00/Cargo.toml
Normal file
9
problem_00/Cargo.toml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
[package]
|
||||||
|
name = "problem_00"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
env_logger = "0.9.0"
|
||||||
|
log = "0.4.0"
|
||||||
|
tokio = { version = "1.27.0", features = ["full"] }
|
||||||
11
problem_00/Dockerfile
Normal file
11
problem_00/Dockerfile
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
FROM rust:latest as builder
|
||||||
|
RUN apt-get update && apt-get -y install ca-certificates cmake musl-tools libssl-dev && rm -rf /var/lib/apt/lists/*
|
||||||
|
COPY . .
|
||||||
|
RUN rustup default stable && rustup update
|
||||||
|
RUN rustup target add x86_64-unknown-linux-musl
|
||||||
|
ENV PKG_CONFIG_ALLOW_CROSS=1
|
||||||
|
RUN cargo build --target x86_64-unknown-linux-musl --release
|
||||||
|
FROM scratch
|
||||||
|
COPY --from=builder /target/x86_64-unknown-linux-musl/release/problem_00 .
|
||||||
|
EXPOSE 8080
|
||||||
|
CMD ["/problem_00"]
|
||||||
20
problem_00/fly.toml
Normal file
20
problem_00/fly.toml
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
# fly.toml app configuration file generated for restless-bush-123 on 2023-04-19T13:36:26+02:00
|
||||||
|
#
|
||||||
|
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
|
||||||
|
#
|
||||||
|
|
||||||
|
app = "restless-bush-123"
|
||||||
|
primary_region = "ams"
|
||||||
|
|
||||||
|
[experimental]
|
||||||
|
auto_rollback = true
|
||||||
|
|
||||||
|
[env]
|
||||||
|
ECHO_PORT = "8080"
|
||||||
|
|
||||||
|
[[services]]
|
||||||
|
protocol = "tcp"
|
||||||
|
internal_port = 8080
|
||||||
|
|
||||||
|
[[services.ports]]
|
||||||
|
port = 8080
|
||||||
38
problem_00/src/main.rs
Normal file
38
problem_00/src/main.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||||
|
use tokio::net::TcpListener;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
env_logger::init();
|
||||||
|
let listener = TcpListener::bind("0.0.0.0:8080").await?;
|
||||||
|
log::info!("Start TCP server");
|
||||||
|
loop {
|
||||||
|
let (mut socket, _) = listener.accept().await?;
|
||||||
|
|
||||||
|
tokio::spawn(async move {
|
||||||
|
let mut buf = [0; 1024];
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let n = match socket.read(&mut buf).await {
|
||||||
|
Ok(n) if n == 0 => {
|
||||||
|
log::info!("Receiving echo: {}", n);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Ok(n) => {
|
||||||
|
log::info!("Receiving echo: {}", n);
|
||||||
|
n
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("failed to read from socket; err = {:?}", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Err(e) = socket.write_all(&buf[0..n]).await {
|
||||||
|
log::error!("failed to write to socket; err = {:?}", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue