Fix listener socket shutdown on OSX

Calling socket.shutdown() on OSX is causing socket error 57 (socket is
not connected) so catch this exception and call close() on the socket
when it occurs. Appears to fix the issue without any bad side-effects.