public function connectRaw($host)
{
$this->type = 'raw';
if (@inet_pton($host) === false) {
// dirty check
\PHPDaemon\Clients\DNS\Pool::getInstance()->resolve($host, function ($result) use($host) {
if ($result === false) {
Daemon::log(get_class($this) . '->connectRaw : unable to resolve hostname: ' . $host);
$this->onFailureEv();
return;
}
// @TODO stack of addrs
if (is_array($result)) {
srand(Daemon::$process->getPid());
$real = $result[rand(0, sizeof($result) - 1)];
srand();
} else {
$real = $result;
}
$this->connectRaw($real);
});
return true;
}
$this->hostReal = $host;
if ($this->host === null) {
$this->host = $this->hostReal;
}
$this->addr = $this->hostReal . ':raw';
$fd = socket_create(\EventUtil::AF_INET, \EventUtil::SOCK_RAW, 1);
if (!$fd) {
return false;
}
socket_set_nonblock($fd);
@socket_connect($fd, $host, 0);
$this->setFd($fd);
if (!$this->bev) {
return false;
}
return true;
}