Skip to content

Commit f7dc18f

Browse files
Flush the TCP Stream on the server
1 parent 175fa16 commit f7dc18f

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/multiplayer/plumbing.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::{
2-
io::Read,
2+
io::{Read, Write},
33
marker::PhantomData,
44
mem,
55
net::TcpStream,
@@ -216,6 +216,7 @@ impl<ItemIdxType: IdxTrait, RecipeIdxType: IdxTrait> ActionSource<ItemIdxType, R
216216
log::info!("Sending GameState to new connection");
217217
if let Err(err) = new_conn.set_nonblocking(false) {
218218
log::warn!("Failed setting connction to blocking: {:?}", err);
219+
continue;
219220
}
220221

221222
let mut compressed =
@@ -246,6 +247,12 @@ impl<ItemIdxType: IdxTrait, RecipeIdxType: IdxTrait> ActionSource<ItemIdxType, R
246247

247248
if let Err(err) = new_conn.set_nonblocking(true) {
248249
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;
249256
}
250257

251258
self.client_connections.lock().push(new_conn);
@@ -282,8 +289,9 @@ impl<ItemIdxType: IdxTrait, RecipeIdxType: IdxTrait>
282289
) {
283290
let actions: Vec<_> = actions.into_iter().collect();
284291
// 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();
287295

288296
// let keep = serde_json::to_writer(conn, &actions).is_ok();
289297

0 commit comments

Comments
 (0)