aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Domke <tmbinc@elitedvb.net>2006-02-25 02:48:51 +0000
committerFelix Domke <tmbinc@elitedvb.net>2006-02-25 02:48:51 +0000
commit842dabf727814691bfd949ac4d910ce04c32b887 (patch)
tree03a1dfb9fb4c20afa4d97b616a5652e2d88a079c
parent672b1ef9c238b94bd46f17020557780745f0db18 (diff)
downloadenigma2-842dabf727814691bfd949ac4d910ce04c32b887.tar.gz
enigma2-842dabf727814691bfd949ac4d910ce04c32b887.zip
some fixes for twisted
-rw-r--r--e2reactor.py9
-rw-r--r--lib/base/ebase.cpp33
-rw-r--r--lib/base/ebase.h4
3 files changed, 40 insertions, 6 deletions
diff --git a/e2reactor.py b/e2reactor.py
index 1ecd40e8..7caeb7f1 100644
--- a/e2reactor.py
+++ b/e2reactor.py
@@ -35,7 +35,8 @@ class E2SharedPoll:
del self.dict[fd]
def poll(self, timeout = None):
- return getApplication().poll(timeout, self.dict)
+ r = getApplication().poll(timeout, self.dict)
+ return r
poller = E2SharedPoll()
@@ -56,6 +57,8 @@ class PollReactor(posixbase.PosixReactorBase):
poller.register(fd, mask)
else:
if selectables.has_key(fd): del selectables[fd]
+
+ getApplication().interruptPoll()
def _dictRemove(self, selectable, mdict):
try:
@@ -131,6 +134,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
@@ -183,6 +187,9 @@ class PollReactor(posixbase.PosixReactorBase):
if why:
self._disconnectSelectable(selectable, why, inRead)
+ def callLater(self, *args, **kwargs):
+ getApplication().interruptPoll()
+ return posixbase.PosixReactorBase.callLater(self, *args, **kwargs)
def install():
"""Install the poll() reactor."""
diff --git a/lib/base/ebase.cpp b/lib/base/ebase.cpp
index 7a57d533..addd1b88 100644
--- a/lib/base/ebase.cpp
+++ b/lib/base/ebase.cpp
@@ -165,7 +165,6 @@ int eMainloop::processOneEvent(unsigned int user_timeout, PyObject **res, PyObje
int ret = 0;
-
if (poll_timeout)
{
std::multimap<int,eSocketNotifier*>::iterator it;
@@ -312,10 +311,31 @@ int eMainloop::iterate(unsigned int user_timeout, PyObject **res, PyObject *dict
{
int ret = 0;
+ timeval user_timer;
+ gettimeofday(&user_timer, 0);
+ user_timer += user_timeout;
+
+ /* TODO: this code just became ugly. fix that. */
do
- {
+ {
+ if (m_interrupt_requested)
+ {
+ m_interrupt_requested = 0;
+ return 0;
+ }
if (app_quit_now) return -1;
- ret = processOneEvent(user_timeout, res, dict);
+ timeval now, timeout;
+ gettimeofday(&now, 0);
+ timeout = user_timer - now;
+
+ if (user_timeout && (user_timer <= now))
+ return 0;
+
+ int to = 0;
+ if (user_timeout)
+ to = timeout.tv_sec * 1000 + timeout.tv_usec / 1000;
+
+ ret = processOneEvent(to, res, dict);
if (res && *res)
return ret;
} while (ret == 0);
@@ -341,7 +361,7 @@ PyObject *eMainloop::poll(PyObject *timeout, PyObject *dict)
}
int user_timeout = (timeout == Py_None) ? 0 : PyInt_AsLong(timeout);
-
+
iterate(user_timeout, &res, dict);
if (!res) /* return empty list on timeout */
@@ -350,6 +370,11 @@ PyObject *eMainloop::poll(PyObject *timeout, PyObject *dict)
return res;
}
+void eMainloop::interruptPoll()
+{
+ m_interrupt_requested = 1;
+}
+
void eMainloop::quit(int ret)
{
retval = ret;
diff --git a/lib/base/ebase.h b/lib/base/ebase.h
index a224e2cc..b819fc35 100644
--- a/lib/base/ebase.h
+++ b/lib/base/ebase.h
@@ -187,6 +187,7 @@ class eMainloop
pthread_mutex_t recalcLock;
int m_now_is_invalid;
+ int m_interrupt_requested;
#endif
public:
static void addTimeOffset(int offset);
@@ -200,7 +201,7 @@ public:
#endif
eMainloop()
- :app_quit_now(0),loop_level(0),retval(0)
+ :app_quit_now(0),loop_level(0),retval(0), m_interrupt_requested(0)
{
m_now_is_invalid = 0;
existing_loops.push_back(this);
@@ -230,6 +231,7 @@ public:
/* our new shared polling interface. */
PyObject *poll(PyObject *dict, PyObject *timeout);
+ void interruptPoll();
};
/**