The previous behaviour was unsound, as it was prone to dropping
connections under (temporary) high load. The new behaviour requires that
users are well-behaved with respect to shutdown - the root listener
must be shut down before any of the child listeners are, otherwise
deadlocks may occur. This requirement seems reasonable.
When the root listener is closed, child listeners will not be closed
until all parked connections are served. This prevents losing
connections that have been read from.
This also allows moving the main test to package cmux_test, but that
will happen in a separate change.
cmux.go:28:1: exported method ErrNotMatched.Temporary should have comment or be unexported
cmux.go:29:1: exported method ErrNotMatched.Timeout should have comment or be unexported
cmux.go:38:2: exported var ErrListenerClosed should have comment or be unexported
cmux.go:165:6: exported type MuxConn should have comment or be unexported
As reported in #4, when the root listener is closed, calling Accept
on mux'd listeners would block forever, instead of returning an error.
This is because of a bug introduced in b90740d.
This commit fixes#4 by selecting on both donec and connc of muxed
listeners.
Added a test case to guard against this issue.
If a matcher go-routine mateches a connection after the root
listener was closed, cmux will panic since all connection channels
will be closed. This commit avoids closing connection channels but
signals the matcher go-routines that the listener is closed via
a done channel.
Tested: Added a test case for this issue.