This commit is contained in:
2021-03-23 19:07:24 +08:00
parent 4c1dd409b0
commit 14bea1664e
3 changed files with 35 additions and 4 deletions
+1 -1
View File
@@ -391,7 +391,7 @@ class Server extends HttpService
if (!isset($settings['pid_file'])) { if (!isset($settings['pid_file'])) {
$settings['pid_file'] = PID_PATH; $settings['pid_file'] = PID_PATH;
} }
$this->debug(sprintf('Check listen %s::%d -> ok', $config['host'], $config['port'])); $this->debug(Snowflake::listen($config));
$this->onLoadWebsocketHandler(); $this->onLoadWebsocketHandler();
if ($this->baseServer instanceof Http) { if ($this->baseServer instanceof Http) {
+24 -3
View File
@@ -59,9 +59,9 @@ class Service extends Component
$mode = $service['mode'] ?? SWOOLE_SOCK_TCP6; $mode = $service['mode'] ?? SWOOLE_SOCK_TCP6;
if (Snowflake::port_already($service['port'])) { if (Snowflake::port_already($service['port'])) {
throw new Exception(sprintf('Port %s::%d is already.', $service['host'], $service['port'])); throw new Exception($this->already($service));
} }
$this->debug(sprintf('Port %s::%d is already.', $service['host'], $service['port'])); $this->debug(Snowflake::listen($service));
$rpcServer = $server->addlistener($service['host'], $service['port'], $mode); $rpcServer = $server->addlistener($service['host'], $service['port'], $mode);
$rpcServer->set([ $rpcServer->set([
@@ -72,7 +72,28 @@ class Service extends Component
'open_http_protocol' => false, 'open_http_protocol' => false,
'open_websocket_protocol' => false, 'open_websocket_protocol' => false,
]); ]);
$router->addPortListen($service['port'], function () use ($service, $mode) { $this->listenPort($service, $mode);
}
/**
* @param $service
* @return string
*/
private function already($service): string
{
return sprintf('Port %s::%d is already.', $service['host'], $service['port']);
}
/**
* @param $service
* @param $mode
* @throws Exception
*/
private function listenPort($service, $mode)
{
router()->addPortListen($service['port'], function () use ($service, $mode) {
try { try {
/** @var Request $request */ /** @var Request $request */
$request = Context::getContext('request'); $request = Context::getContext('request');
+10
View File
@@ -102,6 +102,16 @@ class Snowflake
} }
/**
* @param $service
* @return string
*/
#[Pure] public static function listen($service): string
{
return sprintf('Check listen %s::%d -> ok', $service['host'], $service['port']);
}
/** /**
* @param $className * @param $className
* @param array $construct * @param array $construct