rust/hedgewars-server/src/server/network.rs
changeset 14701 8a45c90f4580
parent 14698 6a2e13e36b7f
child 14702 f64e21f164a5
--- a/rust/hedgewars-server/src/server/network.rs	Thu Feb 07 18:04:53 2019 +0300
+++ b/rust/hedgewars-server/src/server/network.rs	Thu Feb 07 22:26:56 2019 +0300
@@ -330,7 +330,7 @@
         client_id
     }
 
-    fn flush_server_messages(&mut self, mut response: handlers::Response) {
+    fn flush_server_messages(&mut self, mut response: handlers::Response, poll: &Poll) {
         debug!("{} pending server messages", response.len());
         let output = response.extract_messages(&mut self.server);
         for (clients, message) in output {
@@ -344,6 +344,10 @@
                 }
             }
         }
+
+        for client_id in response.extract_removed_clients() {
+            self.deregister_client(poll, client_id);
+        }
     }
 
     fn create_client_socket(&self, socket: TcpStream) -> io::Result<ClientSocket> {
@@ -381,7 +385,7 @@
         handlers::handle_client_accept(&mut self.server, client_id, &mut response);
 
         if !response.is_empty() {
-            self.flush_server_messages(response);
+            self.flush_server_messages(response, poll);
         }
 
         Ok(())
@@ -438,14 +442,7 @@
         }
 
         if !response.is_empty() {
-            self.flush_server_messages(response);
-        }
-
-        if !self.server.removed_clients.is_empty() {
-            let ids: Vec<_> = self.server.removed_clients.drain(..).collect();
-            for client_id in ids {
-                self.deregister_client(poll, client_id);
-            }
+            self.flush_server_messages(response, poll);
         }
 
         Ok(())
@@ -476,7 +473,7 @@
         self.deregister_client(poll, client_id);
         let mut response = handlers::Response::new(client_id);
         handlers::handle_client_loss(&mut self.server, client_id, &mut response);
-        self.flush_server_messages(response);
+        self.flush_server_messages(response, poll);
 
         Ok(())
     }