736
736
"""Connect this medium if not already connected."""
737
737
if self._connected:
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
744
742
port = int(self._port)
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:
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:
763
if self._socket is None:
748
764
# socket errors either have a (string) or (errno, string) as their
750
766
if type(err.args) is str: