def _do_listen(self, addr, family, backlog, slave):
        """
        A callback method to be used with
        :meth:`~pants._channel._Channel._resolve_addr` - either listens
        immediately or notifies the user of an error.

        =========  =====================================================
        Argument   Description
        =========  =====================================================
        backlog    The maximum size of the connection queue.
        slave      If True, this will cause a Server listening on
                   IPv6 INADDR_ANY to create a slave Server that
                   listens on the IPv4 INADDR_ANY.
        addr       The address to listen on or None if address
                   resolution failed.
        family     The detected socket family or None if address
                   resolution failed.
        error      *Optional.* Error information or None if no error
                   occurred.
        =========  =====================================================
        """
        if self._socket:
            if self._socket.family != family:
                self.engine.remove_channel(self)
                self._socket_close()
                self._closed = False

        sock = socket.socket(family, socket.SOCK_STREAM)
        self._socket_set(sock)
        self.engine.add_channel(self)

        try:
            self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
        except __HOLE__:
            pass

        if hasattr(socket, "IPPROTO_IPV6") and hasattr(socket, "IPV6_V6ONLY")\
                and family == socket.AF_INET6:
            self._socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
            slave = False

        try:
            self._socket_bind(addr)
            self._socket_listen(backlog)
        except socket.error as err:
            self.close()
            raise

        self.listening = True
        self._safely_call(self.on_listen)

        if slave and not isinstance(addr, str) and addr[0] == '' and HAS_IPV6:
            # Silently fail if we can't make a slave.
            try:
                self._slave = _SlaveServer(self.engine, self, addr, backlog)
            except Exception:
                self._slave = None

    ##### Internal Event Handler Methods ######################################
dataset/ETHPy150Open ecdavis/pants/pants/server.py/Server._do_listen