functional server config

This commit is contained in:
2022-12-13 22:10:45 +01:00
parent d992981f22
commit 8991a7fbf0
8 changed files with 180 additions and 115 deletions

45
src/server_conf/server.rs Normal file
View File

@@ -0,0 +1,45 @@
use std::net::{TcpListener, TcpStream};
use std::os::unix::net::{UnixListener, UnixStream};
use std::io::prelude::*;
use std::result;
use crate::conf;
use crate::server_conf::conexion::Conexion;
use std::sync::{Arc, RwLock};
use std::path::{Path, PathBuf};
pub struct ConfSer{
path: String,
listener: UnixListener,
}
impl ConfSer {
fn new(path: String) -> ConfSer{
ConfSer{
path: path.clone(),
listener: UnixListener::bind(path).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"));
for stream in ser.listener.incoming() {
match stream{
Ok(s) => {
Conexion::new(conf.clone(), s).process_reques();
},
Err(_e) => println!("{}",_e),
}
}
}