Doesn't really work, but I'm starting to implement request headers
This commit is contained in:
@@ -17,7 +17,7 @@ use crate::
|
||||
ROOT_DIR,
|
||||
};
|
||||
|
||||
pub fn watch_files(file_list: &Vec<PathBuf>) -> u8
|
||||
pub fn watch_files(file_list: &[PathBuf]) -> u8
|
||||
{
|
||||
let (tx, rx) = mpsc::channel::<Result<Event>>(); // Use recommended_watcher() to automatically select the best implementation
|
||||
|
||||
|
||||
23
src/main.rs
23
src/main.rs
@@ -20,7 +20,6 @@ lazy_static! {
|
||||
// TODO, make 'code' an enum
|
||||
// TODO, safely modify bytes in thread.
|
||||
// TODO, Makes paths more consistent.
|
||||
// TODO, Avoid copying bytes
|
||||
fn main() -> io::Result<()>
|
||||
{
|
||||
#![warn(clippy::pedantic, clippy::perf)]
|
||||
@@ -32,11 +31,6 @@ fn main() -> io::Result<()>
|
||||
let listener = TcpListener::bind(BIND_ADDRESS).unwrap();
|
||||
println!("Listening at {BIND_ADDRESS}");
|
||||
|
||||
/*
|
||||
let mut file_list: Vec<std::path::PathBuf> = vec![ROOT_DIR.join(INDEX_FILE)];
|
||||
let (mut bytes, mut new_file_list) = files::read_file(INDEX_FILE, 0);
|
||||
file_list.append(&mut new_file_list);
|
||||
*/
|
||||
// File watch thread
|
||||
thread::spawn(
|
||||
move || {
|
||||
@@ -44,7 +38,6 @@ fn main() -> io::Result<()>
|
||||
let mut file_list: Vec<PathBuf>;
|
||||
(bytes, file_list) = files::read_file(INDEX_FILE, 0);
|
||||
file_list.push(ROOT_DIR.join(INDEX_FILE));
|
||||
println!("Tracking: {:?}", file_list);
|
||||
|
||||
tx.send(bytes.clone()).unwrap();
|
||||
loop
|
||||
@@ -56,7 +49,7 @@ fn main() -> io::Result<()>
|
||||
|
||||
(bytes, file_list) = files::read_file(INDEX_FILE, 0);
|
||||
file_list.push(ROOT_DIR.join(INDEX_FILE));
|
||||
tx.send(bytes.clone()).unwrap();
|
||||
tx.send(bytes).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,9 +64,17 @@ fn main() -> io::Result<()>
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_connection(mut stream: TcpStream, bytes: &Vec<u8>)
|
||||
fn handle_connection(mut stream: TcpStream, bytes: &[u8])
|
||||
{
|
||||
let buf_reader = BufReader::new(&stream);
|
||||
println!("CONNECTION: {buf_reader:#?}");
|
||||
stream.write_all(bytes.as_slice()).unwrap();
|
||||
let notp_request: Vec<_> = buf_reader
|
||||
.lines()
|
||||
.map(|result| result.unwrap())
|
||||
.take_while(|line| !line.is_empty())
|
||||
.collect();
|
||||
println!("REQUEST: {:?}", notp_request);
|
||||
if let Err(e) = stream.write_all(bytes)
|
||||
{
|
||||
eprintln!("Failed to send response: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user