From ec1d354c80637d6ab5c7cf5d188f7fb75534f8f5 Mon Sep 17 00:00:00 2001 From: Dimitur Kirov Date: Fri, 3 Feb 2006 22:54:05 +0000 Subject: [PATCH] use old select.select for polling on win-gtk2.8 untill there is a stable 2.8 version --- src/common/xmpp/idlequeue.py | 61 ++++++++++++++++++++++++++++++++ src/common/xmpp/transports_nb.py | 4 +-- src/gajim.py | 13 ++++--- 3 files changed, 72 insertions(+), 6 deletions(-) diff --git a/src/common/xmpp/idlequeue.py b/src/common/xmpp/idlequeue.py index 6733fa862..40043425a 100644 --- a/src/common/xmpp/idlequeue.py +++ b/src/common/xmpp/idlequeue.py @@ -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 diff --git a/src/common/xmpp/transports_nb.py b/src/common/xmpp/transports_nb.py index fa32a062c..29254e6e1 100644 --- a/src/common/xmpp/transports_nb.py +++ b/src/common/xmpp/transports_nb.py @@ -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 diff --git a/src/gajim.py b/src/gajim.py index 530fdd404..2603aef7d 100755 --- a/src/gajim.py +++ b/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()