fix keep alive tried to read closed connection

This commit is contained in:
MeexReay 2025-04-10 22:16:19 +03:00
parent fe41dc8339
commit 396d8918bd

View File

@ -1,7 +1,7 @@
use std::{ use std::{
error::Error, io::{BufRead, BufReader, Read, Write}, error::Error, io::{BufRead, BufReader, Read, Write},
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, TcpListener, TcpStream}, net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, TcpListener, TcpStream},
str::FromStr, sync::Arc, thread::{sleep, spawn}, time::Duration str::FromStr, sync::Arc, thread::{spawn, JoinHandle}
}; };
use ignore_result::Ignore; use ignore_result::Ignore;
@ -34,32 +34,35 @@ impl FlowgateServer {
} }
pub fn run(self) { pub fn run(self) {
self.start();
loop {
sleep(Duration::from_secs(60));
}
}
pub fn start(self) {
let local_self = Arc::new(self); let local_self = Arc::new(self);
local_self.clone().start_http(); local_self.clone().start_http();
local_self.clone().start_https(); local_self.clone().run_https().ignore();
} }
pub fn start_http(self: Arc<Self>) { pub fn start(self) -> Vec<JoinHandle<()>> {
let local_self = Arc::new(self);
let mut handles = Vec::new();
handles.push(local_self.clone().start_http());
handles.push(local_self.clone().start_https());
handles
}
pub fn start_http(self: Arc<Self>) -> JoinHandle<()> {
spawn({ spawn({
let local_self = self.clone(); let local_self = self.clone();
move || { local_self.run_http().ignore(); } move || { local_self.run_http().ignore(); }
}); })
} }
pub fn start_https(self: Arc<Self>) { pub fn start_https(self: Arc<Self>) -> JoinHandle<()> {
spawn({ spawn({
let local_self = self.clone(); let local_self = self.clone();
move || { local_self.run_https().ignore(); } move || { local_self.run_https().ignore(); }
}); })
} }
pub fn run_http(self: Arc<Self>) -> Result<(), Box<dyn Error>> { pub fn run_http(self: Arc<Self>) -> Result<(), Box<dyn Error>> {
@ -344,7 +347,7 @@ impl FlowgateServer {
while read < content_length { while read < content_length {
let mut buf = vec![0; 4096]; let mut buf = vec![0; 4096];
let Ok(size) = conn.stream.get_mut().read(&mut buf) else { break }; let size = conn.stream.get_mut().read(&mut buf).ok()?;
if size == 0 { break } if size == 0 { break }
@ -414,7 +417,7 @@ impl FlowgateServer {
while read < content_length { while read < content_length {
let mut buf = vec![0; 4096]; let mut buf = vec![0; 4096];
let Ok(size) = conn.stream.get_mut().read(&mut buf) else { break }; let size = conn.stream.get_mut().read(&mut buf).ok()?;
if size == 0 { break } if size == 0 { break }