Bug fix for windows: closesocket (Issue #447)

fixed close error (Issue #447)
and build error (Issue #422, Issue #451)
(include a patch by @ccoenen)