Exemple #1
0
    def run(self):
        """thread context"""

        # setup the socket
        sock = socket(AF_INET, SOCK_STREAM)
        sock.connect(self.addr_ini)
        self._online = True
        self._is_shutdown.clear()
        self.q_send.put(SimPkg(tid=SimPkg.T_CON))

        # doomsday loop
        while self._online:
            # select
            r, w, e = select([sock], [], [sock], self.poll)
            # error
            if len(e) > 0:
                break
            # receive
            if len(r) > 0:
                pkg = recv_pkg(sock)
                if pkg is None:
                    break
                if pkg.tid == SimPkg.T_STS:
                    self.status = pkg.cont[0].cont.copy()
                self.q_recv.put(pkg)
                if self.delegate is not None:
                    self.delegate.notify()
            # send
            while not self.q_send.empty():
                item = self.q_send.get()
                send_pkg(sock, item)
                self.q_send.task_done()

        self._is_shutdown.set()
Exemple #2
0
    def run(self):
        """thread context"""

        # setup the socket
        sock = socket(AF_INET, SOCK_STREAM)
        sock.connect(self.addr_ini)
        self._online = True
        self._is_shutdown.clear()
        self.q_send.put(SimPkg(tid=SimPkg.T_CON))

        # doomsday loop
        while self._online:
            # select
            r, w, e = select([sock], [], [sock], self.poll)
            # error
            if len(e) > 0:
                break
            # receive
            if len(r) > 0:
                pkg = recv_pkg(sock)
                if pkg is None:
                    break
                if pkg.tid == SimPkg.T_STS:
                    self.status = pkg.cont[0].cont.copy()
                self.q_recv.put(pkg)
                if self.delegate is not None:
                    self.delegate.notify()
            # send
            while not self.q_send.empty():
                item = self.q_send.get()
                send_pkg(sock, item)
                self.q_send.task_done()

        self._is_shutdown.set()
Exemple #3
0
    def handle(self):
        """the run method"""

        while True:
            # select
            r, w, e = select([self.request], [], [self.request], self.poll)
            # error
            if len(e) > 0:
                break
            # receive
            if len(r) > 0:
                pkg = recv_pkg(self.request)
                if pkg is None:
                    break
                if pkg.tid in [SimPkg.T_CON, SimPkg.T_END]:
                    pkg.cont = self.client_address
                self.q_recv.put(pkg)
                if pkg.tid == SimPkg.T_END:
                    break
            # send
            with self.sq_lock:
                while not self.q_send.empty():
                    item = self.q_send.get()
                    send_pkg(self.request, item)
                    self.q_send.task_done()
Exemple #4
0
    def handle(self):
        """the run method"""

        while True:
            # select
            r, w, e = select([self.request], [], [self.request], self.poll)
            # error
            if len(e) > 0:
                break
            # receive
            if len(r) > 0:
                pkg = recv_pkg(self.request)
                if pkg is None:
                    break
                if pkg.tid in [SimPkg.T_CON, SimPkg.T_END]:
                    pkg.cont = self.client_address
                self.q_recv.put(pkg)
                if pkg.tid == SimPkg.T_END:
                    break
            # send
            with self.sq_lock:
                while not self.q_send.empty():
                    item = self.q_send.get()
                    send_pkg(self.request, item)
                    self.q_send.task_done()