예제 #1
0
파일: _common.py 프로젝트: uliana-dzyoba/DB
    def _yield_messages(self, sock):
        try:
            buffer = UnpackableBuffer()
            unpacker = Unpacker(buffer)
            chunk_size = 0
            while True:

                while chunk_size == 0:
                    # Determine the chunk size and skip noop
                    buffer.receive(sock, 2)
                    chunk_size = buffer.pop_u16()
                    if chunk_size == 0:
                        log.debug("[#%04X]  S: <NOOP>", sock.getsockname()[1])

                buffer.receive(sock, chunk_size + 2)
                chunk_size = buffer.pop_u16()

                if chunk_size == 0:
                    # chunk_size was the end marker for the message
                    size, tag = unpacker.unpack_structure_header()
                    fields = [unpacker.unpack() for _ in range(size)]
                    yield tag, fields
                    # Reset for new message
                    unpacker.reset()

        except OSError as error:
            self.on_error(error)
예제 #2
0
 def _yield_messages(self, sock):
     try:
         buffer = UnpackableBuffer()
         chunk_loader = self._load_chunks(sock, buffer)
         unpacker = Unpacker(buffer)
         details = []
         while True:
             unpacker.reset()
             details[:] = ()
             chunk_size = -1
             while chunk_size != 0:
                 chunk_size = next(chunk_loader)
             summary_signature = None
             summary_metadata = None
             size, signature = unpacker.unpack_structure_header()
             if size > 1:
                 raise ProtocolError("Expected one field")
             if signature == b"\x71":
                 data = unpacker.unpack()
                 details.append(data)
             else:
                 summary_signature = signature
                 summary_metadata = unpacker.unpack_map()
             yield details, summary_signature, summary_metadata
     except OSError as error:
         self.on_error(error)
예제 #3
0
 def _yield_messages(self, sock):
     try:
         buffer = UnpackableBuffer()
         chunk_loader = self._load_chunks(sock, buffer)
         unpacker = Unpacker(buffer)
         while True:
             unpacker.reset()
             chunk_size = -1
             while chunk_size != 0:
                 chunk_size = next(chunk_loader)
             size, tag = unpacker.unpack_structure_header()
             fields = [unpacker.unpack() for _ in range(size)]
             yield tag, fields
     except OSError as error:
         self.on_error(error)