Presently, the connection to a device is closed as soon as the command channel is closed.
However, a command channel may be closed by library users in a situation where
a) there are no more commands to send, but
b) there is still data to receive (e.g. from a long-running /listen command)
In this PR, the connection will stay alive until either
a) a fatal error occurs, or TCP socket is closed by far end (as per existing "shutdown" cases), or
b) both the command channel is closed, and all running_commands complete.
Presently, the connection to a device is closed as soon as the command channel is closed.
However, a command channel may be closed by library users in a situation where a) there are no more commands to send, but b) there is still data to receive (e.g. from a long-running /listen command)
In this PR, the connection will stay alive until either a) a fatal error occurs, or TCP socket is closed by far end (as per existing "shutdown" cases), or b) both the command channel is closed, and all running_commands complete.