mirror of
https://github.com/danog/dns.git
synced 2024-11-26 20:14:51 +01:00
Fix garbage collection and mark classes as final / internal
This commit is contained in:
parent
fd7c82113c
commit
8271989335
@ -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 */
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Amp\Dns;
|
||||
|
||||
class Config {
|
||||
final class Config {
|
||||
private $nameservers;
|
||||
private $knownHosts;
|
||||
private $timeout;
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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 = [
|
||||
|
Loading…
Reference in New Issue
Block a user