]> kaliko git repositories - python-musicpd.git/commitdiff
mpd.py: adding fileno() to export socket FD
authorJ. Alexander Treuman <jat@spatialrift.net>
Thu, 15 Jul 2010 17:52:40 +0000 (13:52 -0400)
committerJ. Alexander Treuman <jat@spatialrift.net>
Thu, 15 Jul 2010 17:52:40 +0000 (13:52 -0400)
This allows access to the socket FD for polling if it can be written
to/read from.  This is useful with, for example, the idle command.  Simply
call send_idle(), poll the socket FD with select/poll/etc to check if it's
ready for reading, and if it is, call fetch_idle() to see what changed.
Note that select et al. call fileno() on any objects you pass to them, so
you can simply pass the MPDClient instance itself to these functions
instead of the FD returned by fileno().

mpd.py

diff --git a/mpd.py b/mpd.py
index cb16701872c5b700bc44620eb415780e7715e64c..7ff17b7b314cf9d519be9a0b0851853ead5ce2ce 100644 (file)
--- a/mpd.py
+++ b/mpd.py
@@ -389,6 +389,11 @@ class MPDClient(object):
         self._sock.close()
         self._reset()
 
         self._sock.close()
         self._reset()
 
+    def fileno(self):
+        if not self._sock:
+            raise ConnectionError("Not connected")
+        return self._sock.fileno()
+
     def command_list_ok_begin(self):
         if self._command_list is not None:
             raise CommandListError("Already in command list")
     def command_list_ok_begin(self):
         if self._command_list is not None:
             raise CommandListError("Already in command list")