def _consume_single_frame(self): try: header = self._sock.recv(9) except Exception as e: self.logger.debug("%s _consume_single_frame:%r, inactive time:%d", self.ip, e, time.time() - self.last_recv_time) self.close("ConnectionReset:%r" % e) return self.last_recv_time = time.time() # Parse the header. We can use the returned memoryview directly here. frame, length = Frame.parse_frame_header(header) if length > FRAME_MAX_ALLOWED_LEN: self.logger.error( "%s Frame size exceeded on stream %d (received: %d, max: %d)", self.ip, frame.stream_id, length, FRAME_MAX_LEN) # self._send_rst_frame(frame.stream_id, 6) # 6 = FRAME_SIZE_ERROR try: data = self._recv_payload(length) except Exception as e: self.close("ConnectionReset:%r" % e) return self._consume_frame_payload(frame, data)
def _consume_single_frame(self): try: header = self._sock.recv(9) except socket.timeout as e: self.logger.debug("%s _consume_single_frame:%r, inactive time:%d", self.ip_str, e, time.time() - self.last_recv_time) self.close("recv.timeout:%r" % e) return except ConnectionResetError as e: self.logger.debug("%s _consume_single_frame:%r, inactive time:%d", self.ip_str, e, time.time() - self.last_recv_time) self.close("ConnectionReset:%r" % e) return except BlockingIOError as e: # This error happened on upload large file or speed test # Just ignore this error and will be fine # self.logger.debug("%s _consume_single_frame BlockingIOError %r", self.ip_str, e) return except Exception as e: if self.keep_running: self.logger.exception( "%s _consume_single_frame:%r, inactive time:%d", self.ip_str, e, time.time() - self.last_recv_time) self.close("ConnectionReset:%r" % e) return self.last_recv_time = time.time() # Parse the header. We can use the returned memoryview directly here. frame, length = Frame.parse_frame_header(header) #self.logger.debug("h2 %s recv %s", self.ip_str, frame) if length > FRAME_MAX_ALLOWED_LEN: self.logger.error( "%s Frame size exceeded on stream %d (received: %d, max: %d)", self.ip_str, frame.stream_id, length, FRAME_MAX_LEN) # self._send_rst_frame(frame.stream_id, 6) # 6 = FRAME_SIZE_ERROR try: data = self._recv_payload(length) except Exception as e: self.close("ConnectionReset:%r" % e) return self._consume_frame_payload(frame, data)
def _consume_single_frame(self): try: header = self._sock.recv(9) except Exception as e: xlog.warn("%s _consume_single_frame:%r", self.ip, e) self.close("disconnect:%r" % e) return # Parse the header. We can use the returned memoryview directly here. frame, length = Frame.parse_frame_header(header) if length > FRAME_MAX_LEN: xlog.error("Frame size exceeded on stream %d (received: %d, max: %d)", frame.stream_id, length, FRAME_MAX_LEN) # self._send_rst_frame(frame.stream_id, 6) # 6 = FRAME_SIZE_ERROR data = self._recv_payload(length) self._consume_frame_payload(frame, data)
def _consume_single_frame(self): try: header = self._sock.recv(9) except Exception as e: self.logger.debug("%s _consume_single_frame:%r, inactive time:%d", self.ip, e, time.time()-self.last_active_time) self.close("disconnect:%r" % e) return # Parse the header. We can use the returned memoryview directly here. frame, length = Frame.parse_frame_header(header) if length > FRAME_MAX_ALLOWED_LEN: self.logger.error("%s Frame size exceeded on stream %d (received: %d, max: %d)", self.ip, frame.stream_id, length, FRAME_MAX_LEN) # self._send_rst_frame(frame.stream_id, 6) # 6 = FRAME_SIZE_ERROR data = self._recv_payload(length) self.last_active_time = time.time() self._consume_frame_payload(frame, data)
def decode_frame(frame_data): f, length = Frame.parse_frame_header(frame_data[:9]) f.parse_body(memoryview(frame_data[9:9 + length])) assert 9 + length == len(frame_data) return f