filepush: convert default buffersize into a #define
[openblackhole/openblackhole-enigma2.git] / e2reactor.py
index 1ecd40e..61447e2 100644 (file)
@@ -11,7 +11,7 @@ Maintainer: U{Felix Domke<mailto:tmbinc@elitedvb.net>}
 import select, errno, sys
 
 # Twisted imports
-from twisted.python import log, threadable, failure
+from twisted.python import log, failure
 from twisted.internet import main, posixbase, error
 #from twisted.internet.pollreactor import PollReactor, poller
 
@@ -27,15 +27,20 @@ POLL_DISCONNECTED = (select.POLLHUP | select.POLLERR | select.POLLNVAL)
 class E2SharedPoll:
        def __init__(self):
                self.dict = { }
+               self.eApp = getApplication()
 
        def register(self, fd, eventmask = select.POLLIN | select.POLLERR | select.POLLOUT):
                self.dict[fd] = eventmask
-       
+
        def unregister(self, fd):
                del self.dict[fd]
-       
+
        def poll(self, timeout = None):
-               return getApplication().poll(timeout, self.dict)
+               try:
+                       r = self.eApp.poll(timeout, self.dict)
+               except KeyboardInterrupt:
+                       return None
+               return r
 
 poller = E2SharedPoll()
 
@@ -57,6 +62,9 @@ class PollReactor(posixbase.PosixReactorBase):
                else:
                        if selectables.has_key(fd): del selectables[fd]
 
+
+               poller.eApp.interruptPoll()
+
        def _dictRemove(self, selectable, mdict):
                try:
                        # the easy way
@@ -117,7 +125,7 @@ class PollReactor(posixbase.PosixReactorBase):
                selectables.clear()
                for fd in fds:
                        poller.unregister(fd)
-                       
+
                if self.waker is not None:
                        self.addReader(self.waker)
                return result
@@ -131,6 +139,7 @@ class PollReactor(posixbase.PosixReactorBase):
                           POLLIN=select.POLLIN,
                           POLLOUT=select.POLLOUT):
                """Poll the poller for new events."""
+
                if timeout is not None:
                        timeout = int(timeout * 1000) # convert seconds to milliseconds
 
@@ -157,7 +166,7 @@ class PollReactor(posixbase.PosixReactorBase):
 
        doIteration = doPoll
 
-       def _doReadOrWrite(self, selectable, fd, event, POLLIN, POLLOUT, log, 
+       def _doReadOrWrite(self, selectable, fd, event, POLLIN, POLLOUT, log,
                faildict={
                        error.ConnectionDone: failure.Failure(error.ConnectionDone()),
                        error.ConnectionLost: failure.Failure(error.ConnectionLost())
@@ -183,10 +192,13 @@ class PollReactor(posixbase.PosixReactorBase):
                if why:
                        self._disconnectSelectable(selectable, why, inRead)
 
+       def callLater(self, *args, **kwargs):
+               poller.eApp.interruptPoll()
+               return posixbase.PosixReactorBase.callLater(self, *args, **kwargs)
 
 def install():
        """Install the poll() reactor."""
-       
+
        p = PollReactor()
        main.installReactor(p)