def __run_tx(self):
        buf = ''
        first_time = True
        while True:
            if self.__owner._shutdown:
                return
            if self.__reconnect:
                buf = '' # throw away unsent data
            if len(buf) == 0:
                data, addr = None, None
                if not self.__reconnect:
                    self.__owner._wi_available.acquire()
                    while len(self.__owner._wi) == 0 and not self.__reconnect:
                        self.__owner._wi_available.wait()
                        if self.__owner._shutdown:
                            os.close(self.fileno())
                            self.__owner._wi_available.release()
                            return
                    if len(self.__owner._wi) > 0:
                        data, addr, laddress = self.__owner._wi.pop(0)
                    self.__owner._wi_available.release()
                if self.__reconnect:
                    #print self, self.__reconnect_count
                    if not first_time:
                        time.sleep(0.1)
                        try:
                            os.close(self.fileno())
                        except:
                            pass
                    try:
                        self.connect(jid=iksemel.JID('127.0.0.1'), tls=False, port=22223)
                        first_time = False
                        os.write(self.fileno(), '<b2bua_slot id="%s"/>' % self.__id)
                        pollobj = poll()
                        pollobj.register(self.fileno(), POLLOUT)
                    except iksemel.StreamError:
                        continue
                    except:
                        traceback.print_exc(file = sys.stdout)
                        sys.stdout.flush()
                        continue
                    self.__reconnect = False
                    self.__reconnect_count += 1
                if data == None:
                    continue
                dst_addr, dst_port = addr
                buf = '<outgoing_packet dst_addr="%s" dst_port="%s" ' \
                                'src_addr="%s" src_port="%s" ' \
                                'msg="%s"/>' % (dst_addr, dst_port, 
                                                laddress[0], laddress[1], 
                                                base64.b64encode(data))
            if self.__owner._shutdown:
                os.close(self.fileno())
                return
            pollret = dict(pollobj.poll())
            if pollret.get(self.fileno(), 0) & POLLOUT == 0:
                continue
            try:
                sent = os.write(self.fileno(), buf)
                buf = buf[sent:]
            except IOError:
                # wait for reconnect
                self.__reconnect = True
            except __HOLE__:
                # wait for reconnect
                self.__reconnect = True
dataset/ETHPy150Open sippy/b2bua/sippy/XMPP_server.py/Worker.__run_tx