My first time Multithread #3082
RepublicEmpire
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
// by using the Rust's book codes, started out with the single tread.
//It worked out fine as usual with minor tweaks to the code which made it run effective.
//Unsure if it was able to open up the browser as intended.
use std::{
fs,
io::{prelude::*, BufReader},
net::{TcpListener, TcpStream},
thread,
time::Duration,
tokio,
hyper,
Request,
};
//It was 8080 before changing it to 3992.
// different appoarch to the number.
async fn main() {
let listener = TcpListener::bind("127.0.01:3992").unwrap();
}
//Using the tokio appoarch as which to make a threads possible at best.
//It has multiple functions to make sure if it's correctly.'
#[tokio]
fn handle_connection(_: links_name) -> proper_connection (usize) {
renewed_connect();
let spawn = thread;
}
async fn another_path(proper_connection: _) {
beta_route(proper_connection);
}
async fn fun_name(proper_connection: _) {
let proper_connection = proper_connection;
}
fn renewed_connect() {
let spawn = spawn;
}
//different ways to make the links is possible to make
fn links_name(mut stream: TcpStream) -> Vec {
if modname::proper_connection = "GET / HTTP/1.1" {
let status_line = "HTTP/1.1 200 OK";
let contents = fs::read_to_string("hello to High American Timeline.html").unwrap();
let length = contents.len();
}
//In my mind, this would be the data to be acquired but unable to implement.
fn logical_database() {
let (status_line, filename) = match &request_line[..] {
"GET / HTTP/1.1" => ("HTTP/1.1 200 OK", "hello.html"),
"GET / sleep HTTP/1.1" => {
thread::sleep(Duration::from_secs(5));
("HTTP/1.1 200 OK", "hello.html")
}
_=> ("HTTP/1.1 404 NOT FOUND", "404.html"),
};
}
fn http_request (mut stream: TcpStream) {
let buf_reader = BufReader::new(&mut stream);
let http_request: Vec<_> = buf_reader
.lines()
.map(|result| result.unwrap())
.take_while(|line| !line.is_empty())
.collect();
}
//The following lines is especially where the complications arose.
//After trying to adjusting the code to make it, but unable to do so.
//I could delete some of them, but ends up being a error.
// Although if with more time to work on, I found it was a extremely difficult to do.
// Each time, it shows more potential fixes created more problems than good solutions.
async fn connection(thread::(move window || ) {
mod fn seperate_window(main) {
async fn seperate_window(_:Request<hyper::Bmod) {
pub(crate) fn status_line (tokio) {
tokio::signal::windows()
.await
.expect("Open new open signal handler");
};
let hyper = thread(duration::from_secs(5));
return main
}
}
}
async impl pub(thread) {
let (hyper).Clone(tokio) = match &request_line[..] {
"GET / HTTP/1.1" => ("HTTP/1.1 500 OK", "Fred says Hi.html"),
"GET / sleep HTTP/1.1" => {
thread::sleep(Duration::from_secs(5));
("HTTP/1.1 500 OK", "Fred says Hi.html")
}
_=> ("HTTP/1.1 404 NOT FOUND", "404.html"),
};
let hyper = thread(duration::from_secs(5));
return main
}
}
// It gets more diffcult as it goes by since this requires alot of effort to work on the hypertread code.
// Therefore, it's the point where this code becoming unworkable at this point.
// There is a absurd ways to take this appoarch considering this is not the right way to code it.
pub(crate) #[tokio] thread::spawn(move status_line || pub (crate) #[tokio]) {
let (status_line, filename).clone(thread) = match &request_line[..] {
"GET / HTTP/1.1" => ("HTTP/1.1 900 OK", "History of the world.html"),
"GET / sleep HTTP/1.1" => {
thread::sleep(Duration::from_secs(5));
("HTTP/1.1 900 OK", "History of the world.html")
}
_=> ("HTTP/1.1 404 NOT FOUND", "404.html"),
};
let hyper = thread(duration::from_secs(5));
return main
}
async fn shutdown_signal() {
tokio::signal::ctrl_c()
.await
. .expect("failed to install CTRL+C signal handler");
}
{
println! ("failure to make a proper multitread")
}
// The code ends here despite it's a massive flawed coding.
//The issue for me is that I get the coding concepts, but trying to implement is the issue.
// If I had more time to work on the code, maybe it would work considering single tread code is often workable.
// Multitread requires proper calaucations to adjust it while to make sure that treads are connected.
// The last part is essientally how to close the code as part of the book's last section.
//The class is very interesting to challenge myself even to one day as to consider as a backup option.
// Therefore, I did my best effort to turn in on time even it may not work considering how flawed the coding right now.
Beta Was this translation helpful? Give feedback.
All reactions