读取的数据满足之后触发的回调函数,由于connection是共有 的,所以我们要把这一大坨和连接相关的状态保存在各自连接中 :param data: 收到的数据 :param conn: 对应的连接 :param data_type: 1 头部 2 因为头部的解析错误,需要被读取的错误body 3 正确的body :param invoke_id :return:
(self, data, conn, data_type, invoke_id)
| 111 | raise NotImplementedError() |
| 112 | |
| 113 | def _callback(self, data, conn, data_type, invoke_id): |
| 114 | """ |
| 115 | 读取的数据满足之后触发的回调函数,由于connection是共有 |
| 116 | 的,所以我们要把这一大坨和连接相关的状态保存在各自连接中 |
| 117 | :param data: 收到的数据 |
| 118 | :param conn: 对应的连接 |
| 119 | :param data_type: |
| 120 | 1 头部 |
| 121 | 2 因为头部的解析错误,需要被读取的错误body |
| 122 | 3 正确的body |
| 123 | :param invoke_id |
| 124 | :return: |
| 125 | next_read_length 下一次读取需要读取的数据长度 |
| 126 | next_read_type 下一次读取需要读取的数据类型 |
| 127 | invoke_id 此次调用的id |
| 128 | """ |
| 129 | host = conn.remote_host() |
| 130 | # 关闭连接 |
| 131 | if not data: |
| 132 | logger.debug('{} closed by remote server.'.format(host)) |
| 133 | self._delete_connection(conn) |
| 134 | return 0, 0, 0 |
| 135 | |
| 136 | # 响应的头部 |
| 137 | if data_type == 1: |
| 138 | logger.debug('received response head with invoke_id={}, host={}'.format(unpack('!q', data[4:12])[0], host)) |
| 139 | return self._parse_head(data, conn) |
| 140 | # 错误的响应体 |
| 141 | elif data_type == 2: |
| 142 | logger.debug('received error response body with invoke_id={}, host={}'.format(invoke_id, host)) |
| 143 | res = Response(data) |
| 144 | error = res.read_next() |
| 145 | self.results[invoke_id] = DubboResponseException('\n{}'.format(error)) |
| 146 | self.conn_events[invoke_id].set() |
| 147 | return DEFAULT_READ_PARAMS |
| 148 | # 正常的响应体 |
| 149 | elif data_type == 3: |
| 150 | logger.debug('received normal response body with invoke_id={}, host={}'.format(invoke_id, host)) |
| 151 | self._parse_response(invoke_id, data) |
| 152 | return DEFAULT_READ_PARAMS |
| 153 | |
| 154 | else: |
| 155 | raise RuntimeError('Unknown data type {}.'.format(data_type)) |
| 156 | |
| 157 | def _parse_head(self, data, conn): |
| 158 | """ |
nothing calls this directly
no test coverage detected