This commit is contained in:
2021-10-28 16:17:25 +08:00
parent 642e16a07c
commit cd17f2b63b
+3 -15
View File
@@ -97,11 +97,7 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
private function batchDispatch(Server $server, int $fd, array $data): void private function batchDispatch(Server $server, int $fd, array $data): void
{ {
if (isset($data['jsonrpc'])) { if (isset($data['jsonrpc'])) {
$dispatch = $this->dispatch($data); $result = json_encode($this->dispatch($data), JSON_UNESCAPED_UNICODE);
if (!isset($data['id'])) {
return;
}
$result = json_encode($dispatch, JSON_UNESCAPED_UNICODE);
} else { } else {
$channel = new Channel($total = count($data)); $channel = new Channel($total = count($data));
foreach ($data as $datum) { foreach ($data as $datum) {
@@ -109,11 +105,7 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
} }
$result = []; $result = [];
for ($i = 0; $i < $total; $i++) { for ($i = 0; $i < $total; $i++) {
$params = $channel->pop(); $result[] = $channel->pop();
if (empty($params)) {
continue;
}
$result[] = $params;
} }
} }
$server->send($fd, json_encode($result, JSON_UNESCAPED_UNICODE)); $server->send($fd, json_encode($result, JSON_UNESCAPED_UNICODE));
@@ -132,11 +124,7 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
} else if (!isset($datum['method'])) { } else if (!isset($datum['method'])) {
$channel->push($this->failure(-32700, 'Parse error语法解析错误')); $channel->push($this->failure(-32700, 'Parse error语法解析错误'));
} else { } else {
$dispatch = $this->dispatch($datum); $channel->push($this->dispatch($datum));
if (!isset($dispatch['id'])) {
$dispatch = null;
}
$channel->push($dispatch);
} }
}); });
} }