325 let client = NetworkClient::new(id, client_socket, addr); |
325 let client = NetworkClient::new(id, client_socket, addr); |
326 info!("client {} ({}) added", client.id, client.peer_addr); |
326 info!("client {} ({}) added", client.id, client.peer_addr); |
327 entry.insert(client); |
327 entry.insert(client); |
328 } |
328 } |
329 |
329 |
330 fn flush_server_messages(&mut self) { |
330 fn flush_server_messages(&mut self, mut response: handlers::Response) { |
331 debug!("{} pending server messages", self.server.output.len()); |
331 debug!("{} pending server messages", response.len()); |
332 for (clients, message) in self.server.output.drain(..) { |
332 let output = response.extract_messages(&mut self.server); |
|
333 for (clients, message) in output { |
333 debug!("Message {:?} to {:?}", message, clients); |
334 debug!("Message {:?} to {:?}", message, clients); |
334 let msg_string = message.to_raw_protocol(); |
335 let msg_string = message.to_raw_protocol(); |
335 for client_id in clients { |
336 for client_id in clients { |
336 if let Some(client) = self.clients.get_mut(client_id) { |
337 if let Some(client) = self.clients.get_mut(client_id) { |
337 client.send_string(&msg_string); |
338 client.send_string(&msg_string); |
430 &e, |
431 &e, |
431 "Error while reading from client socket", |
432 "Error while reading from client socket", |
432 )?, |
433 )?, |
433 } |
434 } |
434 |
435 |
435 self.flush_server_messages(); |
436 if !response.is_empty() { |
|
437 self.flush_server_messages(response); |
|
438 } |
436 |
439 |
437 if !self.server.removed_clients.is_empty() { |
440 if !self.server.removed_clients.is_empty() { |
438 let ids: Vec<_> = self.server.removed_clients.drain(..).collect(); |
441 let ids: Vec<_> = self.server.removed_clients.drain(..).collect(); |
439 for client_id in ids { |
442 for client_id in ids { |
440 self.deregister_client(poll, client_id); |
443 self.deregister_client(poll, client_id); |