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()
poller.register(fd, mask)
else:
if selectables.has_key(fd): del selectables[fd]
+
+ getApplication().interruptPoll()
def _dictRemove(self, selectable, mdict):
try:
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
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."""
int ret = 0;
-
if (poll_timeout)
{
std::multimap<int,eSocketNotifier*>::iterator it;
{
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);
}
int user_timeout = (timeout == Py_None) ? 0 : PyInt_AsLong(timeout);
-
+
iterate(user_timeout, &res, dict);
if (!res) /* return empty list on timeout */
return res;
}
+void eMainloop::interruptPoll()
+{
+ m_interrupt_requested = 1;
+}
+
void eMainloop::quit(int ret)
{
retval = ret;
pthread_mutex_t recalcLock;
int m_now_is_invalid;
+ int m_interrupt_requested;
#endif
public:
static void addTimeOffset(int offset);
#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);
/* our new shared polling interface. */
PyObject *poll(PyObject *dict, PyObject *timeout);
+ void interruptPoll();
};
/**