Avoid use-after-free if the socket is disconnected before ConnectStream connects (#308), and avoid leaks and hangs if client construct() calls throw (#309). Also add tests to cover these and other client connection errors, as suggested by @ryanofsky.
The following cases are tested:
- Connecting to a socket serving a valid init interface
- Passing a disconnected socket (
ConnectStreamthrows during theconstruct()call) - Passing a disconnected socket to an interface without
construct()(the failure is deferred to the first IPC request) - Passing a disconnected socket and making no calls (the disconnect is still handled and the connection cleaned up)
- Passing a live socket that disconnects after some data is received
- Passing a socket from a listening socket (
accept()) that disconnects after some data arrives
Additionally, a new FooInit test interface is added, and the UnixListener class introduced in #269 is extracted to a shared file so the new connect_tests.cpp file can use it.
Note: Clients that own their connection now delete it on unexpected disconnects, so calls after a server disconnect fail with "called after disconnect" instead of "interrupted by disconnect" (one test.cpp assertion updated accordingly).