mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-02 11:48:08 +08:00
Fixed: http server will be affected of wesocket server
This commit is contained in:
parent
1bfb8d1d07
commit
204b1ac3da
@ -24,7 +24,7 @@ class FdCollector
|
||||
static::$fds[$id] = new Fd($id, $class);
|
||||
}
|
||||
|
||||
public static function get(int $id, $default = null): Fd
|
||||
public static function get(int $id, $default = null): ?Fd
|
||||
{
|
||||
return static::$fds[$id] ?? $default;
|
||||
}
|
||||
|
@ -30,12 +30,9 @@ class CoreMiddleware extends HttpCoreMiddleware
|
||||
{
|
||||
/** @var ResponseInterface $response */
|
||||
$uri = $request->getUri();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* Returns array with one of the following formats:
|
||||
* [self::NOT_FOUND]
|
||||
* [self::METHOD_NOT_ALLOWED, ['GET', 'OTHER_ALLOWED_METHODS']]
|
||||
* [self::FOUND, $handler, ['varName' => 'value', ...]]
|
||||
*/
|
||||
$routes = $this->dispatcher->dispatch($request->getMethod(), $uri->getPath());
|
||||
|
||||
|
@ -154,15 +154,20 @@ class Server implements MiddlewareInitializerInterface, OnHandShakeInterface, On
|
||||
|
||||
public function onClose(\Swoole\Server $server, int $fd, int $reactorId): void
|
||||
{
|
||||
$this->logger->debug("WebSocket: fd[{$fd}] close a active connection.");
|
||||
if ($obj = FdCollector::get($fd)) {
|
||||
$this->logger->debug("WebSocket: fd[{$fd}] close a active connection.");
|
||||
if (! $this->container->has($obj)) {
|
||||
$this->logger->error("WebSocket: class[{$obj}] is not defined.");
|
||||
return;
|
||||
}
|
||||
|
||||
$obj = FdCollector::get($fd);
|
||||
$class = $this->container->get($obj->class);
|
||||
if ($class instanceof OnCloseInterface) {
|
||||
$class->onClose($server, $fd, $reactorId);
|
||||
$class = $this->container->get($obj->class);
|
||||
if ($class instanceof OnCloseInterface) {
|
||||
$class->onClose($server, $fd, $reactorId);
|
||||
}
|
||||
|
||||
FdCollector::del($fd);
|
||||
}
|
||||
|
||||
FdCollector::del($fd);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user