rust/hedgewars-server/src/server/io.rs
changeset 15937 e514ceb5e7d6
parent 15831 7d0f747afcb8
child 15938 ce47259d5c86
equal deleted inserted replaced
15936:c5c53ebb2d91 15937:e514ceb5e7d6
     1 use std::{
     1 use std::{
     2     fs::{File, OpenOptions},
     2     fs::{File, OpenOptions},
     3     io::{Error, ErrorKind, Read, Result, Write},
     3     io::{Error, ErrorKind, Read, Result, Write},
     4     sync::{mpsc, Arc},
     4     sync::{mpsc, Arc},
       
     5     task::Waker,
     5     thread,
     6     thread,
     6 };
     7 };
     7 
     8 
     8 use crate::{
     9 use crate::{
     9     handlers::{IoResult, IoTask},
    10     handlers::{IoResult, IoTask},
    21 impl IoThread {
    22 impl IoThread {
    22     pub fn new(waker: Waker) -> Self {
    23     pub fn new(waker: Waker) -> Self {
    23         let (core_tx, io_rx) = mpsc::channel();
    24         let (core_tx, io_rx) = mpsc::channel();
    24         let (io_tx, core_rx) = mpsc::channel();
    25         let (io_tx, core_rx) = mpsc::channel();
    25 
    26 
    26         let mut db = Database::new();
    27         /*let mut db = Database::new("localhost");
    27         db.connect("localhost");
       
    28 
    28 
    29         thread::spawn(move || {
    29         thread::spawn(move || {
    30             while let Ok((request_id, task)) = io_rx.recv() {
    30             while let Ok((request_id, task)) = io_rx.recv() {
    31                 let response = match task {
    31                 let response = match task {
    32                     IoTask::CheckRegistered { nick } => match db.is_registered(&nick) {
    32                     IoTask::CheckRegistered { nick } => match db.is_registered(&nick) {
   136                     }
   136                     }
   137                 };
   137                 };
   138                 io_tx.send((request_id, response));
   138                 io_tx.send((request_id, response));
   139                 waker.wake();
   139                 waker.wake();
   140             }
   140             }
   141         });
   141         });*/
   142 
   142 
   143         Self { core_rx, core_tx }
   143         Self { core_rx, core_tx }
   144     }
   144     }
   145 
   145 
   146     pub fn send(&self, request_id: RequestId, task: IoTask) {
   146     pub fn send(&self, request_id: RequestId, task: IoTask) {