Added the beginning of the threaded code.
This commit is contained in:
parent
c47b511e04
commit
8ab294277b
1 changed files with 50 additions and 35 deletions
85
src/main.rs
85
src/main.rs
|
@ -23,6 +23,11 @@ use std::{
|
||||||
env::args,
|
env::args,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
collections::VecDeque,
|
collections::VecDeque,
|
||||||
|
sync::mpsc::{
|
||||||
|
channel,
|
||||||
|
Sender,
|
||||||
|
},
|
||||||
|
thread,
|
||||||
};
|
};
|
||||||
use irc_proto::command::{
|
use irc_proto::command::{
|
||||||
CapSubCommand,
|
CapSubCommand,
|
||||||
|
@ -134,41 +139,7 @@ fn handle_message(message: Message) -> Option<Message> {
|
||||||
return None
|
return None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn handle_server(config: Value, tx: Sender<[String; 4]>) {
|
||||||
let mut server_conf_flag = false;
|
|
||||||
let mut config_path = None;
|
|
||||||
let mut server_conf_path = None;
|
|
||||||
for arg in args().skip(1) {
|
|
||||||
match arg.as_str() {
|
|
||||||
"-s" => server_conf_flag = true,
|
|
||||||
"-h" => {
|
|
||||||
println!("Usage: mention2mail [config file] [-s server config directory]");
|
|
||||||
},
|
|
||||||
_ => if server_conf_flag {
|
|
||||||
server_conf_path = Some(arg);
|
|
||||||
} else {
|
|
||||||
config_path = Some(arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let config;
|
|
||||||
|
|
||||||
match config_path {
|
|
||||||
Some(p) => config = config::get_main_config(PathBuf::from(p))
|
|
||||||
.expect("Could not get config"),
|
|
||||||
None => config = config::get_main_config(PathBuf::from("/etc/Mention2Mail/config.toml"))
|
|
||||||
.expect("Could not get default config in /etc/Mention2Mail/default.toml"),
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut server_configs;
|
|
||||||
|
|
||||||
match server_conf_path {
|
|
||||||
Some(p) => server_configs = config::get_server_configs(config, PathBuf::from(p))
|
|
||||||
.expect("Could not get server config."),
|
|
||||||
None => (),
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut stream = connect::connect_irc(&config).unwrap();
|
let mut stream = connect::connect_irc(&config).unwrap();
|
||||||
|
|
||||||
let mut message_queue = get_irc_identify_messages(&config).unwrap();
|
let mut message_queue = get_irc_identify_messages(&config).unwrap();
|
||||||
|
@ -225,3 +196,47 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut server_conf_flag = false;
|
||||||
|
let mut config_path = None;
|
||||||
|
let mut server_conf_path = None;
|
||||||
|
for arg in args().skip(1) {
|
||||||
|
match arg.as_str() {
|
||||||
|
"-s" => server_conf_flag = true,
|
||||||
|
"-h" => {
|
||||||
|
println!("Usage: mention2mail [config file] [-s server config directory]");
|
||||||
|
},
|
||||||
|
_ => if server_conf_flag {
|
||||||
|
server_conf_path = Some(arg);
|
||||||
|
} else {
|
||||||
|
config_path = Some(arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let config;
|
||||||
|
|
||||||
|
match config_path {
|
||||||
|
Some(p) => config = config::get_main_config(PathBuf::from(p))
|
||||||
|
.expect("Could not get config"),
|
||||||
|
None => config = config::get_main_config(PathBuf::from("/etc/Mention2Mail/config.toml"))
|
||||||
|
.expect("Could not get default config in /etc/Mention2Mail/default.toml"),
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut server_configs;
|
||||||
|
|
||||||
|
match server_conf_path {
|
||||||
|
Some(p) => server_configs = config::get_server_configs(config, PathBuf::from(p))
|
||||||
|
.expect("Could not get server config."),
|
||||||
|
None => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
let (tx,rx) = channel();
|
||||||
|
|
||||||
|
for s_conf in server_configs {
|
||||||
|
// TODO: create channel and spawn server threads
|
||||||
|
handle_server(s_conf, tx.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue