Fixed bug.

This commit is contained in:
李铭昕 2019-08-02 15:46:12 +08:00
parent 30b182db92
commit 5d29105f39
2 changed files with 16 additions and 22 deletions

View File

@ -82,12 +82,7 @@ class ConfigFetcherProcess extends AbstractProcess
$processes = ProcessCollector::all();
/** @var \Swoole\Process $process */
foreach ($processes as $process) {
// TODO: Socket is not work for expected.
/* @var \Swoole\Coroutine\Socket $sock */
// $sock = $this->process->exportSocket();
// $sock->send($string);
$process->write($string);
$process->exportSocket()->send($string);
}
}

View File

@ -105,22 +105,21 @@ abstract class AbstractProcess implements ProcessInterface
*/
protected function listen()
{
Event::add($this->process->pipe, function ($pipe) {
try {
// TODO: Socket is not work for expected.
/** @var \Swoole\Coroutine\Socket $sock */
// $sock = $this->process->exportSocket();
// $recv = $sock->recv();
$recv = $this->process->read();
if ($this->event && $data = unserialize($recv)) {
$this->event->dispatch(new PipeMessage($data));
}
} catch (\Throwable $exception) {
if ($this->container->has(StdoutLoggerInterface::class) && $this->container->has(FormatterInterface::class)) {
$logger = $this->container->get(StdoutLoggerInterface::class);
$formatter = $this->container->get(FormatterInterface::class);
$logger->error($formatter->format($exception));
go(function () {
while (true) {
try {
/** @var \Swoole\Coroutine\Socket $sock */
$sock = $this->process->exportSocket();
$recv = $sock->recv();
if ($this->event && $data = unserialize($recv)) {
$this->event->dispatch(new PipeMessage($data));
}
} catch (\Throwable $exception) {
if ($this->container->has(StdoutLoggerInterface::class) && $this->container->has(FormatterInterface::class)) {
$logger = $this->container->get(StdoutLoggerInterface::class);
$formatter = $this->container->get(FormatterInterface::class);
$logger->error($formatter->format($exception));
}
}
}
});