Merge pull request #23 from 854854321/master

[MOD] add global function -> getAllFdByConnectType  根据连接类型获取所有fd.
This commit is contained in:
Whale 2020-12-25 16:41:48 +08:00 committed by GitHub
commit 747ecf28ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -369,7 +369,7 @@ class ServerEventHandler
ManagerGM::pushConnect($request->fd, $type_conn);
$conn = ManagerGM::get($request->fd);
set_coroutine_params(["server" => $server, "request" => $request, "connection" => $conn, "fd" => $request->fd]);
$conn->setOption("connect_id", strval($request->header["x-self-id"]) ?? "");
$conn->setOption("connect_id", strval($request->header["x-self-id"] ?? ""));
$dispatcher = new EventDispatcher(OnSwooleEvent::class);
$dispatcher->setRuleFunction(function ($v) {

View File

@ -288,6 +288,15 @@ function bot() {
}
}
/**
* 获取同类型所有连接的文件描述符 ID
* @author 854854321
* @return array
*/
function getAllFdByConnectType(string $type = 'default'): array {
$fds = [];
foreach (ManagerGM::getAllByName($type) as $obj) {
$fds[] = $obj->getFd();
}
return $fds;
}