add start_server func like an alias

This commit is contained in:
MeexReay 2024-06-22 21:10:25 +03:00
parent b6d03ac3ab
commit 7b37307f5b
2 changed files with 16 additions and 3 deletions

View File

@ -712,7 +712,7 @@ impl<T: HttpServer + Send + 'static> HttpServerStarter<T> {
let running = Arc::new(AtomicBool::new(true));
if self.threads == 0 {
start_server(self.http_server, &self.host, self.timeout, handler, running)
start_server_new_thread(self.http_server, &self.host, self.timeout, handler, running)
} else if self.threads == 1 {
start_server_sync(self.http_server, &self.host, self.timeout, handler, running)
} else {
@ -743,7 +743,7 @@ impl<T: HttpServer + Send + 'static> HttpServerStarter<T> {
let thread = if self.threads == 0 {
thread::spawn(move || {
start_server(
start_server_new_thread(
self.http_server,
&self.host,
self.timeout,
@ -827,7 +827,7 @@ where
Ok(())
}
fn start_server<F, S>(
fn start_server_new_thread<F, S>(
server: S,
host: &str,
timeout: Option<Duration>,
@ -1000,3 +1000,14 @@ impl Worker {
Worker { thread }
}
}
pub fn start_server<S: HttpServer + Send + 'static>(server: S, host: &str) {
start_server_new_thread(
server,
host,
None,
handle_connection,
Arc::new(AtomicBool::new(true)),
)
.unwrap();
}

View File

@ -46,4 +46,6 @@ fn main() {
.threads(5) // threadpool size
.start_forever()
.expect("http server error");
// ezhttp::start_server(site, host);
}