generated from PlexSheep/rs-base
We have a server at least #3
|
@ -53,7 +53,7 @@ impl Config {
|
||||||
addr: cli.addr.clone(),
|
addr: cli.addr.clone(),
|
||||||
mode: cli.mode.clone(),
|
mode: cli.mode.clone(),
|
||||||
threads: cli.threads,
|
threads: cli.threads,
|
||||||
timeout: Duration::from_millis(DEFAULT_TIMEOUT_LEN)
|
timeout: Duration::from_millis(DEFAULT_TIMEOUT_LEN),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ async fn main() -> Result<()> {
|
||||||
#[cfg(feature = "server")]
|
#[cfg(feature = "server")]
|
||||||
if cli.server {
|
if cli.server {
|
||||||
info!("starting server");
|
info!("starting server");
|
||||||
return Server::build(cfg).await?.run().await
|
return Server::build(cfg).await?.run().await;
|
||||||
}
|
}
|
||||||
// implicit else, so we can work without the server feature
|
// implicit else, so we can work without the server feature
|
||||||
info!("starting client");
|
info!("starting client");
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
#![cfg(feature = "server")]
|
#![cfg(feature = "server")]
|
||||||
use std::{net::SocketAddr, time::Duration};
|
use std::{net::SocketAddr, time::Duration};
|
||||||
|
|
||||||
use anyhow::{Result, anyhow};
|
use anyhow::{anyhow, Result};
|
||||||
use libpt::{
|
use libpt::{
|
||||||
bintols::display::humanbytes,
|
bintols::display::humanbytes,
|
||||||
log::{error, info, trace, warn, debug},
|
log::{debug, error, info, trace},
|
||||||
};
|
};
|
||||||
use threadpool::ThreadPool;
|
use threadpool::ThreadPool;
|
||||||
use tokio::{
|
use tokio::{
|
||||||
io::{AsyncBufRead, AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader, Interest},
|
io::{AsyncReadExt, BufReader},
|
||||||
net::{self, TcpListener, TcpSocket, TcpStream},
|
net::{TcpListener, TcpStream},
|
||||||
select,
|
|
||||||
time::timeout,
|
time::timeout,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -44,7 +43,7 @@ impl Server {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_stream(&self, mut stream: (TcpStream, SocketAddr)) -> Result<()> {
|
async fn handle_stream(&self, stream: (TcpStream, SocketAddr)) -> Result<()> {
|
||||||
info!("start handling stream {:?}", stream.1);
|
info!("start handling stream {:?}", stream.1);
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
let mut reader = BufReader::new(stream.0);
|
let mut reader = BufReader::new(stream.0);
|
||||||
|
@ -81,8 +80,9 @@ impl Server {
|
||||||
trace!("loop");
|
trace!("loop");
|
||||||
len = match timeout(self.cfg.timeout, reader.read(buf)).await {
|
len = match timeout(self.cfg.timeout, reader.read(buf)).await {
|
||||||
Ok(inner) => {
|
Ok(inner) => {
|
||||||
trace!("Read for len: {inner:?}"); 0
|
trace!("Read for len: {inner:?}");
|
||||||
},
|
0
|
||||||
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("timeout while reading: {err}");
|
error!("timeout while reading: {err}");
|
||||||
return Err(err.into());
|
return Err(err.into());
|
||||||
|
@ -90,8 +90,7 @@ impl Server {
|
||||||
};
|
};
|
||||||
if self.should_end(&buf) {
|
if self.should_end(&buf) {
|
||||||
return Ok(len);
|
return Ok(len);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// ?????????
|
// ?????????
|
||||||
failsafe += 1;
|
failsafe += 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue