summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs
index a230a7e..03f9e02 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -5,8 +5,10 @@ extern crate irc;
extern crate serde;
extern crate serde_json;
+use std::sync::Arc;
use std::collections::HashMap;
use std::io::Read;
+use std::thread;
use hyper::Client;
use hyper::header::Connection;
@@ -74,11 +76,11 @@ fn extract_username(prefix: Option<String>) -> Option<String> {
}
struct IrcBot<T: IrcRead, U: IrcWrite> {
- server: IrcServer<T, U>,
+ server: Arc<IrcServer<T, U>>,
}
impl<T: IrcRead, U: IrcWrite> IrcBot<T, U> {
- fn new(server: IrcServer<T, U>) -> IrcBot<T, U> {
+ fn new(server: Arc<IrcServer<T, U>>) -> IrcBot<T, U> {
IrcBot {
server: server,
}
@@ -149,9 +151,19 @@ fn main() {
.. Default::default()
};
- let server = IrcServer::from_config(config).unwrap();
+ let server = Arc::new(IrcServer::from_config(config).unwrap());
server.identify().unwrap();
- let bot = IrcBot::new(server);
- bot.process_messages();
+ let mut handles = Vec::new();
+ for _ in 0..4 {
+ let s = server.clone();
+ handles.push(thread::spawn(move || {
+ let bot = IrcBot::new(s.clone());
+ bot.process_messages();
+ }));
+ }
+
+ for handle in handles.into_iter() {
+ handle.join();
+ }
}