13 use mio::{Evented, Poll, PollOpt}; |
13 use mio::{Evented, Poll, PollOpt}; |
14 use mio_extras::channel; |
14 use mio_extras::channel; |
15 |
15 |
16 pub type RequestId = u32; |
16 pub type RequestId = u32; |
17 |
17 |
18 pub struct IOThread { |
18 pub struct IoThread { |
19 core_tx: mpsc::Sender<(RequestId, IoTask)>, |
19 core_tx: mpsc::Sender<(RequestId, IoTask)>, |
20 core_rx: channel::Receiver<(RequestId, IoResult)>, |
20 core_rx: channel::Receiver<(RequestId, IoResult)>, |
21 } |
21 } |
22 |
22 |
23 impl IOThread { |
23 impl IoThread { |
24 pub fn new() -> Self { |
24 pub fn new() -> Self { |
25 let (core_tx, io_rx) = mpsc::channel(); |
25 let (core_tx, io_rx) = mpsc::channel(); |
26 let (io_tx, core_rx) = channel::channel(); |
26 let (io_tx, core_rx) = channel::channel(); |
27 |
27 |
28 let mut db = Database::new(); |
28 let mut db = Database::new(); |
29 db.connect("localhost"); |
29 db.connect("localhost"); |
30 |
30 |
31 thread::spawn(move || { |
31 thread::spawn(move || { |
32 while let Ok((request_id, task)) = io_rx.try_recv() { |
32 while let Ok((request_id, task)) = io_rx.recv() { |
33 let response = match task { |
33 let response = match task { |
34 IoTask::GetAccount { |
34 IoTask::GetAccount { |
35 nick, |
35 nick, |
36 protocol, |
36 protocol, |
37 password_hash, |
37 password_hash, |