mirror of
https://github.com/danog/dns.git
synced 2025-01-23 05:51:11 +01:00
Merge branch '0.2'
This commit is contained in:
commit
361e207d1f
@ -179,14 +179,16 @@ class Client
|
||||
private function sendRequest($request)
|
||||
{
|
||||
$packet = $this->requestBuilder->buildRequest($request['id'], $request['name'], $request['type']);
|
||||
fwrite($this->socket, $packet);
|
||||
|
||||
$bytesWritten = fwrite($this->socket, $packet);
|
||||
if ($bytesWritten < strlen($packet)) {
|
||||
$this->completeRequest($request, null, ResolutionErrors::ERR_REQUEST_SEND_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
$request['timeout_id'] = $this->reactor->once(function() use($request) {
|
||||
unset($this->pendingRequestsByNameAndType[$request['name']][$request['type']]);
|
||||
|
||||
foreach ($request['lookups'] as $id => $lookup) {
|
||||
$this->completePendingLookup($id, null, ResolutionErrors::ERR_SERVER_TIMEOUT);
|
||||
}
|
||||
$this->completeRequest($request, null, ResolutionErrors::ERR_SERVER_TIMEOUT);
|
||||
}, $this->requestTimeout);
|
||||
|
||||
if ($this->readWatcherId === null) {
|
||||
@ -245,9 +247,7 @@ class Client
|
||||
$this->cache->store($name, $addr, $type, $ttl);
|
||||
}
|
||||
|
||||
foreach ($request['lookups'] as $id => $lookup) {
|
||||
$this->completePendingLookup($id, $addr, $type);
|
||||
}
|
||||
$this->completeRequest($request, $addr, $type);
|
||||
} else {
|
||||
foreach ($request['lookups'] as $id => $lookup) {
|
||||
$this->processPendingLookup($id);
|
||||
@ -271,6 +271,20 @@ class Client
|
||||
unset($this->pendingLookups[$id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Complete all lookups in a request
|
||||
*
|
||||
* @param array $request
|
||||
* @param string|null $addr
|
||||
* @param int $type
|
||||
*/
|
||||
private function completeRequest($request, $addr, $type)
|
||||
{
|
||||
foreach ($request['lookups'] as $id => $lookup) {
|
||||
$this->completePendingLookup($id, $addr, $type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a request to the server
|
||||
*
|
||||
|
@ -7,4 +7,5 @@ class ResolutionErrors
|
||||
const ERR_INVALID_NAME = 1;
|
||||
const ERR_NO_RECORD = 2;
|
||||
const ERR_SERVER_TIMEOUT = 3;
|
||||
const ERR_REQUEST_SEND_FAILED = 4;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user