def process_msg(self, msg, body_len): version, flags, stream_id, opcode = self._header_unpack( msg[:self._header_length]) if stream_id < 0: callback = None else: callback = self._callbacks.pop(stream_id, None) with self.lock: self.request_ids.append(stream_id) body = None try: # check that the protocol version is supported given_version = version & PROTOCOL_VERSION_MASK if given_version != self.protocol_version: msg = "Server protocol version (%d) does not match the specified driver protocol version (%d). " +\ "Consider setting Cluster.protocol_version to %d." raise ProtocolError( msg % (given_version, self.protocol_version, given_version)) # check that the header direction is correct if version & HEADER_DIRECTION_MASK != HEADER_DIRECTION_TO_CLIENT: raise ProtocolError( "Header direction in response is incorrect; opcode %04x, stream id %r" % (opcode, stream_id)) if body_len > 0: body = msg[self._full_header_length:] elif body_len == 0: body = six.binary_type() else: raise ProtocolError("Got negative body length: %r" % body_len) response = decode_response(given_version, self.user_type_map, stream_id, flags, opcode, body, self.decompressor) except Exception as exc: log.exception( "Error decoding response from Cassandra. " "opcode: %04x; message contents: %r", opcode, msg) if callback is not None: callback(exc) self.defunct(exc) return try: if stream_id >= 0: if isinstance(response, ProtocolException): log.error( "Closing connection %s due to protocol error: %s", self, response.summary_msg()) self.defunct(response) if callback is not None: callback(response) else: self.handle_pushed(response) except Exception: log.exception("Callback handler errored, ignoring:")
def process_msg(self, msg, body_len): version, flags, stream_id, opcode = self._header_unpack(msg[: self._header_length]) if stream_id < 0: callback = None else: callback = self._callbacks.pop(stream_id, None) with self.lock: self.request_ids.append(stream_id) self.msg_received = True body = None try: # check that the protocol version is supported given_version = version & PROTOCOL_VERSION_MASK if given_version != self.protocol_version: msg = ( "Server protocol version (%d) does not match the specified driver protocol version (%d). " + "Consider setting Cluster.protocol_version to %d." ) raise ProtocolError(msg % (given_version, self.protocol_version, given_version)) # check that the header direction is correct if version & HEADER_DIRECTION_MASK != HEADER_DIRECTION_TO_CLIENT: raise ProtocolError( "Header direction in response is incorrect; opcode %04x, stream id %r" % (opcode, stream_id) ) if body_len > 0: body = msg[self._full_header_length :] elif body_len == 0: body = six.binary_type() else: raise ProtocolError("Got negative body length: %r" % body_len) response = decode_response( given_version, self.user_type_map, stream_id, flags, opcode, body, self.decompressor ) except Exception as exc: log.exception("Error decoding response from Cassandra. " "opcode: %04x; message contents: %r", opcode, msg) if callback is not None: callback(exc) self.defunct(exc) return try: if stream_id >= 0: if isinstance(response, ProtocolException): log.error("Closing connection %s due to protocol error: %s", self, response.summary_msg()) self.defunct(response) if callback is not None: callback(response) else: self.handle_pushed(response) except Exception: log.exception("Callback handler errored, ignoring:")
def process_msg(self, msg, body_len): version, flags, stream_id, opcode = header_unpack(msg[:4]) if stream_id < 0: callback = None else: callback = self._callbacks.pop(stream_id, None) self._id_queue.put_nowait(stream_id) body = None try: # check that the protocol version is supported given_version = version & PROTOCOL_VERSION_MASK if given_version != self.protocol_version: msg = "Server protocol version (%d) does not match the specified driver protocol version (%d). " +\ "Consider setting Cluster.protocol_version to %d." raise ProtocolError(msg % (given_version, self.protocol_version, given_version)) # check that the header direction is correct if version & HEADER_DIRECTION_MASK != HEADER_DIRECTION_TO_CLIENT: raise ProtocolError( "Header direction in response is incorrect; opcode %04x, stream id %r" % (opcode, stream_id)) if body_len > 0: body = msg[8:] elif body_len == 0: body = six.binary_type() else: raise ProtocolError("Got negative body length: %r" % body_len) response = decode_response(stream_id, flags, opcode, body, self.decompressor) except Exception as exc: log.exception("Error decoding response from Cassandra. " "opcode: %04x; message contents: %r", opcode, msg) if callback is not None: callback(exc) self.defunct(exc) return try: if stream_id < 0: self.handle_pushed(response) elif callback is not None: callback(response) except Exception: log.exception("Callback handler errored, ignoring:")
def process_msg(self, header, body): stream_id = header.stream if stream_id < 0: callback = None else: callback = self._callbacks.pop(stream_id, None) with self.lock: self.request_ids.append(stream_id) self.msg_received = True try: response = decode_response(header.version, self.user_type_map, stream_id, header.flags, header.opcode, body, self.decompressor) except Exception as exc: log.exception("Error decoding response from Cassandra. " "opcode: %04x; message contents: %r", header.opcode, body) if callback is not None: callback(exc) self.defunct(exc) return try: if stream_id >= 0: if isinstance(response, ProtocolException): if 'unsupported protocol version' in response.message: self.is_unsupported_proto_version = True log.error("Closing connection %s due to protocol error: %s", self, response.summary_msg()) self.defunct(response) if callback is not None: callback(response) else: self.handle_pushed(response) except Exception: log.exception("Callback handler errored, ignoring:")