pub fn run(&self, threads: usize, opts: BindOptions) -> Result<()> {
        let debug_addr;

        if self.ctx.enable_sync {
            self.spawn_sync_thread()?;
            self.spawn_healthcheck_thread()?;
        } else {
            info!("Background sync is disabled. Health check forced to healthy.");
        }

        let listener = match opts {
            BindOptions::BindToAddr(addr) => {
                debug_addr = format!("http://{}/", addr);
                HttpListener::new(addr)?
            }
            BindOptions::BindToFd(fd) => {
                debug_addr = format!("file descriptor {}", fd);
                // unsafe is okay here because we dup the fd
                unsafe { HttpListener::from_raw_fd(libc::dup(fd)) }
            }
            BindOptions::UseConfig => {
                if let Some(fd) = get_systemd_fd()? {
                    debug_addr = format!("systemd supplied fd");
                    // unsafe is sortof okay here because get_systemd_fd will
                    // not return the fd a second time and we also do not pass
                    // that information to potential children
                    unsafe { HttpListener::from_raw_fd(fd) }
                } else {
                    let addr = self.ctx.config.get_server_socket_addr()?;
                    let (host, port) = addr;
                    debug_addr = format!("http://{}:{}/", host, port);
                    HttpListener::new((host.as_str(), port))?
                }
            }
        };
        info!("Listening on {}", debug_addr);
        info!("Spawning {} listener threads", threads);

        let ctx = self.ctx.clone();
        Server::new(listener)
            .handle_threads(move |req: Request, resp: Response|
        {
            let is_head = req.method == Method::Head;
            let handler = match req.uri {
                RequestUri::AbsolutePath(ref path) => {
                    match path.as_str() {
                        "/health" => handlers::healthcheck_handler,
                        "/lookup" => handlers::lookup_symbol_handler,
                        "/sdks" => handlers::list_sdks_handler,
                        "/version" => handlers::version_handler,
                        _ => not_found,
                    }
                }
                _ => bad_request,
            };
            match handler(&*ctx.clone(), req) {
                Ok(result) => result,
                Err(err) => ApiResponse::from_error(err).unwrap(),
            }.write_to_response(is_head, resp).unwrap();
        }, threads)?;
        Ok(())
    }
/// Runs the server in a loop.
Runs the server in a loop.
Runs the server in a loop .
pub fn run(&self, threads: usize, opts: BindOptions) -> Result<()> {
        let debug_addr;
        if self.ctx.enable_sync {
            self.spawn_sync_thread()?;
            self.spawn_healthcheck_thread()?;
        } else {
            info!("Background sync is disabled. Health check forced to healthy.");
        }
        let listener = match opts {
            BindOptions::BindToAddr(addr) => {
                debug_addr = format!("http://{}/", addr);
                HttpListener::new(addr)?
            }
            BindOptions::BindToFd(fd) => {
                debug_addr = format!("file descriptor {}", fd);
                // unsafe is okay here because we dup the fd
                unsafe { HttpListener::from_raw_fd(libc::dup(fd)) }
            }
            BindOptions::UseConfig => {
                if let Some(fd) = get_systemd_fd()? {
                    debug_addr = format!("systemd supplied fd");
                    // unsafe is sortof okay here because get_systemd_fd will
                    // not return the fd a second time and we also do not pass
                    // that information to potential children
                    unsafe { HttpListener::from_raw_fd(fd) }
                } else {
                    let addr = self.ctx.config.get_server_socket_addr()?;
                    let (host, port) = addr;
                    debug_addr = format!("http://{}:{}/", host, port);
                    HttpListener::new((host.as_str(), port))?
                }
            }
        };
        info!("Listening on {}", debug_addr);
        info!("Spawning {} listener threads", threads);
        let ctx = self.ctx.clone();
        Server::new(listener)
            .handle_threads(move |req: Request, resp: Response|
        {
            let is_head = req.method == Method::Head;
            let handler = match req.uri {
                RequestUri::AbsolutePath(ref path) => {
                    match path.as_str() {
                        "/health" => handlers::healthcheck_handler,
                        "/lookup" => handlers::lookup_symbol_handler,
                        "/sdks" => handlers::list_sdks_handler,
                        "/version" => handlers::version_handler,
                        _ => not_found,
                    }
                }
                _ => bad_request,
            };
            match handler(&*ctx.clone(), req) {
                Ok(result) => result,
                Err(err) => ApiResponse::from_error(err).unwrap(),
            }.write_to_response(is_head, resp).unwrap();
        }, threads)?;
        Ok(())
    }
pub fn run ( & self , threads : usize , opts : BindOptions ) -> Result < ( ) > { let debug_addr ; if self . ctx . enable_sync { self . spawn_sync_thread ( ) ? ; self . spawn_healthcheck_thread ( ) ? ; } else { info ! ( " " ) ; } let listener = match opts { BindOptions :: BindToAddr ( addr ) => { debug_addr = format ! ( " " addr ) ; HttpListener :: new ( addr ) ? } BindOptions :: BindToFd ( fd ) => { debug_addr = format ! ( " " fd ) ; // unsafe is okay here because we dup the fd unsafe { HttpListener :: from_raw_fd ( libc :: dup ( fd ) ) } } BindOptions :: UseConfig => { if let Some ( fd ) = get_systemd_fd ( ) ? { debug_addr = format ! ( " " ) ; // unsafe is sortof okay here because get_systemd_fd will // not return the fd a second time and we also do not pass // that information to potential children unsafe { HttpListener :: from_raw_fd ( fd ) } } else { let addr = self . ctx . config . get_server_socket_addr ( ) ? ; let ( host , port ) = addr ; debug_addr = format ! ( " " host port ) ; HttpListener :: new ( ( host . as_str ( ) , port ) ) ? } } } ; info ! ( " " debug_addr ) ; info ! ( " " threads ) ; let ctx = self . ctx . clone ( ) ; Server :: new ( listener ) . handle_threads ( move | req : Request , resp : Response | { let is_head = req . method == Method :: Head ; let handler = match req . uri { RequestUri :: AbsolutePath ( ref path ) => { match path . as_str ( ) { " " => handlers :: healthcheck_handler , " " => handlers :: lookup_symbol_handler , " " => handlers :: list_sdks_handler , " " => handlers :: version_handler , _ => not_found , } } _ => bad_request , } ; match handler ( & * ctx . clone ( ) , req ) { Ok ( result ) => result , Err ( err ) => ApiResponse :: from_error ( err ) . unwrap ( ) , } . write_to_response ( is_head , resp ) . unwrap ( ) ; } , threads ) ? ; Ok ( ( ) ) }
Runs the server in a loop.
Runs the server in a loop .
&self
threads
usize
opts
BindOptions