def read_protocol_id(self): id = self.reader.read_int() if id != self.protocol.protocol_id: log.warn("Wrong protocol id %s" % id) self.close() return self.reader.flush() self.has_read_protocol_id = True
def read_twp_magic(self): magic_length = len(TWP_MAGIC) magic = self.reader.read_bytes(magic_length) if magic != TWP_MAGIC: log.warn("Wrong TWP magic") self.close() return self.reader.flush() self.has_read_magic = True
def handle_expression_result(self, msg, client): log.warn("Result from async client %s" % msg) client.close() if not isinstance(msg, Reply): log.warn("Expected reply, but got: %s" % msg) self.send_error("Unexpected message from intermediate.") self.close() return rid = msg.request_id # TODO sanity check rid self.operands[rid] = msg.result self.send_result_if_complete()
def log_request(self, msg): try: le = twp.protocols.logging.LogEntry() le.seconds = int(time.time()) le.useconds = 0 le.source = self.name thread_id = msg.get_thread_id() if thread_id: le.thread_id = "%s" % dict(thread_id._fields) le.text = "Request %s: %s" % (msg.id, msg.arguments) # FIXME self.get_log_client().send_twp(le) log.error("Would log to service: %s" % le) except: log.warn("logging service request failed") raise
def handle_read(self): try: initial_pos = self.reader.pos if not self.has_read_magic: self.read_twp_magic() if not self.has_read_protocol_id: self.read_protocol_id() else: message = self.read_message() self.on_message(message) if self.reader.remaining_byte_length: # We did not process all the bytes, read again self.handle_read() except reader.NotEnoughBytes: # Rewind self.reader.pos = initial_pos except reader.ReaderError as e: log.warn(e) self.close()
def handle_close(self): log.warn("Client disconnected (%s %s)" % self._addr) return asyncore.dispatcher_with_send.handle_close(self)
def handle_expression_error(self, client): log.warn("Error from async client") self.send_error("Intermediate failed to deliver result.") client.close()