diff options
Diffstat (limited to 'corgi/src/main.rs')
-rw-r--r-- | corgi/src/main.rs | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/corgi/src/main.rs b/corgi/src/main.rs index 3923084..fb6b75a 100644 --- a/corgi/src/main.rs +++ b/corgi/src/main.rs @@ -3,6 +3,7 @@ use std::{ path::PathBuf, pin::Pin, sync::{Arc, Mutex}, + thread::JoinHandle, time::Instant, }; @@ -30,17 +31,26 @@ pub struct Settings { scripts: Vec<Script>, } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug)] pub enum ScriptKind { Executable, - Object, + Module { thread: Arc<Option<JoinHandle<()>>> }, +} + +impl ScriptKind { + pub fn is_executable(&self) -> bool { + if let ScriptKind::Executable = self { + true + } else { + false + } + } } #[derive(Clone, Debug)] pub struct Script { name: String, kind: ScriptKind, - module_lock: Arc<Mutex<()>>, regex: Option<Regex>, filename: String, env: Vec<(String, String)>, @@ -98,7 +108,9 @@ fn parse_script_conf(conf: &Value) -> Script { let kind = match conf.get("Type") { None => ScriptKind::Executable, Some("executable") => ScriptKind::Executable, - Some("object") => ScriptKind::Object, + Some("object") => ScriptKind::Module { + thread: Arc::new(None), + }, Some(kind) => { eprintln!("'{kind}' is not a valid script type"); std::process::exit(1) @@ -108,7 +120,6 @@ fn parse_script_conf(conf: &Value) -> Script { Script { name, kind, - module_lock: Arc::new(Mutex::new(())), regex, filename, env: env.unwrap_or_default(), @@ -240,14 +251,12 @@ impl Svc { body: if content_length > 0 { Some(body) } else { None }, }; - let start_cgi = Instant::now(); let cgi_response = match script.kind { ScriptKind::Executable => { caller::call_and_parse_cgi(script.clone(), http_request).await } ScriptKind::Object => caller::call_and_parse_module(script.clone(), http_request).await, }; - let cgi_time = start_cgi.elapsed(); let status = StatusCode::from_u16(cgi_response.status).unwrap(); let mut response = Response::builder().status(status); @@ -264,10 +273,8 @@ impl Svc { }; println!( - "served to [{client_addr}]\n\tscript: {}\n\tpath: {path}\n\tcgi took {}ms. total time {}ms\n\tUA: {uagent}", - &script.name, - cgi_time.as_millis(), - start.elapsed().as_millis() + "served to [{client_addr}]\n\tscript: {}\n\tpath: {path}\n\tUA: {uagent}", + &script.name ); stats.log_request(db_req); |