use crate::conf; use crate::server_conf::conexion::Conexion; use crate::server_conf::listener::GenericListener; use std::thread; use std::sync::{Arc, RwLock}; use log::{error,warn,info}; pub struct ConfSer{ path: String, listener: GenericListener, } impl ConfSer { fn new(path: String, conf_type: &String) -> ConfSer{ ConfSer{ path: path.clone(), listener: match GenericListener::bind(path, GenericListener::string_top_type(conf_type)){ Ok(l) => l, Err(e) => { warn!("Error al levantar el servidor de configuraciones:{}",e); panic!("Error al levantar el servidor de configuraciones:{}",e) }, }, } } } 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(); info!("> Dropping {}", self.path); } } pub fn start(conf: Arc>){ let ser = ConfSer::new( conf.read().unwrap().get_bindeable_conf(), conf.read().unwrap().get_conf_type(), ); loop{ match ser.listener.accept() { Ok(stream) => { let c = conf.clone(); thread::spawn(|| Conexion::new(c, stream).process_reques()); } Err(e) => error!("{}", e) } } }