示例#1
0
    def _connectedProtocol(self, interface=""):
        """
        Return a new L{DNSDatagramProtocol} bound to a randomly selected port
        number.
        """
        failures = 0
        proto = dns.DNSDatagramProtocol(self, reactor=self._reactor)

        while True:
            try:
                self._reactor.listenUDP(dns.randomSource(),
                                        proto,
                                        interface=interface)
            except error.CannotListenError as e:
                failures += 1

                if (hasattr(e.socketError, "errno")
                        and e.socketError.errno == errno.EMFILE):
                    # We've run out of file descriptors. Stop trying.
                    raise

                if failures >= 1000:
                    # We've tried a thousand times and haven't found a port.
                    # This is almost impossible, and likely means something
                    # else weird is going on. Raise, as to not infinite loop.
                    raise
            else:
                return proto
示例#2
0
 def _connectedProtocol(self):
     """
     Return a new L{ExtendDNSDatagramProtocol} bound to a randomly selected port
     number.
     """
     proto = ExtendDNSDatagramProtocol(self, reactor=self._reactor)
     while True:
         try:
             self._reactor.listenUDP(dns.randomSource(), proto)
         except error.CannotListenError:
             pass
         else:
             return proto
示例#3
0
 def _connectedProtocol(self):
     """
     Return a new L{ExtendDNSDatagramProtocol} bound to a randomly selected port
     number.
     """
     proto = ExtendDNSDatagramProtocol(self, reactor=self._reactor)
     while True:
         try:
             self._reactor.listenUDP(dns.randomSource(), proto)
         except error.CannotListenError:
             pass
         else:
             return proto
示例#4
0
 def _connectedProtocol(self):
     """
     Return a new L{DNSDatagramProtocol} bound to a randomly selected port
     number.
     """
     if 'protocol' in self.__dict__:
         # Some code previously asked for or set the deprecated `protocol`
         # attribute, so it probably expects that object to be used for
         # queries.  Give it back and skip the super awesome source port
         # randomization logic.  This is actually a really good reason to
         # remove this deprecated backward compatibility as soon as
         # possible. -exarkun
         return self.protocol
     proto = dns.DNSDatagramProtocol(self)
     while True:
         try:
             self._reactor.listenUDP(dns.randomSource(), proto)
         except error.CannotListenError:
             pass
         else:
             return proto
 def _connectedProtocol(self):
     """
     Return a new L{DNSDatagramProtocol} bound to a randomly selected port
     number.
     """
     if 'protocol' in self.__dict__:
         # Some code previously asked for or set the deprecated `protocol`
         # attribute, so it probably expects that object to be used for
         # queries.  Give it back and skip the super awesome source port
         # randomization logic.  This is actually a really good reason to
         # remove this deprecated backward compatibility as soon as
         # possible. -exarkun
         return self.protocol
     proto = dns.DNSDatagramProtocol(self)
     while True:
         try:
             self._reactor.listenUDP(dns.randomSource(), proto)
         except error.CannotListenError:
             pass
         else:
             return proto