use old select.select for polling on win-gtk2.8
untill there is a stable 2.8 version
This commit is contained in:
parent
b4b810f465
commit
ec1d354c80
|
@ -138,6 +138,8 @@ class IdleQueue:
|
|||
|
||||
def process(self):
|
||||
if not self.queue:
|
||||
# check for timeouts/alert also when there are no active fds
|
||||
self.check_time_events()
|
||||
return True
|
||||
try:
|
||||
waiting_descriptors = self.selector.poll(0)
|
||||
|
@ -149,3 +151,62 @@ class IdleQueue:
|
|||
self.process_events(fd, flags)
|
||||
self.check_time_events()
|
||||
return True
|
||||
|
||||
class SelectIdleQueue(IdleQueue):
|
||||
'''
|
||||
Extends IdleQueue to use select.select() for polling
|
||||
This class exisists for the sake of gtk2.8 on windows, which
|
||||
doesn't seem to support io_add_watch properly (yet)
|
||||
'''
|
||||
# TODO: remove this class and its reference gajim.py, when win-gtk2.8 is stable
|
||||
def init_idle(self):
|
||||
''' this method is called at the end of class constructor.
|
||||
Creates a dict, which maps file/pipe/sock descriptor to glib event id'''
|
||||
self.read_fds = {}
|
||||
self.write_fds = {}
|
||||
self.error_fds = {}
|
||||
|
||||
def add_idle(self, fd, flags):
|
||||
''' this method is called when we plug a new idle object.
|
||||
Remove descriptor to read/write/error lists, according flags
|
||||
'''
|
||||
if flags & 3:
|
||||
self.read_fds[fd] = fd
|
||||
if flags & 4:
|
||||
self.write_fds[fd] = fd
|
||||
self.error_fds[fd] = fd
|
||||
|
||||
def remove_idle(self, fd):
|
||||
''' this method is called when we unplug a new idle object.
|
||||
Remove descriptor from read/write/error lists
|
||||
'''
|
||||
if self.read_fds.has_key(fd):
|
||||
del(self.read_fds[fd])
|
||||
if self.write_fds.has_key(fd):
|
||||
del(self.write_fds[fd])
|
||||
if self.error_fds.has_key(fd):
|
||||
del(self.error_fds[fd])
|
||||
|
||||
def process(self):
|
||||
if not self.write_fds and not self.read_fds:
|
||||
self.check_time_events()
|
||||
return True
|
||||
try:
|
||||
waiting_descriptors = select.select(self.read_fds.keys(),
|
||||
self.write_fds.keys(), self.error_fds.keys(), 0)
|
||||
except select.error, e:
|
||||
waiting_descriptors = ((),(),())
|
||||
if e[0] != 4: # interrupt
|
||||
raise
|
||||
for fd in waiting_descriptors[0]:
|
||||
self.queue.get(fd).pollin()
|
||||
self.check_time_events()
|
||||
return True
|
||||
for fd in waiting_descriptors[1]:
|
||||
self.queue.get(fd).pollout()
|
||||
self.check_time_events()
|
||||
return True
|
||||
for fd in waiting_descriptors[2]:
|
||||
self.queue.get(fd).pollend()
|
||||
self.check_time_events()
|
||||
return True
|
||||
|
|
|
@ -256,9 +256,9 @@ class NonBlockingTcp(PlugIn, IdleObject):
|
|||
if self.state != 0:
|
||||
return
|
||||
self._sock.setblocking(False)
|
||||
# connect_ex is better than try:connect
|
||||
errnum = 0
|
||||
try:
|
||||
errnum = self._sock.connect_ex(self._server)
|
||||
self._sock.connect(self._server)
|
||||
except socket.error, e:
|
||||
errnum = e[0]
|
||||
# in progress, or would block
|
||||
|
|
13
src/gajim.py
13
src/gajim.py
|
@ -1496,10 +1496,15 @@ class Interface:
|
|||
gajim.socks5queue = socks5.SocksQueue(
|
||||
self.handle_event_file_rcv_completed,
|
||||
self.handle_event_file_progress)
|
||||
# in a nongui implementation, just call:
|
||||
# gajim.idlequeue = IdleQueue() , and
|
||||
# gajim.idlequeue.process() each foo miliseconds
|
||||
gajim.idlequeue = GlibIdleQueue()
|
||||
|
||||
# pygtk2.8 on win, breaks io_add_watch. We use good old select.select()
|
||||
if os.name == 'nt' and gtk.pygtk_version > (2, 8, 0):
|
||||
gajim.idlequeue = idlequeue.SelectIdleQueue()
|
||||
else:
|
||||
# in a nongui implementation, just call:
|
||||
# gajim.idlequeue = IdleQueue() , and
|
||||
# gajim.idlequeue.process() each foo miliseconds
|
||||
gajim.idlequeue = GlibIdleQueue()
|
||||
# resolve and keep current record of resolved hosts
|
||||
gajim.resolver = nslookup.Resolver(gajim.idlequeue)
|
||||
self.register_handlers()
|
||||
|
|
Loading…
Reference in New Issue