public function onReadUdp($stream = null, $events = 0, $arg = null)
{
if (Daemon::$process->reload) {
return false;
}
if ($this->pool->maxConcurrency) {
if ($this->pool->count() >= $this->pool->maxConcurrency) {
$this->overload = true;
return false;
}
}
$host = null;
do {
$l = @socket_recvfrom($this->fd, $buf, 10240, MSG_DONTWAIT, $host, $port);
if (!$l) {
break;
}
$key = '[' . $host . ']:' . $port;
if (!isset($this->portsMap[$key])) {
if ($this->pool->allowedClients !== null) {
if (!self::netMatch($this->pool->allowedClients, $host)) {
Daemon::log('Connection is not allowed (' . $host . ')');
}
continue;
}
$class = $this->pool->connectionClass;
$conn = new $class(null, $this->pool);
$conn->setDgram(true);
$conn->onWriteEv(null);
$conn->setPeername($host, $port);
$conn->setParentSocket($this);
$this->portsMap[$key] = $conn;
$conn->timeoutRef = setTimeout(function ($timer) use($conn) {
$conn->finish();
$timer->finish();
}, $conn->timeout * 1000000.0);
$conn->onUdpPacket($buf);
} else {
$conn = $this->portsMap[$key];
$conn->onUdpPacket($buf);
Timer::setTimeout($conn->timeoutRef);
}
} while (true);
return $host !== null;
}