diff --git a/lib/BasicResolver.php b/lib/BasicResolver.php index c88c998..7b5030a 100644 --- a/lib/BasicResolver.php +++ b/lib/BasicResolver.php @@ -14,7 +14,7 @@ use LibDNS\Records\Question; use LibDNS\Records\QuestionFactory; use function Amp\call; -class BasicResolver implements Resolver { +final class BasicResolver implements Resolver { const CACHE_PREFIX = "amphp.dns."; /** @var \Amp\Dns\ConfigLoader */ @@ -52,9 +52,10 @@ class BasicResolver implements Resolver { $this->gcWatcher = Loop::repeat(5000, function () { $now = \time(); - foreach ($this->servers as $server) { + foreach ($this->servers as $key => $server) { if ($server->getLastActivity() < $now - 60) { - unset($this->servers); + $server->close(); + unset($this->servers[$key]); } } }); @@ -192,6 +193,7 @@ class BasicResolver implements Resolver { $server = yield $this->getServer($protocol . "://" . $nameservers[$i]); if (!$server->isAlive()) { + $this->servers[$protocol . "://" . $nameservers[$i]]->close(); unset($this->servers[$protocol . "://" . $nameservers[$i]]); /** @var \Amp\Dns\Server $server */ diff --git a/lib/Config.php b/lib/Config.php index 9db9d25..dff02d7 100644 --- a/lib/Config.php +++ b/lib/Config.php @@ -2,7 +2,7 @@ namespace Amp\Dns; -class Config { +final class Config { private $nameservers; private $knownHosts; private $timeout; diff --git a/lib/Record.php b/lib/Record.php index 768fa69..800090f 100644 --- a/lib/Record.php +++ b/lib/Record.php @@ -5,7 +5,7 @@ namespace Amp\Dns; use LibDNS\Records\ResourceQTypes; use LibDNS\Records\ResourceTypes; -class Record { +final class Record { const A = ResourceTypes::A; const AAAA = ResourceTypes::AAAA; const AFSDB = ResourceTypes::AFSDB; diff --git a/lib/Server.php b/lib/Server.php index 2076d22..c0a22d7 100644 --- a/lib/Server.php +++ b/lib/Server.php @@ -14,6 +14,7 @@ use LibDNS\Messages\MessageTypes; use LibDNS\Records\Question; use function Amp\call; +/** @internal */ abstract class Server { /** @var ResourceInputStream */ private $input; @@ -154,6 +155,18 @@ abstract class Server { }); } + public function close() { + if ($this->input === null) { + return; + } + + $this->input->close(); + $this->output->close(); + + $this->input = null; + $this->output = null; + } + protected function read(): Promise { return $this->input->read(); } diff --git a/lib/TcpServer.php b/lib/TcpServer.php index 206b2c1..ad44a95 100644 --- a/lib/TcpServer.php +++ b/lib/TcpServer.php @@ -13,6 +13,7 @@ use LibDNS\Encoder\EncoderFactory; use LibDNS\Messages\Message; use function Amp\call; +/** @internal */ class TcpServer extends Server { /** @var \LibDNS\Encoder\Encoder */ private $encoder; diff --git a/lib/UdpServer.php b/lib/UdpServer.php index 21d234d..4f8b61a 100644 --- a/lib/UdpServer.php +++ b/lib/UdpServer.php @@ -9,6 +9,7 @@ use LibDNS\Encoder\EncoderFactory; use LibDNS\Messages\Message; use function Amp\call; +/** @internal */ class UdpServer extends Server { /** @var \LibDNS\Encoder\Encoder */ private $encoder; diff --git a/lib/UnixConfigLoader.php b/lib/UnixConfigLoader.php index 1c7af9d..bbf47b8 100644 --- a/lib/UnixConfigLoader.php +++ b/lib/UnixConfigLoader.php @@ -7,7 +7,7 @@ use Amp\File\FilesystemException; use Amp\Promise; use function Amp\call; -class UnixConfigLoader implements ConfigLoader { +final class UnixConfigLoader implements ConfigLoader { private $path; private $hostLoader; diff --git a/lib/WindowsConfigLoader.php b/lib/WindowsConfigLoader.php index 8c2e38b..113ad79 100644 --- a/lib/WindowsConfigLoader.php +++ b/lib/WindowsConfigLoader.php @@ -7,7 +7,7 @@ use Amp\WindowsRegistry\KeyNotFoundException; use Amp\WindowsRegistry\WindowsRegistry; use function Amp\call; -class WindowsConfigLoader implements ConfigLoader { +final class WindowsConfigLoader implements ConfigLoader { public function loadConfig(): Promise { return call(function () { $keys = [