[Pkg-mpd-commits] [python-mpd] 48/262: preliminary unix socket support

Simon McVittie smcv at debian.org
Sun May 22 18:16:23 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 8ec145e72766913295c842c0622952c0e50a73a7
Author: J. Alexander Treuman <jat at spatialrift.net>
Date:   Sun Jun 7 15:39:38 2009 -0400

    preliminary unix socket support
    
    If the host passed to connect() starts with a "/", then a connection
    attempt is made to the unix socket at the specified path.  The port
    argument is currently still required, but will be ignored.  Attempting to
    connect to a unix socket on Windows will raise an AttributeError (because
    socket.AF_UNIX isn't defined), however this will later be changed.
---
 mpd.py | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/mpd.py b/mpd.py
index fdba8ba..e2ef2e8 100644
--- a/mpd.py
+++ b/mpd.py
@@ -298,29 +298,41 @@ class MPDClient(object):
         self._rfile = _NotConnected()
         self._wfile = _NotConnected()
 
-    def connect(self, host, port):
-        if self._sock:
-            raise ConnectionError("Already connected")
-        msg = "getaddrinfo returns an empty list"
+    def _unix_connect(self, path):
+        sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+        sock.connect(path)
+        return sock
+
+    def _tcp_connect(self, host, port):
         try:
             flags = socket.AI_ADDRCONFIG
         except AttributeError:
             flags = 0
+        msg = "getaddrinfo returns an empty list"
         for res in socket.getaddrinfo(host, port, socket.AF_UNSPEC,
                                       socket.SOCK_STREAM, socket.IPPROTO_TCP,
                                       flags):
             af, socktype, proto, canonname, sa = res
             try:
-                self._sock = socket.socket(af, socktype, proto)
-                self._sock.connect(sa)
+                sock = socket.socket(af, socktype, proto)
+                sock.connect(sa)
             except socket.error, msg:
-                if self._sock:
-                    self._sock.close()
-                self._sock = None
+                if sock:
+                    sock.close()
+                sock = None
                 continue
             break
-        if not self._sock:
+        if not sock:
             raise socket.error(msg)
+        return sock
+
+    def connect(self, host, port):
+        if self._sock:
+            raise ConnectionError("Already connected")
+        if host.startswith("/"):
+            self._sock = self._unix_connect(host)
+        else:
+            self._sock = self._tcp_connect(host, port)
         self._rfile = self._sock.makefile("rb")
         self._wfile = self._sock.makefile("wb")
         try:

-- 
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