]> kaliko git repositories - python-musicpdaio.git/blobdiff - mpdaio/connection.py
Add connections propertie
[python-musicpdaio.git] / mpdaio / connection.py
index f4a97de09039f3220ce81ea6971ef99155bf5f5d..072fc3fc1d0edbe22a9681f994446409f6fcb9da 100644 (file)
@@ -61,12 +61,18 @@ class ConnectionPool(base):
                     if not conn.in_use:
                         await conn.close()
                         break
-
-            log.debug('about to connect %s', host)
-            reader, writer = await asyncio.wait_for(
-                    asyncio.open_connection(server, port),
-                    timeout
-                    )
+            if server[0] in ['/', '@']:
+                log.debug('about to connect unix socket %s', server)
+                reader, writer = await asyncio.wait_for(
+                        asyncio.open_unix_connection(path=server),
+                        timeout
+                        )
+            else:
+                log.debug('about to connect tcp socket %s:%s', *host)
+                reader, writer = await asyncio.wait_for(
+                        asyncio.open_connection(server, port),
+                        timeout
+                        )
             #log.debug('Connected to %s:%s', host[0], host[1])
             connection = Connection(self, host, reader, writer)
             await connection._hello()
@@ -138,7 +144,7 @@ class Connection(base):
 
     def __repr__(self):
         host = f"{self._host[0]}:{self._host[1]}"
-        return f"Connection<{host}>#{id(self)}"
+        return f"Connection<{host}>"
 
     @property
     def closed(self):
@@ -172,7 +178,6 @@ class Connection(base):
         self.version = rcv.split('\n')[0][len(HELLO_PREFIX):]
         log.info('protocol version: %s', self.version)
 
-
     def __getattr__(self, name: str) -> Any:
         """All unknown attributes are delegated to the reader and writer"""
         if self._closed or not self.in_use: