]> git.pond.sub.org Git - empserver/commitdiff
(io_output_all,update_main,update_wait): Do not block on writing when
authorRon Koenderink <rkoenderink@yahoo.ca>
Sun, 21 Aug 2005 17:17:38 +0000 (17:17 +0000)
committerRon Koenderink <rkoenderink@yahoo.ca>
Sun, 21 Aug 2005 17:17:38 +0000 (17:17 +0000)
aborting commands for an update.  Move update_pending to the start of
the update sequence where the commands are aborted.

src/lib/gen/io.c
src/lib/update/main.c
src/server/update.c

index 389cfc8813a29cd9bd924c8eb00239c57fed732a..bf77d0f27698abf6299fd43721e848b6d5ae33e7 100644 (file)
@@ -62,6 +62,7 @@
 #include "ioqueue.h"
 #include "empio.h"
 #include "gen.h"               /* getfdtablesize */
+#include "server.h"
 
 #include "empthread.h"
 
@@ -337,7 +338,11 @@ io_output_all(struct iop *iop)
 {
     int n;
 
-    while ((n = io_output(iop, IO_NOWAIT)) > 0) {
+    /*
+     * Mustn't block a player thread while update is pending, or else
+     * a malicous player could delay the update indefinitely
+     */
+    while (((n = io_output(iop, IO_NOWAIT)) > 0) && !update_pending) {
        empth_select(iop->fd, EMPTH_FD_WRITE);
     }
     return n;
index 0c265e2dacd70fd4b1be5b59aecaf2dc6416e31c..c1ebf886a7b3dc942edad329b71ca94383a8d7d0 100644 (file)
@@ -74,6 +74,9 @@ update_main(void *unused)
     struct natstr *cnp;
     struct natstr *np;
 
+    if (CANT_HAPPEN(!update_pending))
+        update_pending = 1;
+
     /* First, make sure all mobility is updated correctly. */
     if (opt_MOB_ACCESS) {
        mob_ship(etu);
@@ -81,7 +84,6 @@ update_main(void *unused)
        mob_plane(etu);
        mob_land(etu);
     }
-    update_pending = 1;
     player->proc = empth_self();
     player->cnum = 0;
     player->god = 1;
index 015747f6d763acdca223dcfdd2bf8cf7662a7118..f4026bd449a0d1ef41460b0fcc38c46bfa35ebbb 100644 (file)
@@ -120,6 +120,7 @@ update_wait(void *unused)
 
     while (1) {
        empth_sem_wait(update_sem);
+       update_pending = 1;
        running = 0;
        for (p = player_next(0); p != 0; p = player_next(p)) {
            if (p->state != PS_PLAYING)
@@ -137,8 +138,10 @@ update_wait(void *unused)
            empth_sleep(now + 2);
        }
        if (*pre_update_hook) {
-           if (run_hook(pre_update_hook, "pre-update"))
+           if (run_hook(pre_update_hook, "pre-update")) {
+               update_pending = 0;
                continue;
+           }
        }
        /* 
         * we rely on the fact that update's priority is the highest
@@ -147,6 +150,7 @@ update_wait(void *unused)
        dp = player_new(0, 0);
        if (!dp) {
            logerror("can't create dummy player for update");
+           update_pending = 0;
            continue;
        }
        stacksize = 100000 +