From 8fd907e8059d37688cc5ede914faf660880ba93f Mon Sep 17 00:00:00 2001 From: yutent Date: Thu, 24 Aug 2023 14:49:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dmpd=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=E6=A3=80=E6=B5=8B,mpd=E6=8E=89=E7=BA=BF=E6=97=B6=E6=AD=BB?= =?UTF-8?q?=E5=BE=AA=E7=8E=AF=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mpd.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/mpd.py b/mpd.py index ad0e0ce..3b3c45e 100644 --- a/mpd.py +++ b/mpd.py @@ -447,7 +447,8 @@ class MPDClient(MPDClientBase, GObject.Object): 'offline': (GObject.SignalFlags.RUN_FIRST, None, ()), 'playing': (GObject.SignalFlags.RUN_FIRST, None, (object, object)), 'song_changed': (GObject.SignalFlags.RUN_FIRST, None, (object, object)), - 'state_changed': (GObject.SignalFlags.RUN_FIRST, None, (object,)) + 'state_changed': (GObject.SignalFlags.RUN_FIRST, None, (object,)), + 'error': (GObject.SignalFlags.RUN_FIRST, None, (object,)) } @@ -543,7 +544,7 @@ class MPDClient(MPDClientBase, GObject.Object): def _read_line(self): line = self._rbfile.readline().decode("utf-8") if not line.endswith("\n"): - self.end() + self.destroy() raise ConnectionError("Connection lost while reading line") line = line.rstrip("\n") if line.startswith(ERROR_PREFIX): @@ -597,7 +598,7 @@ class MPDClient(MPDClientBase, GObject.Object): value = self._read_chunk(chunk_size) if len(value) != chunk_size: - self.end() + self.destroy() raise ConnectionError( "Connection lost while reading binary data: " "expected %d bytes, got %d" % (chunk_size, len(value)) @@ -605,7 +606,7 @@ class MPDClient(MPDClientBase, GObject.Object): if self._rbfile.read(1) != b"\n": # newline after binary content - self.end() + self.destroy() raise ConnectionError("Connection lost while reading line") obj[key] = value @@ -685,7 +686,7 @@ class MPDClient(MPDClientBase, GObject.Object): def _check_is_mpd_server(self, line): if not line.endswith("\n"): - self.end() + self.destroy() return line = line.rstrip("\n") @@ -725,7 +726,7 @@ class MPDClient(MPDClientBase, GObject.Object): except Exception as e: if e.strerror == 'Connection refused': - self.emit('offline', True) + self.emit('offline') else: self.emit('error', e) @@ -772,10 +773,13 @@ class MPDClient(MPDClientBase, GObject.Object): self._check_is_mpd_server(helloline) if self.connected: break - + except Exception as e: self.connected = False - self.end() + self.destroy() + + + time.sleep(2) def heart_beat(self): @@ -809,7 +813,7 @@ class MPDClient(MPDClientBase, GObject.Object): else: break - self.end() + self.destroy() self.start() @@ -819,11 +823,8 @@ class MPDClient(MPDClientBase, GObject.Object): self.emit('online') self.heart_beat() + def destroy(self): - self.end() - - - def end(self): if self._rbfile is not None: self._rbfile.close() if self._wfile is not None: