functional server config
This commit is contained in:
45
src/server_conf/server.rs
Normal file
45
src/server_conf/server.rs
Normal 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),
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user