Skip to content

Commit

Permalink
修正rpc服务端执行容器
Browse files Browse the repository at this point in the history
  • Loading branch information
yunwuxin committed Feb 1, 2021
1 parent 9613066 commit 5ccbb5a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/RpcManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ public function onReceive(Server $server, $fd, $reactorId, $data)
$this->waitCoordinator('workerStart');

$this->recv($server, $fd, $data, function ($data) use ($fd) {
$this->runInSandbox(function (Dispatcher $dispatcher) use ($fd, $data) {
$dispatcher->dispatch($fd, $data);
$this->runInSandbox(function (App $app, Dispatcher $dispatcher) use ($fd, $data) {
$dispatcher->dispatch($app, $fd, $data);
}, $fd, true);
});
}
Expand Down
18 changes: 8 additions & 10 deletions src/rpc/server/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ class Dispatcher
*/
const INTERNAL_ERROR = -32603;

protected $app;

protected $parser;

protected $services = [];
Expand All @@ -56,9 +54,8 @@ class Dispatcher

protected $middleware = [];

public function __construct(App $app, ParserInterface $parser, Server $server, $services, $middleware = [])
public function __construct(ParserInterface $parser, Server $server, $services, $middleware = [])
{
$this->app = $app;
$this->parser = $parser;
$this->server = $server;
$this->prepareServices($services);
Expand Down Expand Up @@ -141,10 +138,11 @@ protected function getParameters(ReflectionMethod $method)

/**
* 调度
* @param App $app
* @param int $fd
* @param string|File|Error $data
*/
public function dispatch(int $fd, $data)
public function dispatch(App $app, int $fd, $data)
{
try {
switch (true) {
Expand All @@ -159,7 +157,7 @@ public function dispatch(int $fd, $data)
break;
default:
$protocol = $this->parser->decode($data);
$result = $this->dispatchWithMiddleware($protocol, $fd);
$result = $this->dispatchWithMiddleware($app, $protocol, $fd);
}
} catch (Throwable $e) {
$result = Error::make($e->getCode(), $e->getMessage());
Expand All @@ -172,12 +170,12 @@ public function dispatch(int $fd, $data)
unset($this->files[$fd]);
}

protected function dispatchWithMiddleware(Protocol $protocol, $fd)
protected function dispatchWithMiddleware(App $app, Protocol $protocol, $fd)
{
return Middleware::make($this->app, $this->middleware)
return Middleware::make($app, $this->middleware)
->pipeline()
->send($protocol)
->then(function (Protocol $protocol) use ($fd) {
->then(function (Protocol $protocol) use ($app, $fd) {

$interface = $protocol->getInterface();
$method = $protocol->getMethod();
Expand All @@ -198,7 +196,7 @@ protected function dispatchWithMiddleware(Protocol $protocol, $fd)
);
}

return $this->app->invoke([$this->app->make($service['class']), $method], $params);
return $app->invoke([$app->make($service['class']), $method], $params);
});
}
}

0 comments on commit 5ccbb5a

Please sign in to comment.