Reset the last command only on tagged responses

The command should be reset even if there is a custom response, but
not with untagged responses that may be part of the command result.
Handle multiple connections

To allow multiple simultaneous connections, two approaches are possible:

a. fork off a new client (process or thread) for each connection
b. use a finite state machine and use poll()

I choose the latter, because

1. cached values should be shared, so one process per connection is
   inefficient
2. multithreading would require locking of shared resources (e.g. calls
   into crash, which is not thread-safe)
3. converting the code to a FSM is relatively easy, though not trivial
cleanup: remove conn_again

This state is not needed, after all.
cleanup: convert a switch statement to table lookup

There shouldn't be much of a difference in the resulting code, but
it looks better.
cleanup: provide a function to destroy all connections
Prepare for multiple servers

The main motivation, however, is the change in the termination logic.
After this change, it's possible to shut down the listening socket
while still delivering BYE messages to clients.
conn_done: fix check for a valid FD

Zero is a valid FD, negative is not...
Close connection if shutdown() fails

Sending back an error message was not so useful...
cleanup: don't set connection handler from SYMBOL_on_read

The handler now always defaults to finish_response, so there's no need
to set it explicitly to that value.
Preserve return status of do_readcommand

Without doing that, the connection loops on EOF, because the EOF is
handled by conn_readcommand, and the result from finish_response() is
(usually) conn_ok, so the connection is never terminated.
Terminate all sessions on server shutdown

The logic revolves around term_state. Under normal conditions, the state
is conn_running, and the FSM operates as usual.

If the field is set to conn_bye_pending, the FSM will send out a BYE
message when it sends the next response. The previous message is
preserved (so you get a tagged response to the TERMINATE command) and
sent after the BYE message. The read part of the socket is shut down.

After that, the state is bumped to conn_bye_sent to prevent further BYE
messages (e.g. because of TERMINATE commands sent to other connections).

Note that do_TERMINATE doesn't call disconnect() directly, but since
all the state is "broadcast" to all connections, the originating
connection gets it, too.
Hook the BYE code in the main loop instead of conn_respond

While the hook in conn_respond() works fine for any busy connection,
it fails to send the message on an idle one (i.e. when it is waiting
for a command).

However, since we can't insert the BYE message anywhere in the stream
(e.g. it would be ignored/misunderstood inside a literal), we must wait
for a quiescent period.

The idle case can be "fixed" by checking in the main server loop (just
before polling), but this place doesn't work for busy connections,
because they will always have something to send. That's why we also
call it from handle_conn, i.e. right after raw I/O is finished and
before new output can be queued by a handler.

Note that we must preserve the wait events, because the code is now
hooked at a very low level.
Distinguish between connection status and protocl condition codes

These two concepts are completely distinct in fact, and mixing them up
is harmful to error handling.

Let's get it straight:

* condition codes specify what is being sent in a response,
* connection status tells whether the connection is usable or not
cleanup: Fix the mess in send_untagged

Get rid of setting the overall condition code temporarily and adjusting
it if there is an error. Errors should be handled by callers of
send_untagged. Plus, if there is a hard error on the connection, it may
not be possible to send the error message anyway...
Fix missing tag in the response if there is no command
Fix copy_string apparent failures on zero-sized strings

If the destination is NULL, copy_string() may return NULL, although
there is no error.
Non-blocking literal output for READMEM

The READMEM command is broken without this, because send_untagged now
uses the polled I/O, so it doesn't send anything immediately.
Fix scanning of numbers

The strtoul() function may fail at end of line if there is garbage from
a previous command. Let's copy the number out into a temporary location
and convert it from there.

This has the advantage of providing a convenience function for numeric
conversions.