Skip to content

Commit

Permalink
Merge pull request #647 from huangzhhui/jsonrpc
Browse files Browse the repository at this point in the history
Append eof to tcp response
  • Loading branch information
huangzhhui committed Oct 7, 2019
2 parents a8d2bf4 + 9c3b687 commit ce968bb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -92,6 +92,7 @@ Now:

- [#448](https://github.com/hyperf-cloud/hyperf/pull/448) Fixed TCP Server does not works when HTTP Server or WebSocket Server exists.
- [#623](https://github.com/hyperf-cloud/hyperf/pull/623) Fixed the argument value will be replaced by default value when pass a `null` to the method of proxy class.
- [#647](https://github.com/hyperf-cloud/hyperf/pull/647) Append `eof` to TCP response, according to the server configuration.

# v1.0.16 - 2019-09-20

Expand Down
18 changes: 17 additions & 1 deletion src/rpc-server/src/Server.php
Expand Up @@ -126,7 +126,7 @@ public function onReceive(SwooleServer $server, int $fd, int $fromId, string $da
$response = $this->transferToResponse($response);
}
if ($response) {
$server->send($fd, (string) $response->getBody());
$this->send($server, $fd, $response);
}
}
}
Expand All @@ -139,6 +139,22 @@ public function onConnect(SwooleServer $server)
$this->logger->debug(sprintf('Connect to %s:%d', $port->host, $port->port));
}

protected function send(SwooleServer $server, int $fd, ResponseInterface $response): void
{
$eof = $server->setting['package_eof'] ?? '';
$serverPort = $server->getClientInfo($fd)['server_port'] ?? null;
if ($serverPort) {
foreach ($server->ports ?? [] as $port) {
if ($port->port === $serverPort) {
$eof = $port->setting['package_eof'] ?? $eof;
break;
}
}
}

$server->send($fd, (string) $response->getBody() . $eof);
}

abstract protected function createCoreMiddleware(): CoreMiddlewareInterface;

abstract protected function buildRequest(int $fd, int $fromId, string $data): ServerRequestInterface;
Expand Down

0 comments on commit ce968bb

Please sign in to comment.