44 lines
		
	
	
		
			1009 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1009 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
use crate::conf;
 | 
						|
use crate::server_conf::conexion::Conexion;
 | 
						|
use crate::server_conf::listener::GenericListener;
 | 
						|
use std::thread;
 | 
						|
use std::sync::{Arc, RwLock};
 | 
						|
 | 
						|
pub struct ConfSer{
 | 
						|
    path: String,
 | 
						|
    listener: GenericListener,
 | 
						|
}
 | 
						|
 | 
						|
impl ConfSer {
 | 
						|
    fn new(path: String) -> ConfSer{
 | 
						|
        ConfSer{
 | 
						|
            path: path.clone(),
 | 
						|
            listener: GenericListener::bind(path, 1).unwrap(),
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
impl Drop for ConfSer {
 | 
						|
    fn drop(&mut self) {
 | 
						|
        // There's no way to return a useful error here
 | 
						|
        let _ = std::fs::remove_file(self.path.clone()).unwrap();
 | 
						|
        println!("> Dropping {}", self.path);
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
pub fn start(conf: Arc<RwLock<conf::Config>>){
 | 
						|
    let ser = ConfSer::new(String::from("mineproxy"));
 | 
						|
 | 
						|
    loop{
 | 
						|
        match ser.listener.accept() {
 | 
						|
            Ok(stream) => {
 | 
						|
                let c = conf.clone();
 | 
						|
                thread::spawn(|| Conexion::new(c, stream).process_reques());
 | 
						|
            }
 | 
						|
            Err(e) => println!("{}", e)
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
}
 | 
						|
 |