예제 #1
0
    def __receiver_loop(self):
        """
        Main loop listening for incoming data.
        """
        log.info("Starting receiver loop")
        try:
            while self.running:
                try:
                    while self.running:
                        frames = self.__read()

                        for frame in frames:
                            f = utils.parse_frame(frame)
                            if self.__auto_decode:
                                f.body = decode(f.body)
                            self.process_frame(f, frame)
                except exception.ConnectionClosedException:
                    if self.running:
                        self.notify('disconnected')
                        #
                        # Clear out any half-received messages after losing connection
                        #
                        self.__recvbuf = b''
                        self.running = False
                    break
                finally:
                    self.cleanup()
        finally:
            with self.__receiver_thread_exit_condition:
                self.__receiver_thread_exited = True
                self.__receiver_thread_exit_condition.notifyAll()
            log.info("Receiver loop ended")
예제 #2
0
    def __receiver_loop(self):
        """
        Main loop listening for incoming data.
        """
        log.info("Starting receiver loop")
        try:
            while self.running:
                try:
                    while self.running:
                        frames = self.__read()

                        for frame in frames:
                            f = utils.parse_frame(frame)
                            if self.__auto_decode:
                                f.body = decode(f.body)
                            self.process_frame(f, frame)
                except exception.ConnectionClosedException:
                    if self.running:
                        self.notify('disconnected')
                        #
                        # Clear out any half-received messages after losing connection
                        #
                        self.__recvbuf = b''
                        self.running = False
                    break
                finally:
                    self.cleanup()
        finally:
            self.__receiver_thread_exit_condition.acquire()
            self.__receiver_thread_exited = True
            self.__receiver_thread_exit_condition.notifyAll()
            self.__receiver_thread_exit_condition.release()
            log.info("Receiver loop ended")
예제 #3
0
 def run(self):
     try:
         data = []
         while self.running:
             c = self.conn.recv(1)
             if c == '' or len(c) == 0:
                 break
             data.append(c)
             if ord(c) == 0:
                 frame = backward.join(data)
                 print(frame)
                 (frame_type, headers, body) = utils.parse_frame(frame)
                 method = 'handle_%s' % frame_type
                 print('Method = %s' % method)
                 if hasattr(self, method):
                     getattr(self, method)(headers, body)
                 else:
                     self.send_error('invalid command %s' % frame_type)
                 data = []
     except Exception:
         _, e, tb = sys.exc_info()
         print(e)
         import traceback
         traceback.print_tb(tb)
         self.server.remove_connection(self)
     self.shutdown()
예제 #4
0
 def run(self):
     try:
         data = []
         while self.running:
             c = self.conn.recv(1)
             if c == '' or len(c) == 0:
                 break
             data.append(c)
             if ord(c) == 0:
                 frame = backward.join(data)
                 print(frame)
                 f = utils.parse_frame(frame)
                 frame_type = f.cmd.lower()
                 method = 'handle_%s' % frame_type
                 print('Method = %s' % method)
                 if hasattr(self, method):
                     getattr(self, method)(f.headers, f.body)
                 else:
                     self.send_error('invalid command %s' % frame_type)
                 data = []
     except Exception:
         _, e, tb = sys.exc_info()
         print(e)
         import traceback
         traceback.print_tb(tb)
         self.server.remove_connection(self)
     self.shutdown()
예제 #5
0
파일: transport.py 프로젝트: cg2v/stomp.py
    def __receiver_loop(self):
        """
        Main loop listening for incoming data.
        """
        log.info("Starting receiver loop")
        try:
            while self.running:
                if self.socket is None:
                    break

                try:
                    while self.running:
                        frames = self.__read()

                        for frame in frames:
                            f = utils.parse_frame(frame)
                            self.process_frame(f, frame)
                except exception.ConnectionClosedException:
                    if self.running:
                        self.notify('disconnected')
                        #
                        # Clear out any half-received messages after losing connection
                        #
                        self.__recvbuf = ''
                        self.running = False
                    break
                finally:
                    try:
                        self.socket.close()
                    except:
                        pass # ignore errors when attempting to close socket
                    self.socket = None
                    self.current_host_and_port = None
        finally:
            self.__receiver_thread_exit_condition.acquire()
            self.__receiver_thread_exited = True
            self.__receiver_thread_exit_condition.notifyAll()
            self.__receiver_thread_exit_condition.release()
            log.info("Receiver loop ended")