read_bounded_line read at most max + 1 bytes, so a line of exactly max
bytes followed by \r\n stopped after the \r and was refused, while the
same line followed by \n was read. It now reads up to max + 2 bytes,
strips the \n and a \r before it, and then checks the line against max.
A line of max + 1 bytes is still refused with either ending.
A line that is read before the first request is admitted but completes
after the first-request deadline is no longer answered with an error
reply when it is not a request (bad JSON, a failed token check or an
oversized line). serve_tcp closes the connection without a reply, as it
does for a request read after the deadline.
A request read just after the deadline, for example because the thread
paused between the deadline check and the socket read, was admitted and
dispatched. admit now returns TimedOut when the deadline has passed and
leaves it in place, so the connection closes without a reply.
Tests: a request admitted at the deadline is refused, and a read after
the deadline fails even with input waiting on the socket, so input that
arrives before each read does not extend the deadline.
serve_tcp serves one TCP connection with the same framing and
authentication as serve_lines, and gives the peer a deadline for its
first authenticated request. Every read before that request shares the
one deadline, so blank lines or a line sent a byte at a time do not
extend it. When it passes, the connection closes with no reply and
nothing is dispatched. After the first request, each read waits at most
the idle time the caller passes.
serve_lines waits for the first line as long as the caller's read
timeout, so a local connection that never sends a request keeps its
connection slot for that whole time.
new_token returns 32 bytes from the operating system's random source as
64 lowercase hexadecimal characters, the form valid_token checks. A
server built on serve_lines can now create its per-launch token without
its own random source. The function and its getrandom dependency are
left out on wasm32.
serve_lines wrote replies with writeln!, which hands the writer every
string, number and separator of the JSON value as a separate write. On
an unbuffered TcpStream that is one system call per piece. Replies and
the closing rejection now go through a 64 KiB BufWriter and are flushed
once per line, so a small reply is one write and a large one is a few
buffer-sized writes without a second whole copy in memory.