Implement cancelling listening on a socket.