~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/medium.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-09-19 11:01:31 UTC
  • mfrom: (3711.2.3 bzr.dev)
  • Revision ID: pqm@pqm.ubuntu.com-20080919110131-v81t8izemtywe4vu
(Jelmer) Support IPv6 in the smart server.

Show diffs side-by-side

added added

removed removed

Lines of Context:
704
704
 
705
705
 
706
706
# Port 4155 is the default port for bzr://, registered with IANA.
707
 
BZR_DEFAULT_INTERFACE = '0.0.0.0'
 
707
BZR_DEFAULT_INTERFACE = None
708
708
BZR_DEFAULT_PORT = 4155
709
709
 
710
710
 
736
736
        """Connect this medium if not already connected."""
737
737
        if self._connected:
738
738
            return
739
 
        self._socket = socket.socket()
740
 
        self._socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
741
739
        if self._port is None:
742
740
            port = BZR_DEFAULT_PORT
743
741
        else:
744
742
            port = int(self._port)
745
743
        try:
746
 
            self._socket.connect((self._host, port))
747
 
        except socket.error, err:
 
744
            sockaddrs = socket.getaddrinfo(self._host, port, socket.AF_UNSPEC, 
 
745
                socket.SOCK_STREAM, 0, 0)
 
746
        except socket.gaierror, (err_num, err_msg):
 
747
            raise errors.ConnectionError("failed to lookup %s:%d: %s" %
 
748
                    (self._host, port, err_msg))
 
749
        # Initialize err in case there are no addresses returned:
 
750
        err = socket.error("no address found for %s" % self._host)
 
751
        for (family, socktype, proto, canonname, sockaddr) in sockaddrs:
 
752
            try:
 
753
                self._socket = socket.socket(family, socktype, proto)
 
754
                self._socket.setsockopt(socket.IPPROTO_TCP, 
 
755
                                        socket.TCP_NODELAY, 1)
 
756
                self._socket.connect(sockaddr)
 
757
            except socket.error, err:
 
758
                if self._socket is not None:
 
759
                    self._socket.close()
 
760
                self._socket = None
 
761
                continue
 
762
            break
 
763
        if self._socket is None:
748
764
            # socket errors either have a (string) or (errno, string) as their
749
765
            # args.
750
766
            if type(err.args) is str: