/** * Called when new connections is waiting for accept * @param resource Descriptor * @param integer Events * @param mixed Attached variable * @return void */ public function onAcceptEvent($stream, $events, $arg) { $sockId = $arg[0]; $type = $arg[1]; if (Daemon::$config->logevents->value) { Daemon::$process->log(get_class($this) . '::' . __METHOD__ . '(' . $sockId . ') invoked.'); } if (Daemon::$process->reload) { return FALSE; } if (Daemon::$useSockets) { $fd = @socket_accept($stream); if (!$fd) { return; } socket_set_nonblock($fd); } else { $fd = @stream_socket_accept($stream, 0, $addr); if (!$fd) { return; } stream_set_blocking($fd, 0); } $id = ++Daemon::$process->connCounter; $class = $this->connectionClass; $conn = new $class($fd, $id, $this); $this->list[$id] = $conn; if (Daemon::$useSockets && $type !== self::TYPE_SOCKET) { $getpeername = function ($conn) use(&$getpeername) { $r = @socket_getpeername($conn->fd, $host, $port); if ($r === false) { if (109 === socket_last_error()) { // interrupt if ($this->allowedClients !== null) { $conn->ready = false; // lockwait } $conn->onWriteOnce($handler); return; } } $conn->addr = $host === '' ? '' : $host . ':' . $port; if ($conn->pool->allowedClients !== null) { if (!ConnectionPool::netMatch($conn->pool->allowedClients, substr($addr, 0, $p))) { Daemon::log('Connection is not allowed (' . $addr . ')'); $conn->ready = false; $conn->finish(); } } }; $getpeername($conn); } }