'Return True if we know socket has been closed, False otherwise.'

def socket_closed(self, sock):

    while True:
        try:
            if self._poller:
                with self._lock:
                    self._poller.register(sock, _EVENT_MASK)
                    try:
                        rd = self._poller.poll(0)
                    finally:
                        self._poller.unregister(sock)
            else:
                (rd, _, _) = select.select([sock], [], [], 0)
        except (RuntimeError, KeyError):
            raise
        except ValueError:
            return True
        except (_SELECT_ERROR, IOError) as exc:
            if (_errno_from_exception(exc) in (errno.EINTR, errno.EAGAIN)):
                continue
            return True
        except:
            return True
        return (len(rd) > 0)
