/** * Helper method which returns a proxy instance for a given list of * interfaces, using the default classloader and the handler defined * in setUp() * * @param lang.XPClass[] interfaces * @return lang.reflect.Proxy */ protected function proxyInstanceFor($interfaces) { return Proxy::newProxyInstance(ClassLoader::getDefault(), $interfaces, $this->handler); }
/** * Runs the server. Loads the listener using XPClass::forName() * so that the class is loaded within the thread's process space * and will be recompiled whenever the thread is restarted. * * @throws lang.XPException in case initializing the server fails * @throws lang.SystemException in case setuid fails */ public function run() { try { with($class = \lang\XPClass::forName('peer.ftp.server.FtpProtocol'), $cl = \lang\ClassLoader::getDefault()); // Add listener $this->server->setProtocol($proto = $class->newInstance($storage = Proxy::newProxyInstance($cl, [\lang\XPClass::forName('peer.ftp.server.storage.Storage')], $this->storageHandler), Proxy::newProxyInstance($cl, [\lang\XPClass::forName('security.auth.Authenticator')], $this->authenticatorHandler))); // Copy interceptors to connection listener $proto->interceptors = $this->interceptors; // Enable debugging if ($this->cat) { $proto->setTrace($this->cat); $this->server instanceof Traceable && $this->server->setTrace($this->cat); } // Try to start the server $this->server->init(); } catch (\lang\Throwable $e) { $this->server->shutdown(); throw $e; } // Check if we should run child processes // with another uid/pid if (isset($this->processGroup)) { $group = posix_getgrnam($this->processGroup); $this->cat && $this->cat->debugf('Setting group to: %s (GID: %d)', $group['name'], $group['uid']); if (!posix_setgid($group['gid'])) { throw new \lang\SystemException('Could not set GID'); } } if (isset($this->processOwner)) { $user = posix_getpwnam($this->processOwner); $this->cat && $this->cat->debugf('Setting user to: %s (UID: %d)', $user['name'], $user['uid']); if (!posix_setuid($user['uid'])) { throw new \lang\SystemException('Could not set UID'); } } $this->server->service(); }