[Pkg-mpd-commits] [python-mpd] 32/262: mpd.py: loop over addresses returned by getaddrinfo to connect to

Simon McVittie smcv at debian.org
Sun May 22 18:16:21 UTC 2016


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to branch upstream
in repository python-mpd.

commit 3bbc456dc51c95e8ad5bb4e270d781ed370bfe27
Author: J. Alexander Treuman <jat at spatialrift.net>
Date:   Sun Mar 23 16:47:06 2008 -0400

    mpd.py: loop over addresses returned by getaddrinfo to connect to
    
    This allows us to support IPv6 and multi-homed hostnames.  getaddrinfo is
    called with the same flags as libmpdclient uses, making address resolution
    consistent between the two.
---
 mpd.py | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/mpd.py b/mpd.py
index ce1784b..ae1f2b3 100644
--- a/mpd.py
+++ b/mpd.py
@@ -289,8 +289,22 @@ class MPDClient(object):
     def connect(self, host, port):
         if self._sock:
             raise ConnectionError, "Already connected"
-        self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-        self._sock.connect((host, port))
+        msg = "getaddrinfo returns an empty list"
+        for res in socket.getaddrinfo(host, port, socket.AF_UNSPEC,
+                                      socket.SOCK_STREAM, socket.IPPROTO_TCP,
+                                      socket.AI_ADDRCONFIG):
+            af, socktype, proto, canonname, sa = res
+            try:
+                self._sock = socket.socket(af, socktype, proto)
+                self._sock.connect(sa)
+            except socket.error, msg:
+                if self._sock:
+                    self._sock.close()
+                self._sock = None
+                continue
+            break
+        if not self._sock:
+            raise socket.error, msg
         self._rfile = self._sock.makefile("rb")
         self._wfile = self._sock.makefile("wb")
         self._hello()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mpd/python-mpd.git



More information about the Pkg-mpd-commits mailing list