about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <programble@gmail.com>2017-08-08 20:44:22 -0400
committerJune McEnroe <programble@gmail.com>2017-08-08 20:44:22 -0400
commit1f410444568f733e8044b6f60a53c704cfbc0c6f (patch)
tree2b8cfaf555629125c474963aa5d7ed3d25bd5544
parentReverse order of main loop (diff)
downloadtorus-1f410444568f733e8044b6f60a53c704cfbc0c6f.tar.gz
torus-1f410444568f733e8044b6f60a53c704cfbc0c6f.zip
Completely retry if a send fails during a broadcast
This fixes a bug where the saved next client to iterate through would
also get removed.

This can result in messages being sent multiple times to a client, but
that will have no negative effect.
-rwxr-xr-xserver.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/server.c b/server.c
index 64e4e18..2fcdff7 100755
--- a/server.c
+++ b/server.c
@@ -123,16 +123,15 @@ static bool clientSend(const struct Client *client, const struct ServerMessage *
 }
 
 static void clientCast(const struct Client *origin, const struct ServerMessage *msg) {
+retry:
     for (struct Client *client = clientHead; client; client = client->next) {
         if (client == origin) continue;
         if (client->tileX != origin->tileX) continue;
         if (client->tileY != origin->tileY) continue;
 
         if (!clientSend(client, msg)) {
-            struct Client *dead = client;
-            client = client->next;
-            clientRemove(dead);
-            if (!client) break;
+            clientRemove(client);
+            goto retry;
         }
     }
 }