]> git.pond.sub.org Git - empserver/commitdiff
(pr_player, upr_player): Blocking I/O on another player's struct iop *
authorRon Koenderink <rkoenderink@yahoo.ca>
Mon, 4 Jul 2005 14:07:31 +0000 (14:07 +0000)
committerRon Koenderink <rkoenderink@yahoo.ca>
Mon, 4 Jul 2005 14:07:31 +0000 (14:07 +0000)
is unsafe!  By the time the blocked thread wakes up, that player may
be gone, along with its struct iop *, and io_write() follows a
dangling pointer.  Moreover, at most one thread may use empth_select()
on the same file descriptor.  Violations of that restriction cause
threads to hang under Windows since ntthread.c rev. 1.15.  Make all
output to another player non-blocking for now.  Historically, player
threads sent output only to their socket, though their own iop.  This
was broken by flash and asynchronous telegram notification a long time
ago.

src/lib/subs/pr.c

index 3cb8d08de854750d18fd2e78aa0ffffffe30fee8..a382c8c9e1ec4ee73e577d47cdc7f0e93f4e0704 100644 (file)
@@ -220,7 +220,8 @@ pr_player(struct player *pl, int id, char *buf)
        p = strchr(bp, '\n');
        if (p != NULL) {
            len = (p - bp) + 1;
-           if (pl->command && (pl->command->c_flags & C_MOD))
+           if ((pl->command && (pl->command->c_flags & C_MOD)) ||
+               (player != pl))
                io_write(pl->iop, bp, len, IO_NOWAIT);
            else
                io_write(pl->iop, bp, len, IO_WAIT);
@@ -274,7 +275,8 @@ upr_player(struct player *pl, int id, char *buf)
            }
        }
        if (ch == '\n') {
-           if (pl->command && (pl->command->c_flags & C_MOD))
+           if ((pl->command && (pl->command->c_flags & C_MOD)) ||
+               (player != pl))
                io_write(pl->iop, &ch, 1, IO_NOWAIT);
            else
                io_write(pl->iop, &ch, 1, IO_WAIT);