Rename server.rs to handler.rs for clarity, since this is responsible for handling one interaction with a client
This commit is contained in:
@@ -3,14 +3,14 @@ use common::{Request, RESPONSE_NO, RESPONSE_OK};
|
|||||||
use std::io::{Error, Write};
|
use std::io::{Error, Write};
|
||||||
use std::os::unix::net::UnixStream;
|
use std::os::unix::net::UnixStream;
|
||||||
|
|
||||||
pub struct Server {
|
pub struct Handler {
|
||||||
stream: UnixStream,
|
stream: UnixStream,
|
||||||
handler: PasswordDirectory,
|
handler: PasswordDirectory,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Server {
|
impl Handler {
|
||||||
pub fn new(stream: UnixStream, handler: PasswordDirectory) -> Result<Server, Error> {
|
pub fn new(stream: UnixStream, handler: PasswordDirectory) -> Result<Handler, Error> {
|
||||||
Ok(Server { stream, handler })
|
Ok(Handler { stream, handler })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn communicate(&mut self) -> Result<(), Error> {
|
fn communicate(&mut self) -> Result<(), Error> {
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
|
use crate::handler::Handler;
|
||||||
use crate::options::OPTIONS;
|
use crate::options::OPTIONS;
|
||||||
use crate::repository::PasswordDirectory;
|
use crate::repository::PasswordDirectory;
|
||||||
use crate::server::Server;
|
|
||||||
use std::fs::{metadata, set_permissions};
|
use std::fs::{metadata, set_permissions};
|
||||||
use std::io::Error;
|
use std::io::Error;
|
||||||
use std::os::unix::fs::PermissionsExt;
|
use std::os::unix::fs::PermissionsExt;
|
||||||
@@ -34,7 +34,7 @@ impl Listener {
|
|||||||
Ok(stream) => {
|
Ok(stream) => {
|
||||||
/* connection succeeded */
|
/* connection succeeded */
|
||||||
let handler = self.handler.clone();
|
let handler = self.handler.clone();
|
||||||
thread::spawn(|| Server::new(stream, handler).unwrap().handle_client());
|
thread::spawn(|| Handler::new(stream, handler).unwrap().handle_client());
|
||||||
}
|
}
|
||||||
Err(_err) => {
|
Err(_err) => {
|
||||||
/* connection failed */
|
/* connection failed */
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
|
mod handler;
|
||||||
mod listener;
|
mod listener;
|
||||||
pub mod options;
|
pub mod options;
|
||||||
mod repository;
|
mod repository;
|
||||||
mod server;
|
|
||||||
|
|
||||||
use crate::listener::Listener;
|
use crate::listener::Listener;
|
||||||
use crate::options::OPTIONS;
|
use crate::options::OPTIONS;
|
||||||
|
|||||||
Reference in New Issue
Block a user