qqq
This commit is contained in:
@@ -42,39 +42,16 @@ class AsyncServer implements ServerInterface
|
|||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function initCoreServers(array $service, int $daemon = 0): void
|
public function initCoreServers(array $service, int $daemon = 0): void
|
||||||
{
|
|
||||||
$this->listener($service, $daemon);
|
|
||||||
$this->initProcess();
|
|
||||||
$this->onSignal();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $service
|
|
||||||
* @param $daemon
|
|
||||||
* @return void
|
|
||||||
* @throws
|
|
||||||
*/
|
|
||||||
private function listener(array $service, $daemon): void
|
|
||||||
{
|
{
|
||||||
$service = $this->genConfigService($service);
|
$service = $this->genConfigService($service);
|
||||||
|
$this->createBaseServer(array_pop($service), $daemon);
|
||||||
foreach ($service as $value) {
|
foreach ($service as $value) {
|
||||||
if (is_null($this->server)) {
|
|
||||||
$this->createBaseServer($value, $daemon);
|
|
||||||
} else {
|
|
||||||
$this->addListener($value);
|
$this->addListener($value);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
private function initProcess(): void
|
|
||||||
{
|
|
||||||
foreach ($this->_process as $process) {
|
foreach ($this->_process as $process) {
|
||||||
$this->server->addProcess($process);
|
$this->server->addProcess($process);
|
||||||
}
|
}
|
||||||
|
on(OnServerBeforeStart::class, [$this, 'onSignal']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -189,21 +166,6 @@ class AsyncServer implements ServerInterface
|
|||||||
$this->onEventListen($port, $config->getEvents());
|
$this->onEventListen($port, $config->getEvents());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $no
|
|
||||||
* @param array $signInfo
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function onSigint($no, array $signInfo): void
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
Logger::_alert('Pid ' . getmypid() . ' get signo ' . $no);
|
|
||||||
$this->shutdown();
|
|
||||||
} catch (\Throwable $exception) {
|
|
||||||
error($exception);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $type
|
* @param string $type
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace Kiri\Server\Abstracts;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Kiri;
|
use Kiri;
|
||||||
|
use Kiri\Abstracts\Logger;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
use Swoole\Coroutine;
|
use Swoole\Coroutine;
|
||||||
use Swoole\Http\Server as HServer;
|
use Swoole\Http\Server as HServer;
|
||||||
@@ -78,6 +79,22 @@ trait TraitServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $no
|
||||||
|
* @param array $signInfo
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function onSigint($no, array $signInfo): void
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
Logger::_alert('Pid ' . getmypid() . ' get signo ' . $no);
|
||||||
|
$this->shutdown();
|
||||||
|
} catch (\Throwable $exception) {
|
||||||
|
error($exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $signal
|
* @param $signal
|
||||||
* @param $callback
|
* @param $callback
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ class Server
|
|||||||
on(OnWorkerStop::class, [Timer::class, 'clearAll'], 9999);
|
on(OnWorkerStop::class, [Timer::class, 'clearAll'], 9999);
|
||||||
on(OnWorkerStart::class, [$this, 'setWorkerName']);
|
on(OnWorkerStart::class, [$this, 'setWorkerName']);
|
||||||
on(OnTaskerStart::class, [$this, 'setTaskerName']);
|
on(OnTaskerStart::class, [$this, 'setTaskerName']);
|
||||||
|
|
||||||
if (\config('reload.hot') === false) {
|
if (\config('reload.hot') === false) {
|
||||||
$this->router->scan_build_route();
|
$this->router->scan_build_route();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user