This commit is contained in:
2021-07-21 14:27:31 +08:00
parent 98cf8ff17d
commit 270a7ca961
3 changed files with 11 additions and 9 deletions
+6 -4
View File
@@ -65,11 +65,13 @@ class HTTPServerListener extends Abstracts\Server
static::$_http->set($settings['settings'] ?? []);
static::$_http->on('request', [$reflect, 'onRequest']);
static::$_http->on('connect', [$reflect, 'onConnect']);
static::$_http->on('disconnect', [$reflect, 'onDisconnect']);
$reflect->setEvents(Constant::DISCONNECT, $settings['events'][Constant::DISCONNECT] ?? null);
static::$_http->on('close', [$reflect, 'onClose']);
if (swoole_version() >= '4.7.0') {
static::$_http->on('disconnect', [$reflect, 'onDisconnect']);
$reflect->setEvents(Constant::DISCONNECT, $settings['events'][Constant::DISCONNECT] ?? null);
}
$reflect->setEvents(Constant::CLOSE, $settings['events'][Constant::CLOSE] ?? null);
$reflect->setEvents(Constant::CONNECT, $settings['events'][Constant::CONNECT] ?? null);
return static::$_http;
}
+3 -3
View File
@@ -31,6 +31,7 @@ class TCPServerListener extends Abstracts\Server
* @return Server\Port
* @throws NotFindClassException
* @throws ReflectionException
* @throws Exception
*/
public static function instance(Server $server, string $host, int $port, int $mode, ?array $settings = []): Server\Port
{
@@ -44,13 +45,12 @@ class TCPServerListener extends Abstracts\Server
static::$_tcp->set($settings['settings'] ?? []);
static::$_tcp->on('receive', [$reflect, 'onReceive']);
static::$_tcp->on('connect', [$reflect, 'onConnect']);
static::$_tcp->on('close', [$reflect, 'onClose']);
if (swoole_version() >= '4.7.0') {
static::$_tcp->on('disconnect', [$reflect, 'onDisconnect']);
$reflect->setEvents(Constant::DISCONNECT, $settings['events'][Constant::DISCONNECT] ?? null);
} else {
static::$_tcp->on('close', [$reflect, 'onClose']);
$reflect->setEvents(Constant::CLOSE, $settings['events'][Constant::CLOSE] ?? null);
}
$reflect->setEvents(Constant::CLOSE, $settings['events'][Constant::CLOSE] ?? null);
$reflect->setEvents(Constant::RECEIVE, $settings['events'][Constant::RECEIVE] ?? null);
$reflect->setEvents(Constant::CONNECT, $settings['events'][Constant::CONNECT] ?? null);
+2 -2
View File
@@ -106,7 +106,7 @@ class WebSocketServerListener extends Abstracts\Server
*/
public function onConnect(Server $server, int $fd)
{
$this->runEvent(Constant::MESSAGE, fn() => $server->confirm($fd), [$server, $fd]);
$this->runEvent(Constant::CONNECT, fn() => $server->confirm($fd), [$server, $fd]);
}
@@ -126,7 +126,7 @@ class WebSocketServerListener extends Abstracts\Server
*/
public function onClose(Server $server, int $fd)
{
$this->runEvent(Constant::MESSAGE, fn() => $server->confirm($fd), [$server, $fd]);
$this->runEvent(Constant::CLOSE, fn() => $server->confirm($fd), [$server, $fd]);
}
}