handle response from IO result handler
authoralfadur
Sun, 02 Jun 2019 23:58:12 +0300
changeset 15107 80ff12edf5e6
parent 15106 f772013867e7
child 15108 823052e66611
handle response from IO result handler
rust/hedgewars-server/src/core/types.rs
rust/hedgewars-server/src/handlers.rs
rust/hedgewars-server/src/main.rs
rust/hedgewars-server/src/server/network.rs
--- a/rust/hedgewars-server/src/core/types.rs	Sun Jun 02 22:16:38 2019 +0200
+++ b/rust/hedgewars-server/src/core/types.rs	Sun Jun 02 23:58:12 2019 +0300
@@ -48,19 +48,19 @@
     pub hat: String,
 }
 
-#[derive(Clone, Serialize, Deserialize)]
+#[derive(Clone, Serialize, Deserialize, Debug)]
 pub struct Ammo {
     pub name: String,
     pub settings: Option<String>,
 }
 
-#[derive(Clone, Serialize, Deserialize)]
+#[derive(Clone, Serialize, Deserialize, Debug)]
 pub struct Scheme {
     pub name: String,
     pub settings: Vec<String>,
 }
 
-#[derive(Clone, Serialize, Deserialize)]
+#[derive(Clone, Serialize, Deserialize, Debug)]
 pub struct RoomConfig {
     pub feature_size: u32,
     pub map_type: String,
@@ -153,6 +153,7 @@
     }
 }
 
+#[derive(Debug)]
 pub struct Replay {
     pub config: RoomConfig,
     pub teams: Vec<TeamInfo>,
--- a/rust/hedgewars-server/src/handlers.rs	Sun Jun 02 22:16:38 2019 +0200
+++ b/rust/hedgewars-server/src/handlers.rs	Sun Jun 02 23:58:12 2019 +0300
@@ -30,7 +30,7 @@
 
 use std::fmt::{Formatter, LowerHex};
 
-#[derive(PartialEq)]
+#[derive(PartialEq, Debug)]
 pub struct Sha1Digest([u8; 20]);
 
 impl Sha1Digest {
@@ -48,6 +48,7 @@
     }
 }
 
+#[derive(Debug)]
 pub struct AccountInfo {
     pub is_registered: bool,
     pub is_admin: bool,
@@ -77,6 +78,7 @@
     },
 }
 
+#[derive(Debug)]
 pub enum IoResult {
     Account(Option<AccountInfo>),
     Replay(Option<Replay>),
--- a/rust/hedgewars-server/src/main.rs	Sun Jun 02 22:16:38 2019 +0200
+++ b/rust/hedgewars-server/src/main.rs	Sun Jun 02 23:58:12 2019 +0300
@@ -82,7 +82,7 @@
                         Err(e) => debug!("Error in timer event: {}", e),
                     },
                     #[cfg(feature = "official-server")]
-                    utils::IO_TOKEN => match hw_network.handle_io_result() {
+                    utils::IO_TOKEN => match hw_network.handle_io_result(&poll) {
                         Ok(()) => (),
                         Err(e) => debug!("Error in IO task: {}", e),
                     },
--- a/rust/hedgewars-server/src/server/network.rs	Sun Jun 02 22:16:38 2019 +0200
+++ b/rust/hedgewars-server/src/server/network.rs	Sun Jun 02 23:58:12 2019 +0300
@@ -20,18 +20,14 @@
 use crate::{
     core::{server::HwServer, types::ClientId},
     handlers,
-    protocol::{messages::*, ProtocolDecoder},
+    handlers::{IoResult, IoTask},
+    protocol::{messages::*, messages::HwServerMessage::Redirect, ProtocolDecoder},
     utils,
 };
 
 #[cfg(feature = "official-server")]
 use super::io::{IoThread, RequestId};
 
-use crate::{
-    handlers::{IoResult, IoTask},
-    protocol::messages::HwServerMessage::Redirect,
-};
-
 #[cfg(feature = "tls-connections")]
 use openssl::{
     error::ErrorStack,
@@ -456,10 +452,12 @@
     }
 
     #[cfg(feature = "official-server")]
-    pub fn handle_io_result(&mut self) -> io::Result<()> {
-        if let Some((client_id, result)) = self.io.try_recv() {
+    pub fn handle_io_result(&mut self, poll: &Poll) -> io::Result<()> {
+        while let Some((client_id, result)) = self.io.try_recv() {
+            debug!("Handling io result {:?} for client {}", result, client_id);
             let mut response = handlers::Response::new(client_id);
             handlers::handle_io_result(&mut self.server, client_id, &mut response, result);
+            self.handle_response(response, poll);
         }
         Ok(())
     }