def _callback()

in dubbo/connection/connections.py [0:0]


    def _callback(self, data, conn, data_type, invoke_id):
        """
        读取的数据满足之后触发的回调函数,由于connection是共有
        的,所以我们要把这一大坨和连接相关的状态保存在各自连接中
        :param data: 收到的数据
        :param conn: 对应的连接
        :param data_type:
                1 头部
                2 因为头部的解析错误,需要被读取的错误body
                3 正确的body
        :param invoke_id
        :return:
            next_read_length 下一次读取需要读取的数据长度
            next_read_type   下一次读取需要读取的数据类型
            invoke_id        此次调用的id
        """
        host = conn.remote_host()
        # 关闭连接
        if not data:
            logger.debug('{} closed by remote server.'.format(host))
            self._delete_connection(conn)
            return 0, 0, 0

        # 响应的头部
        if data_type == 1:
            logger.debug('received response head with invoke_id={}, host={}'.format(unpack('!q', data[4:12])[0], host))
            return self._parse_head(data, conn)
        # 错误的响应体
        elif data_type == 2:
            logger.debug('received error response body with invoke_id={}, host={}'.format(invoke_id, host))
            res = Response(data)
            error = res.read_next()
            self.results[invoke_id] = DubboResponseException('\n{}'.format(error))
            self.conn_events[invoke_id].set()
            return DEFAULT_READ_PARAMS
        # 正常的响应体
        elif data_type == 3:
            logger.debug('received normal response body with invoke_id={}, host={}'.format(invoke_id, host))
            self._parse_response(invoke_id, data)
            return DEFAULT_READ_PARAMS

        else:
            raise RuntimeError('Unknown data type {}.'.format(data_type))