]> git.pond.sub.org Git - empserver/commit
Fix server shutdown to let player output drain properly
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 29 Jan 2012 11:06:30 +0000 (12:06 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Tue, 21 Feb 2012 17:11:13 +0000 (18:11 +0100)
commit904822e3449f35ab1dd7a0cbaa924b4e0a406a0a
tree7a53ec983fa520d255b609e3639335b7ed84ac04
parent8549efbc1904e377c05e385844fe1adada61d573
Fix server shutdown to let player output drain properly

Commit 1e1dfc86 (v4.3.23) attempted to do this, but it's flawed.

Server shutdown makes the player command loops terminate.  Each player
thread then flushes buffered output and closes the server's end of the
connection.  The client eventually gets EOF, and closes its end of the
connection.  All is well.

However, if the client sends more input after the server closed its
end of the connection, but before it completed receiving server
output, it gets ECONNRESET, and the remaining output is lost.

Instead of closing the server's end of the connection, we need to shut
down its transmission direction, then wait for the client to close its
end, by receiving client input until EOF.  Do that in io_close().

The output flushing in player_login() is now superfluous.  Remove it.

Make shutdwn() wait for the io_close() to complete instead of output
queues to drain.  Without that, we could still close the server's end
of the connection prematurely, through program termination.  Change
player_delete() to keep the player in Players until after io_close()
completes, so that shutdwn() can detect completion.
src/lib/empthread/io.c
src/lib/player/accept.c
src/lib/player/login.c
src/server/main.c