void Worker::proc() { //还原信号默认处理方式 signal(SIGTERM, NULL); signal(SIGUSR1, NULL); //set process title Config *cfg = Config::getInstance(); char title[256]; snprintf(title, 256, "fooking gateway worker, %s", cfg->sFile.c_str()); utils::setProcTitle(title); //create loop pEventLoop = new EventLoop(); pEventLoop->setMaxWaitTime(500); pEventLoop->addEventListener(nPipefd, EV_IO_READ, EV_IO_CB(this, Worker::onChannel), NULL); pEventLoop->setLoopBefore(EV_CB(this, Worker::loopBefore), NULL); //listen server pServer = new Server(pEventLoop, pMaster->pServer->getSocket().getFd()); pServer->setConnectionHandler(EV_IO_CB(this, Worker::onConnection)); if(!pMaster->bUseAcceptMutex){ pServer->start(); } //init router initRouter(); //backend env char root[256]; char name[256]; int rootlen = sprintf(root, "%s/%s", cfg->sFastcgiRoot.c_str(), cfg->sFastcgiFile.c_str()); int namelen = sprintf(name, "/%s", cfg->sFastcgiFile.c_str()); Backend::addSharedParam("REQUEST_METHOD", strlen("REQUEST_METHOD"), "POST", strlen("POST")); Backend::addSharedParam("SCRIPT_FILENAME", strlen("SCRIPT_FILENAME"), root, rootlen); Backend::addSharedParam("SCRIPT_NAME", strlen("SCRIPT_NAME"), name, namelen); Backend::addSharedParam("DOCUMENT_ROOT", strlen("DOCUMENT_ROOT"), cfg->sFastcgiRoot.c_str(), cfg->sFastcgiRoot.size()); //backend env from config.lua FastcgiParams::const_iterator it; for(it = cfg->arFastcgiParams.begin(); it != cfg->arFastcgiParams.end(); ++it){ std::string k = it->first; std::string v = it->second; Backend::addSharedParam(k.c_str(), k.size(), v.c_str(), v.size()); } LOG("worker started, pipefd=%d", nPipefd); pEventLoop->run(); }
void RouterProxyManager::updateConfig(boost::shared_ptr<mtalk::zk::ZKManager> zkManagerPtr){ //std::cout<<0<<std::endl; LOG_DEBUG("RouterProxyManagerProxy::updateConfig: router" ); std::vector<std::string> routerNameList; if(!zkManagerPtr->getChildren(routerZKPath_, routerNameList)){ LOG_ERROR("RouterProxyManagerProxy::updateZKProxy => get routerName failure : path = " << routerZKPath_); initRouter(); return; } if(routerNameList.empty()){ LOG_ERROR("RouterProxyManager::updateZKProxy => the children of router is empty,path= "<<routerZKPath_ ); return; } for(size_t i = 0; i < routerNameList.size(); ++i){ //已经存在router if(routerNameSet_.count(routerNameList[i])>0){ //continue; } string routername = routerNameList[i]; string routerNamePath(routerZKPath_); routerNamePath.append("/"); routerNamePath=routerNamePath+routerNameList[i]; LOG_DEBUG("RouterProxyManagerProxy::updateZKProxy => registerRouter begin : routerpathname = " << routerNamePath); registerRouter(routername,routerNamePath); } }
void Worker::onRouterReconnect(TimerId id, void *data) { initRouter(); }