@@ 584-603 (lines=20) @@ | ||
581 | { |
|
582 | $this->type = 'udp'; |
|
583 | $pton = @inet_pton($host); |
|
584 | if ($pton === false) { // dirty check |
|
585 | \PHPDaemon\Clients\DNS\Pool::getInstance()->resolve($host, function ($result) use ($host, $port) { |
|
586 | if (!$result) { |
|
587 | Daemon::log(get_class($this) . '->connectUdp : unable to resolve hostname: ' . $host); |
|
588 | $this->onStateEv($this->bev, \EventBufferEvent::ERROR); |
|
589 | return; |
|
590 | } |
|
591 | // @todo stack of addrs |
|
592 | if (is_array($result)) { |
|
593 | srand(Daemon::$process->getPid()); |
|
594 | $real = $result[rand(0, sizeof($result) - 1)]; |
|
595 | srand(); |
|
596 | } else { |
|
597 | $real = $result; |
|
598 | } |
|
599 | $this->connectUdp($real, $port); |
|
600 | }); |
|
601 | return true; |
|
602 | } |
|
603 | $this->hostReal = $host; |
|
604 | if ($this->host === null) { |
|
605 | $this->host = $this->hostReal; |
|
606 | } |
|
@@ 642-664 (lines=23) @@ | ||
639 | $this->type = 'tcp'; |
|
640 | $pton = @inet_pton($host); |
|
641 | $fd = null; |
|
642 | if ($pton === false) { // dirty check |
|
643 | \PHPDaemon\Clients\DNS\Pool::getInstance()->resolve($this->host, function ($result) use ($host, $port) { |
|
644 | if (!$result) { |
|
645 | Daemon::log(get_class($this) . '->connectTcp : unable to resolve hostname: ' . $host); |
|
646 | $this->onStateEv($this->bev, \EventBufferEvent::ERROR); |
|
647 | return; |
|
648 | } |
|
649 | // @todo stack of addrs |
|
650 | if (is_array($result)) { |
|
651 | if (!sizeof($result)) { |
|
652 | return; |
|
653 | } |
|
654 | srand(Daemon::$process->getPid()); |
|
655 | $real = $result[rand(0, sizeof($result) - 1)]; |
|
656 | srand(); |
|
657 | } else { |
|
658 | $real = $result; |
|
659 | } |
|
660 | $this->connectTcp($real, $port); |
|
661 | }); |
|
662 | return true; |
|
663 | } |
|
664 | $this->hostReal = $host; |
|
665 | if ($this->host === null) { |
|
666 | $this->host = $this->hostReal; |
|
667 | } |