Skip to content

Commit

Permalink
Use system default DNS server config
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Feb 27, 2018
1 parent fd735dd commit dfc89a4
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Once [installed](#install), you can use the following code to connect to an UDP

```php
$loop = React\EventLoop\Factory::create();

$factory = new React\Datagram\Factory($loop);

$factory->createClient('localhost:1234')->then(function (React\Datagram\Socket $client) {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"php": ">=5.3",
"evenement/evenement": "^3.0 || ^2.0 || ^1.0",
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
"react/dns": "^0.4.11",
"react/dns": "^0.4.13",
"react/promise": "~2.1|~1.2"
},
"require-dev": {
Expand Down
6 changes: 1 addition & 5 deletions examples/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
require_once __DIR__.'/../vendor/autoload.php';

$loop = React\EventLoop\Factory::create();

$factory = new React\Dns\Resolver\Factory();
$resolver = $factory->createCached('8.8.8.8', $loop);

$factory = new React\Datagram\Factory($loop, $resolver);
$factory = new React\Datagram\Factory($loop);

$factory->createClient('localhost:1234')->then(function (React\Datagram\Socket $client) use ($loop) {
$client->send('first');
Expand Down
1 change: 0 additions & 1 deletion examples/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require_once __DIR__.'/../vendor/autoload.php';

$loop = React\EventLoop\Factory::create();

$factory = new React\Datagram\Factory($loop);

$factory->createServer('localhost:1234')->then(function (React\Datagram\Socket $server) {
Expand Down
10 changes: 8 additions & 2 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace React\Datagram;

use React\Datagram\Socket;
use React\Dns\Config\Config;
use React\Dns\Resolver\Factory as DnsFactory;
use React\Dns\Resolver\Resolver;
use React\EventLoop\LoopInterface;
Expand All @@ -19,13 +20,18 @@ class Factory
*
* @param LoopInterface $loop
* @param Resolver|null $resolver Resolver instance to use. Will otherwise
* default to using Google's public DNS 8.8.8.8
* try to load the system default DNS config or fall back to using
* Google's public DNS 8.8.8.8
*/
public function __construct(LoopInterface $loop, Resolver $resolver = null)
{
if ($resolver === null) {
// try to load nameservers from system config or default to Google's public DNS
$config = Config::loadSystemConfigBlocking();
$server = $config->nameservers ? reset($config->nameservers) : '8.8.8.8';

$factory = new DnsFactory();
$resolver = $factory->create('8.8.8.8', $loop);
$resolver = $factory->create($server, $loop);
}

$this->loop = $loop;
Expand Down

0 comments on commit dfc89a4

Please sign in to comment.