]> git.pond.sub.org Git - empserver/commit
Move queue flush out of io.c
authorMarkus Armbruster <armbru@pond.sub.org>
Mon, 27 Apr 2009 21:23:30 +0000 (23:23 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 19 Jul 2009 18:11:53 +0000 (14:11 -0400)
commit1b4496253dd973ed9099ae2cc3888b24631cdb7d
tree04b6f4ade44459137fc94afdf09dee3f253c13d9
parent7fd5b869905dd5c904a750a43982b44a83d05a64
Move queue flush out of io.c

Player threads may only sleep under certain conditions.  In
particular, they must not sleep while a command is being aborted by
the update or shutdown.

io.c should not know about that.  Yet io_output_all() does, because it
needs to give up when update or shutdown interrupt it.  The function
was introduced in Empire 2, but it didn't give up then.  Fixed in
commit a7fa7dee, v4.2.22.  The fix dragged unwanted knowledge of
command abortion into io.c.

To clean up this mess, io_output_all() has to go.

First user is io_write().  io_write() automatically flushes the queue.
In wait-mode, it calls io_output_all() when the queue is longer than
the bufsize, to attempt flushing the queue completely.  In
no-wait-mode, it calls io_output() every bufsize bytes.  Except the
test for that is screwy, so it actually misses some of the flush
conditions.

The automatic flush makes io_write() differ from io_gets(), which is
ugly.  It wasn't present in BSD Empire 1.1.  Remove it again, dropping
io_write()'s last argument.

Flush the queue in its callers pr_player() and upr_player() instead.
Provide new io_output_if_queue_long() for them.  Requires new struct
iop member last_out to keep track of queue growth.  pr_player() and
upr_player() call repeatedly until it makes no more progress.  This
flushes a bit less eagerly in wait-mode, and a bit more eagerly in
non-wait mode.

Second user is recvclient().  It needs to flush the queue before
potentially sleeping in io_input().  Do that with a simple loop around
io_output().  No functional change there.
include/empio.h
src/lib/empthread/io.c
src/lib/player/recvclient.c
src/lib/subs/pr.c