Net.HTTP.H1.Pool
A client's connections: plain or TLS, read and written under its limits, and kept between requests in a pool per origin.
Pacing. A Paced connection bounds each read and write by two limits:
the request's total deadline, if it has one, and the stall limit, measured
from when the operation began or the last time a byte moved in either
direction, whichever is later. So the limit fires only on a peer that
stopped reading or sending, never on a caller that waited between reads.
A request body is written in one task while the response is read in
another, so a long upload must not stall out the read that waits for the
response's head: a read that times out while the other direction moved is
tried again, with the stall measured from that movement. A read that times out has taken no
byte, so trying it again loses nothing. A write is never tried again,
since one that timed out may have sent part of its buffer.
Carrying. Once a connection switches protocols, carry bounds each
read and write by the deadline the new protocol sets, or by nothing, and
by neither of the two limits: the protocol keeps its own time, and a
connection waiting for its peer's next message has not stalled.
A link is a connection with what it keeps from one exchange to the
next: its Paced, reset for each exchange, and the Input its responses
are read from. The input's array is reused until heads fill it, rather
than one made, and zero-filled, for every exchange; header values that
view it stay valid, since Input never writes over a head it handed out.
The pool keeps idle connections by origin -- scheme, host and port --
at most perOrigin of each and total in all, for at most idle each.
A connection is given back only by a caller that read its last message to
the exact end; this module trusts that. One taken out is the caller's
alone until it is given back or closed.
Every take and give sweeps the whole pool, closing each connection
idle too long and dropping origins left with none. Sweeping only the
origin asked for would leak: an origin never asked for again would keep
its connections, and a busy one would keep those below its freshest,
since take stops at the first fresh one. Each origin's connections are
kept oldest first, so the sweep reads only up to the first fresh one of
each. Past total, the oldest connection of any origin is closed.
A connection to a server, over TCP or TLS. Its errors are packed into
SomeError, so that an IOError and a TLSError travel the same way
and cast recovers either.
Closes c, ending every read and write parked on it. A failure to close
is dropped: the connection is not used again either way.
Ends c's output; the server can go on sending.
Whether e is a read or write that timed out.
Whether e is what a stale connection, one the server had already
closed, fails with: a reset, a broken pipe, or TLS ending without its
close_notify. A timeout is not: the server may be slow rather than gone.
Returns a link over c, whose reads and writes stall out after stall,
reading heads within limits.
Returns l's pacing, reset for a new exchange bounded by total: no
byte read yet, and the stall measured from now.
Bounds every later read and write on p by d alone, or by nothing.
Returns when the first byte was read from p, if one has been.
Records that a byte moved, as the other direction's limit reads it.
An idle connection, and when it was given back.
Returns an idle connection to origin, the most recently given back,
after closing every connection idle too long.
Keeps l for the next request to origin, after closing every
connection idle too long. Closes l instead if the origin has as many
idle connections as it may, and the pool's oldest if the pool then has
more than total. l's input must hold no byte.
Closes every idle connection.