]> kaliko git repositories - python-musicpd.git/commitdiff
Handles better lost connections
authorKaliko Jack <kaliko@azylum.org>
Mon, 15 Apr 2013 18:13:57 +0000 (20:13 +0200)
committerKaliko Jack <kaliko@azylum.org>
Mon, 15 Apr 2013 18:15:41 +0000 (20:15 +0200)
mpd.py

diff --git a/mpd.py b/mpd.py
index 4ad4804a23a17c1a384af068d8a287601d913ca7..373bd1672d835d6a0ecad229856d55cc3168d4f7 100644 (file)
--- a/mpd.py
+++ b/mpd.py
@@ -236,6 +236,7 @@ class MPDClient(object):
     def _read_line(self):
         line = self._rfile.readline()
         if not line.endswith("\n"):
+            self.disconnect()
             raise ConnectionError("Connection lost while reading line")
         line = line.rstrip("\n")
         if line.startswith(ERROR_PREFIX):
@@ -414,7 +415,7 @@ class MPDClient(object):
                 if sock is not None:
                     sock.close()
         if err is not None:
-            raise err
+            raise ConnectionError(str(err))
         else:
             raise ConnectionError("getaddrinfo returns an empty list")
 
@@ -434,9 +435,15 @@ class MPDClient(object):
             raise
 
     def disconnect(self):
-        self._rfile.close()
-        self._wfile.close()
-        self._sock.close()
+        if isinstance(self._rfile, socket._fileobject):
+            print('closing r socket')
+            self._rfile.close()
+        if isinstance(self._wfile, socket._fileobject):
+            print('closing w socket')
+            self._wfile.close()
+        if isinstance(self._sock, socket.socket):
+            print('closing socket')
+            self._sock.close()
         self._reset()
 
     def fileno(self):