socks users: detect closed sockets. (TROVE-2024-011)
Without this check, our socks code can enter an infinite loop if a socket is closed at the wrong time.
Resolves TROVE-2024-011.
Fixes #1635 (closed).
Additionally, this branch fixes a less severe bug in the use of copy_within, spotted by @opara.