def receive_from_branch(name): """ 从旁路收包,检查包格式 :param name: 旁路名称 :return: 错误/0,(message, address)/成功 """ try: branch = BranchSocket() result = branch.receive_from_branch(name) if result == 0: return 0 if package.check_message(result[0]) == 0: # 无效包,协程超时处理 return 0 return result except Exception as e: g_log.error("%s", e) return 0
def receive_from_sock(sock): """ 从socket收包,检查包格式 :param sock: socket :return: 0/失败,(message, address)/成功 """ if sock: try: message, address = sock.recvfrom(65536) if package.check_message(message) == 0: # 无效包 return 0 return message, address except Exception as e: g_log.debug("%s", e) g_log.error("receive message from socket failed") return 0 else: return 0