Call socket.shutdown before socket.close

Need for some platforms, like what Travis-CI is running.