Skip to content

Commit

Permalink
Prefer IPv4 over IPv6, fixes #35
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Oct 31, 2017
1 parent 0813053 commit ef03a72
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ function connect(string $uri, ClientConnectContext $socketContext = null, Cancel
} else {
// Host is not an IP address, so resolve the domain name.
$records = yield Dns\resolve($host, $socketContext->getDnsTypeRestriction());

// Usually the faster response should be preferred, but we don't have a reliable way of determining IPv6
// support, so we always prefer IPv4 here.
\usort($records, function (Dns\Record $a, Dns\Record $b) {
return $a->getType() - $b->getType();
});

foreach ($records as $record) {
/** @var Dns\Record $record */
if ($record->getType() === Dns\Record::AAAA) {
Expand Down

0 comments on commit ef03a72

Please sign in to comment.