Skip to content

Commit

Permalink
basic thread spawn split
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpclark committed Dec 12, 2017
1 parent 48335f5 commit a89ecb9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
36 changes: 17 additions & 19 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ use std::time::SystemTime;
use std::sync::{Arc, Mutex};
extern crate num_cpus;
extern crate tiny_http;
mod web;
use std::thread;

static ITERATIONS: AtomicUsize = ATOMIC_USIZE_INIT;

Expand Down Expand Up @@ -169,7 +171,7 @@ USE OF THIS BINARY FALLS UNDER THE MIT LICENSE (c) 2017").
}
// End Resume Feature

// BEGIN JSON WEB
// DATA for JSON web end point
let reporter_handler = ReportData {
cores: num_cpus::get() as u8,
chunk: chunk.clone().unwrap().parse::<usize>().unwrap_or(32),
Expand All @@ -187,20 +189,9 @@ USE OF THIS BINARY FALLS UNDER THE MIT LICENSE (c) 2017").

let web_reporter = reporter_handler.clone();

// HTTP SERVER IF ARG
{
use tiny_http::{Server, Response};

let server = Server::http("0.0.0.0:8000").unwrap();

for request in server.incoming_requests() {
let response = Response::from_string({
serde_json::to_string((&web_reporter)).unwrap_or("".to_string())
});
request.respond(response);
}
}
// END JSON WEB
let web_runner = thread::spawn(move || {
web::host_data(&web_reporter)
});

let work_load = WorkLoad(
resume_key_chars,
Expand All @@ -213,11 +204,18 @@ USE OF THIS BINARY FALLS UNDER THE MIT LICENSE (c) 2017").
reporter_handler
);

if matches.is_present("zip") {
return unzip_core_loop(work_load);
}
let mtchs = matches.clone();

let crypt_runner = thread::spawn(move || {
if mtchs.is_present("zip") {
return unzip_core_loop(work_load);
}

return aescrypt_core_loop(work_load);
});

aescrypt_core_loop(work_load)
let _a = web_runner.join().unwrap();
crypt_runner.join().unwrap()
}

fn main() {
Expand Down
4 changes: 2 additions & 2 deletions src/reporter/spinner.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use ::reporter::Reporter;
use ::Digits;
use ::{Digits,ITERATIONS};
use std::io::{self, Write};

const SPINNER: &[char] = &['⠋','⠙','⠹','⠸','⠼','⠴','⠦','⠧','⠇','⠏'];
const SPINNER: [char; 10] = ['⠋','⠙','⠹','⠸','⠼','⠴','⠦','⠧','⠇','⠏'];

struct Spinner;

Expand Down
14 changes: 14 additions & 0 deletions src/web.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use tiny_http::{Server, Response};
use ::reporter::ReportData;
extern crate serde_json;

pub fn host_data(web_reporter: &ReportData) {
let server = Server::http("0.0.0.0:8000").unwrap();

for request in server.incoming_requests() {
let response = Response::from_string({
serde_json::to_string((&web_reporter)).unwrap_or("".to_string())
});
let _a = request.respond(response);
}
}

0 comments on commit a89ecb9

Please sign in to comment.