Function outer_cgi::main

source ·
pub fn main<I, H>(init: I, handler: H) -> !
where I: 'static + Fn(u32), H: 'static + Fn(&mut dyn IO, HashMap<String, String>) -> Result<i32> + Sync + Send + Copy + RefUnwindSafe,
Expand description

The first (and preferably only) function your program’s main function should call. Handles argument parsing, worker thread spawning, etc. For each request, calls the handler you provide.

init is called once, before any requests are handled. It is passed the maximum number of parallel connections that will be handled by this instance. You should perform initialization (read templates, set up database connection pools, etc.) in this function. If you don’t need any such setup, just pass |_|{}.

Your handler receives the standard set of CGI streams and environment variables as parameters. It should use them instead of the usual Rust stdin/stdout/env facilities. outer_cgi tries to ensure that the usual stderr facility (eprintln! etc.) is usable for logging error information.

outer_cgi::main does not return. It handles as many requests as possible, then calls std::process::exit as appropriate. You shouldn’t call anything but outer_cgi::main from your script’s main function; stdin/stdout/stderr may be in an incoherent state, and if you spawn any threads before calling outer_cgi::main, they may silently die in some configurations. Perform any per-process setup on-demand, the first time your handler is called, instead.

See the Common Gateway Interface specification and the module-level documentation for more information.