bool TMultiplexingServer::start() { if (isRunning()) return true; // Loads libs TApplicationServerBase::loadLibraries(); TStaticInitializeThread *initializer = new TStaticInitializeThread(); initializer->start(); initializer->wait(); delete initializer; connect(this, SIGNAL(finished()), this, SLOT(deleteLater())); QThread::start(); return true; }
bool TApplicationServer::open() { T_TRACEFUNC(""); if (!isListening()) { quint16 port = Tf::app()->appSettings().value("ListenPort").toUInt(); int sock = nativeListen(QHostAddress::Any, port); if (sock > 0 && setSocketDescriptor(sock)) { tSystemDebug("listen successfully. port:%d", port); } else { tSystemError("Failed to set socket descriptor: %d", sock); nativeClose(sock); return false; } } // Loads libraries if (!libLoaded) { // Sets work directory QString libPath = Tf::app()->libPath(); if (QDir(libPath).exists()) { // To resolve the symbols in the app libraries QDir::setCurrent(libPath); } else { tSystemError("lib directory not found"); return false; } QStringList libs; #if defined(Q_OS_WIN) libs << "controller" << "view"; #else libs << "libcontroller" << "libview"; #endif for (QStringListIterator it(libs); it.hasNext(); ) { QLibrary lib(it.next()); if (lib.load()) { tSystemDebug("Library loaded: %s", qPrintable(lib.fileName())); libLoaded = true; } else { tSystemError("%s", qPrintable(lib.errorString())); } } QStringList controllers = TActionController::availableControllers(); tSystemDebug("Available controllers: %s", qPrintable(controllers.join(" "))); } QDir::setCurrent(Tf::app()->webRootPath()); TUrlRoute::instantiate(); TSqlDatabasePool::instantiate(); switch (Tf::app()->multiProcessingModule()) { case TWebApplication::Thread: { TStaticInitializeThread *initializer = new TStaticInitializeThread(); initializer->start(); initializer->wait(); delete initializer; break; } case TWebApplication::Prefork: { TStaticInitializer *initializer = new TStaticInitializer(); initializer->start(); delete initializer; break; } default: break; } return true; }
bool TApplicationServer::open() { T_TRACEFUNC(); if (!isListening()) { quint16 port = Tf::app()->appSettings().value("ListenPort").toUInt(); int sock = nativeListen(QHostAddress::Any, port); if (sock > 0 && setSocketDescriptor(sock)) { tSystemDebug("listen successfully. port:%d", port); } else { tSystemError("Failed to set socket descriptor: %d", sock); nativeClose(sock); return false; } } // Loads libraries if (!libLoaded) { // Sets work directory QString libPath = Tf::app()->libPath(); if (QDir(libPath).exists()) { // To resolve the symbols in the app libraries QDir::setCurrent(libPath); } else { tSystemError("lib directory not found"); return false; } QStringList filter; #if defined(Q_OS_WIN) filter << "controller.dll" << "view.dll"; #elif defined(Q_OS_DARWIN) filter << "libcontroller.dylib" << "libview.dylib"; #elif defined(Q_OS_UNIX) filter << "libcontroller.so" << "libview.so"; #else filter << "libcontroller.*" << "libview.*"; #endif QDir controllerDir("."); QStringList list = controllerDir.entryList(filter, QDir::Files); for (QStringListIterator i(list); i.hasNext(); ) { QString path = controllerDir.absoluteFilePath(i.next()); QLibrary lib(path); if (lib.load()) { tSystemDebug("Library loaded: %s", qPrintable(path)); libLoaded = true; } else { tSystemError("%s", qPrintable(lib.errorString())); } } } QDir::setCurrent(Tf::app()->webRootPath()); TUrlRoute::instantiate(); TSqlDatabasePool::instantiate(); switch (Tf::app()->multiProcessingModule()) { case TWebApplication::Thread: { TStaticInitializeThread *initializer = new TStaticInitializeThread(); initializer->start(); initializer->wait(); delete initializer; break; } case TWebApplication::Prefork: { TStaticInitializer *initializer = new TStaticInitializer(); initializer->start(); delete initializer; break; } default: break; } return true; }