ref-method and command merge #4

Merged
Mitch161 merged 39 commits from cmd--optimization into master 2020-08-19 21:29:44 +00:00
2 changed files with 19 additions and 11 deletions
Showing only changes of commit 81c5949de3 - Show all commits

View File

@ -8,6 +8,7 @@ enum Message {
Terminate,
}
#[derive(Debug)]
pub struct ThreadPool{
workers: Vec<Worker>,
sender: Sender<Message>,
@ -50,6 +51,7 @@ impl ThreadPool{
}
}
#[derive(Debug)]
struct Worker {
id: usize,
thread: Option<thread::JoinHandle<()>>,

View File

@ -1,5 +1,5 @@
//#![feature(test)]
#![allow(dead_code)]
#[macro_use]
extern crate lazy_static;
mod client_api;
mod commands;
@ -15,7 +15,7 @@ use cursive::{
align::Align,
view::SizeConstraint,
};
use std::sync::Arc;
//use std::sync::Arc;
use std::time::Duration;
use crossterm::ErrorKind;
use log::info;
@ -24,6 +24,12 @@ use clap::{App, Arg};
use crate::server::server_profile::Server;
fn main() -> Result<(), ErrorKind> {
lazy_static!{
static ref SERVER_NAME: &'static str = "Server-01";
static ref SERVER_ADDRESS: &'static str = "0.0.0.0:6000";
static ref SERVER_AUTHOR: &'static str = "noreply@email.com";
static ref SERVER: Server<'static> = Server::new(&SERVER_NAME, &SERVER_ADDRESS, &SERVER_AUTHOR);
}
let args = App::new("--rust chat server--")
.version("0.1.5")
@ -36,10 +42,10 @@ fn main() -> Result<(), ErrorKind> {
.get_matches();
if args.is_present("graphical") {
let server = Server::new("Server-01", "0.0.0.0:6000", "noreply@email.com");
let server_arc = Arc::new(server);
let s1 = server_arc.clone();
let s2 = s1.clone();
//let server = Server::new("Server-01", "0.0.0.0:6000", "noreply@email.com");
//let server_arc = Arc::new(server);
//let s1 = server_arc.clone();
//let s2 = s1.clone();
cursive::logger::init();
@ -61,8 +67,8 @@ fn main() -> Result<(), ErrorKind> {
.leaf("quit", |s| s.quit()))
.add_subtree("File",
MenuTree::new()
.leaf("Start", move |_s| {let _ = s1.start();})
.leaf("Stop", move |_s| {let _ = s2.stop();})
.leaf("Start", move |_s| {let _ = SERVER.start();})
.leaf("Stop", move |_s| {let _ = SERVER.stop();})
.delimiter()
.leaf("Debug", |s| {s.toggle_debug_console();}));
info!("Main: entering loop");
@ -70,8 +76,8 @@ fn main() -> Result<(), ErrorKind> {
display.run();
Ok(())
} else {
let server = Server::new("Server-01", "0.0.0.0:6000", "noreply@email.com");
server.start()?;
//let server = Server::new("Server-01", "0.0.0.0:6000", "noreply@email.com");
SERVER.start()?;
loop {std::thread::sleep(Duration::from_secs(1));}
}
}