|
1 | 1 | use std::{ |
2 | | - io::Read, |
| 2 | + io::{Read, Write}, |
3 | 3 | marker::PhantomData, |
4 | 4 | mem, |
5 | 5 | net::TcpStream, |
@@ -216,6 +216,7 @@ impl<ItemIdxType: IdxTrait, RecipeIdxType: IdxTrait> ActionSource<ItemIdxType, R |
216 | 216 | log::info!("Sending GameState to new connection"); |
217 | 217 | if let Err(err) = new_conn.set_nonblocking(false) { |
218 | 218 | log::warn!("Failed setting connction to blocking: {:?}", err); |
| 219 | + continue; |
219 | 220 | } |
220 | 221 |
|
221 | 222 | let mut compressed = |
@@ -246,6 +247,12 @@ impl<ItemIdxType: IdxTrait, RecipeIdxType: IdxTrait> ActionSource<ItemIdxType, R |
246 | 247 |
|
247 | 248 | if let Err(err) = new_conn.set_nonblocking(true) { |
248 | 249 | log::warn!("Failed setting connction to blocking: {:?}", err); |
| 250 | + continue; |
| 251 | + } |
| 252 | + |
| 253 | + if let Err(err) = new_conn.flush() { |
| 254 | + log::warn!("Flushing failed: {:?}", err); |
| 255 | + continue; |
249 | 256 | } |
250 | 257 |
|
251 | 258 | self.client_connections.lock().push(new_conn); |
@@ -282,8 +289,9 @@ impl<ItemIdxType: IdxTrait, RecipeIdxType: IdxTrait> |
282 | 289 | ) { |
283 | 290 | let actions: Vec<_> = actions.into_iter().collect(); |
284 | 291 | // Send the actions to the clients |
285 | | - self.client_connections.lock().retain(|conn| { |
286 | | - let keep = postcard::to_io(&actions, conn).is_ok(); |
| 292 | + self.client_connections.lock().retain(|mut conn| { |
| 293 | + let mut keep = postcard::to_io(&actions, conn).is_ok(); |
| 294 | + keep &= conn.flush().is_ok(); |
287 | 295 |
|
288 | 296 | // let keep = serde_json::to_writer(conn, &actions).is_ok(); |
289 | 297 |
|
|
0 commit comments