Exemplo n.º 1
0
	def __peek_protoc(self):
		self.process()
		if len(self.recv_buf) == 0:
			return None
		check_result = protoc.check_recv(self.recv_buf)
		#log.debug('peek protoc:%s'%self.recv_buf)
		return check_result
Exemplo n.º 2
0
	def __peek_protoc(self):
		if len(self.recv_buf) == 0:
			return None

		check_result, proto_class, err = protoc.check_recv(self.recv_buf)
		# wait for un-complete package
		if err in [protoc.PKG_ERR_NOT_READY, protoc.PKG_ERR_TOO_SHORT]:
			log.debug('package un-complete, wait for it')
			return None

		bad_pkg_bytes = 0
		while err != protoc.PKG_OK and len(self.recv_buf) > 0:
			bad_pkg_bytes += 1
			self.recv_buf = self.recv_buf[1:]
			check_result, proto_class, err = protoc.check_recv(self.recv_buf)

		if bad_pkg_bytes:
			log.critical('detect bad package, ignored %d bytes, peer: %s' % (bad_pkg_bytes, self.peername))

		if err == protoc.PKG_OK:
			# log.debug('peek package:: %s, %s' % (str(check_result), str(proto_class)))
			return (check_result, proto_class)
		return None