pub fn start_server(ip: String, port: i32, thread_pool_size: i32, static_files: StaticFiles, dynamic_files: DynamicFiles) {
    let pool = ThreadPool::new(thread_pool_size as usize);

    let address = format!("{}:{}", ip, port);
    let stats = Arc::new(ServerStats { request_results: Mutex::new(vec![]) });

    let server_files = ServerFiles{static_files, dynamic_files};

    let listener = match TcpListener::bind(address) {
        Ok(listener) => listener,
        Err(_) => {
            println!("Threaded: TCP bind error. Consider a restart of the programm");
            return;
        }
    };
    for stream in listener.incoming() {
        let connection = match stream {
            Ok(stream) => stream,
            Err(_) => {
                println!("Threaded: Connection error. Ignoring request");
                continue;
            }
        };

        let server_files = server_files.clone();
        let stats_change = stats.clone();
        let stats_view = stats.clone();
        pool.execute(move|| {
            let result = stat_wrapper(handle_connection, connection, server_files, stats_view);
            let mut results = stats_change.request_results.lock().unwrap();
            match result {
                Some(res) => results.push(res),
                _ => ()
            }
        });
    }
}
/// Starts the threaded server listening on the address,
/// with the amount of threads provided by thread_pool_size.
Starts the threaded server listening on the address,
with the amount of threads provided by thread_pool_size.
Starts the threaded server listening on the address with the amount of threads provided by thread_pool_size .
pub fn start_server(ip: String, port: i32, thread_pool_size: i32, static_files: StaticFiles, dynamic_files: DynamicFiles) {
    let pool = ThreadPool::new(thread_pool_size as usize);
    let address = format!("{}:{}", ip, port);
    let stats = Arc::new(ServerStats { request_results: Mutex::new(vec![]) });
    let server_files = ServerFiles{static_files, dynamic_files};
    let listener = match TcpListener::bind(address) {
        Ok(listener) => listener,
        Err(_) => {
            println!("Threaded: TCP bind error. Consider a restart of the programm");
            return;
        }
    };
    for stream in listener.incoming() {
        let connection = match stream {
            Ok(stream) => stream,
            Err(_) => {
                println!("Threaded: Connection error. Ignoring request");
                continue;
            }
        };
        let server_files = server_files.clone();
        let stats_change = stats.clone();
        let stats_view = stats.clone();
        pool.execute(move|| {
            let result = stat_wrapper(handle_connection, connection, server_files, stats_view);
            let mut results = stats_change.request_results.lock().unwrap();
            match result {
                Some(res) => results.push(res),
                _ => ()
            }
        });
    }
}
pub fn start_server ( ip : String , port : i32 , thread_pool_size : i32 , static_files : StaticFiles , dynamic_files : DynamicFiles ) { let pool = ThreadPool :: new ( thread_pool_size as usize ) ; let address = format ! ( " " ip port ) ; let stats = Arc :: new ( ServerStats { request_results : Mutex :: new ( vec ! [ ] ) } ) ; let server_files = ServerFiles { static_files , dynamic_files } ; let listener = match TcpListener :: bind ( address ) { Ok ( listener ) => listener , Err ( _ ) => { println ! ( " " ) ; return ; } } ; for stream in listener . incoming ( ) { let connection = match stream { Ok ( stream ) => stream , Err ( _ ) => { println ! ( " " ) ; continue ; } } ; let server_files = server_files . clone ( ) ; let stats_change = stats . clone ( ) ; let stats_view = stats . clone ( ) ; pool . execute ( move | | { let result = stat_wrapper ( handle_connection , connection , server_files , stats_view ) ; let mut results = stats_change . request_results . lock ( ) . unwrap ( ) ; match result { Some ( res ) => results . push ( res ) , _ => ( ) } } ) ; } }
Starts the threaded server listening on the address,
with the amount of threads provided by thread_pool_size.
Starts the threaded server listening on the address with the amount of threads provided by thread_pool_size .
ip
String
port
i32
thread_pool_size
i32
static_files
StaticFiles
dynamic_files
DynamicFiles
ip
String
port
i32
thread_pool_size
i32
static_files
StaticFiles
dynamic_files
DynamicFiles