The previous use of a timeout resulting in thread detach instead of thread
join resulted in a race condition on Mac between destruction and thread
closeout. This commit removes the detach functionality and uses dup2() to
on Linux/Mac and connecting to itself on Windows to try to ensure accept()
exits.
Windows returns WSAEWOULDBLOCK on a connect() attempt on a nonblocking socket.
Also wrap socket error handling so errors are correctly reported on Windows.
Fixes#19.