Use SOCKET_OK/TOR_INVALID_SOCKET in socketpair replacement code
Avoid a double-close on one failing case of the socketpair replacement code

Fix for bug 9400, spotted by coverity. Bug introduced in revision 2cb4f7a4
(subversion revision r389).
Merge branch 'bug9400_024_squashed' into maint-0.2.4