1
0
mirror of https://github.com/danog/dns.git synced 2024-11-26 20:14:51 +01:00

Disable read watcher when no resolve operations pending

This commit is contained in:
Daniel Lowrey 2014-11-03 23:49:19 -05:00
parent 980fd6a434
commit e58d46d3c5

View File

@ -83,6 +83,11 @@ class Client {
*/
private $serverPort = 53;
/**
* @var bool
*/
private $isReadWatcherEnabled = false;
/**
* @param \Amp\Reactor $reactor
* @param \Amp\Dns\RequestBuilder $requestBuilder
@ -121,18 +126,23 @@ class Client {
));
}
$future = new Future($this->reactor);
if (!$this->isReadWatcherEnabled) {
$this->isReadWatcherEnabled = true;
$this->reactor->enable($this->readWatcherId);
}
$promisor = new Future($this->reactor);
$id = $this->getNextFreeLookupId();
$this->pendingLookups[$id] = [
'name' => $name,
'requests' => $this->getRequestList($mode),
'last_type' => null,
'future' => $future,
'future' => $promisor,
];
$this->processPendingLookup($id);
return $future->promise();
return $promisor->promise();
}
private function connect() {
@ -142,9 +152,10 @@ class Client {
}
stream_set_blocking($this->socket, 0);
$this->readWatcherId = $this->reactor->onReadable($this->socket, function() {
$this->onReadableSocket();
});
}, $enableNow = false);
return true;
}
@ -231,12 +242,7 @@ class Client {
$this->pendingRequestsById[$id],
$this->pendingRequestsByNameAndType[$name][$request['type']]
);
/*
if (!$this->pendingRequestsById) {
$this->reactor->cancel($this->readWatcherId);
$this->readWatcherId = null;
}
*/
// Interpret the response and make sure we have at least one resource record
$interpreted = $this->responseInterpreter->interpret($response, $request['type']);
if ($interpreted === null) {
@ -280,6 +286,11 @@ class Client {
$code = $type
));
}
if (empty($this->pendingLookups)) {
$this->isReadWatcherEnabled = false;
$this->reactor->disable($this->readWatcherId);
}
}
private function completeRequest($request, $addr, $type) {