改名
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace Server\Abstracts;
|
||||
|
||||
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
use Swoole\Coroutine;
|
||||
use Swoole\Process;
|
||||
|
||||
@@ -16,20 +17,31 @@ abstract class CustomProcess implements \Server\SInterface\CustomProcess
|
||||
protected bool $enableSwooleCoroutine = true;
|
||||
|
||||
|
||||
/** @var Coroutine\Channel */
|
||||
protected Coroutine\Channel $channel;
|
||||
|
||||
|
||||
/**
|
||||
* @param Process $process
|
||||
*/
|
||||
public function signListen(Process $process): void
|
||||
{
|
||||
$this->channel = new Coroutine\Channel(1);
|
||||
$this->channel->push(1);
|
||||
|
||||
if (!$this->enableSwooleCoroutine) {
|
||||
Process::signal(SIGTERM | SIGKILL, function ($signo)
|
||||
use ($process) {
|
||||
putenv('processStatus=exit');
|
||||
|
||||
$this->waiteExit($process);
|
||||
});
|
||||
} else {
|
||||
go(function () use ($process) {
|
||||
$data = Coroutine::waitSignal(SIGTERM | SIGKILL, -1);
|
||||
if ($data) {
|
||||
putenv('processStatus=exit');
|
||||
|
||||
$this->waiteExit($process);
|
||||
}
|
||||
});
|
||||
@@ -37,9 +49,40 @@ abstract class CustomProcess implements \Server\SInterface\CustomProcess
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
#[Pure] protected function getStatus(): string
|
||||
{
|
||||
return env('processStatus', 'working');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
#[Pure] protected function isExit(): bool
|
||||
{
|
||||
return $this->getStatus() == 'exit';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function exit()
|
||||
{
|
||||
$this->channel->pop();
|
||||
$this->channel->close();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isWorking(): bool
|
||||
{
|
||||
return false;
|
||||
return $this->channel->isEmpty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user