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