Cross platform fix for closing sockets