/*************************************************************************** **this part for LFRU Manager ***************************************************************************/ LFRUManager::LFRUManager(LBServer* _lb, ConfigType *serverConfig) : ResourceManager(_lb, serverConfig) { lb = _lb; subServerNum = serverConfig->subServerNum; resourceNum = serverConfig->resourceNumber; capacity = serverConfig->maxCapacity; period = serverConfig->period; std::ostringstream logStr; logStr << "set LFRU period = " << period ; serverLog.writeResourceLog(logStr.str()); initResource(); //set t0 gettimeofday(&t0, NULL); }
PROCESS_THREAD(test, ev, data) { static struct etimer et; PROCESS_BEGIN(); myaddr = init_l2addr_154_char("45:67"); l2 = startL2_154( myaddr, CHANNEL, PANID); ca = initCasan(l2, MTU, slaveid); r1 = initResource (R1_name, R1_title, R1_rt) ; setHandlerResource(r1, COAP_CODE_GET, process_temp ); register_resource(ca, r1); r2 = initResource (R2_name, R2_title, R2_rt) ; setHandlerResource(r2, COAP_CODE_GET, process_temp ); register_resource(ca, r2); while(1) { if (n % NTAB (resname) == 0) print_resources (ca) ; test_resource (ca, l2, resname [n++ % NTAB (resname)]) ; printf("\n"); printf("*************************************************************************"); printf("\n"); etimer_set(&et,5*CLOCK_SECOND); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); } PROCESS_END(); }
bool OnlineProcess::init() { bool ret = parseJson(fileName_, configs_); if( !ret ) { std::cout<< "error in parse json" <<std::endl; return false; } sourceDir_ = "../source"; if ( configs_["source_dir"].isString() ) { sourceDir_ = configs_["source_dir"].asString(); } ret = initResource(); if( !ret ) { std::cout<<"init resource error " <<std::endl; return false; } //useLocalIdf_ = configs_["use_local_idf"].asBool(); wordSplitDicVec_.clear(); size_t size = configs_["wordsplit_dic"].size(); for(size_t i=0 ; i<size ; i++ ){ std::string name = sourceDir_ +"/" + configs_["wordsplit_dic"][i].asString(); wordSplitDicVec_.push_back(name); } Tools& tools_ = ProcessResource::instance().tools() ; int result = tools_.m_wordsplit->load(wordSplitDicVec_); if ( result != 0 ) { std::cout<<"init wordsplit error" <<std::endl; return false; } Json::Value& strategy = configs_["strategy"]; Json::Value::Members members = strategy.getMemberNames(); Json::Value::Members::iterator iter = members.begin(); for( ;iter != members.end(); iter++ ) { std::string name = *iter; std::string ruleFile = strategy[name].asString(); ProcessStrategy& ps = strategies_[name]; ret = ps.init(ruleFile, *this); if( !ret ) { std::cout<<" init failed: "<< name <<std::endl; return false; } } return true; }
ResourceManager::ResourceManager(LBServer *_lb, ConfigType *serverConfig) { lb = _lb; subServerNum = serverConfig->subServerNum; resourceNum = serverConfig->resourceNumber; capacity = serverConfig->maxCapacity; period = serverConfig->period; fileList.clear(); string logStr = "init ResourceManager::fileList"; serverLog.writeResourceLog(logStr); for (unsigned int i = 0; i < resourceNum; i++) { unsigned int filePlayLen = Randomi(serverConfig->minPlayLen, serverConfig->maxPlayLen); FileInfo *fileInfo = new FileInfo(i, filePlayLen); if (fileInfo != NULL) fileList.push_back(fileInfo); } initResource(); }
bool KDSoapUnitTestHelpers::setSslConfiguration() { initResource(); // To make SSL work, we need to tell Qt about our local certificate // Both ways work: #if 0 QSslConfiguration defaultConfig = QSslConfiguration::defaultConfiguration(); QFile certFile(QString::fromLatin1(":/certs/cacert.pem")); if (!certFile.open(QIODevice::ReadOnly)) { qDebug() << "Could not open cacert.pem"; return false; } QSslCertificate cert(&certFile); if (!cert.isValid()) return false; defaultConfig.setCaCertificates(QList<QSslCertificate>() << cert); QSslConfiguration::setDefaultConfiguration(defaultConfig); #endif QFile certFile(QString::fromLatin1(":/certs/cacert.pem")); if (!certFile.open(QIODevice::ReadOnly)) { qDebug() << "Could not open cacert.pem"; return false; } QSslCertificate cert(&certFile); const QDateTime currentTime = QDateTime::currentDateTime(); if (cert.effectiveDate() > currentTime || cert.expiryDate() < currentTime) { qDebug() << "Certificate" << certFile.fileName() << "is not valid"; qDebug() << "It is valid from" << cert.effectiveDate() << "to" << cert.expiryDate(); return false; } QSslSocket::addDefaultCaCertificate(cert); return true; }
int main(int argc , char *argv[]) { char rline[MAXLINE], my_msg[MAXLINE]; //char *start = "Connected to server\n"; int i, j, n; int s, client_fd, client; fd_set read_fds; struct sockaddr_in server_addr; struct sockaddr_in proxy_addr; struct sockaddr_in client_addr; struct __message rcv = { 0x0, }; struct __message trans = { 0x0, }; pthread_mutex_init(&m_lock, NULL); if(argc < 4) { printf("usage : %s [proxy_port#] [server_ip#] [server_port#] [cache_mode#] [cache_algorithm#]\n", argv[0]); exit(0); } //if(argc else if(argc < 6) { g_uiCacheMode = 0; g_uiCacheAlgorithm = 0; } else { g_uiCacheMode = atoi(argv[4]); g_uiCacheAlgorithm = atoi(argv[5]); } //TODO: init timer handler //initTimerHandler(); //TODO: init cached resource struct initResource(); //TODO: init server connection bzero((char *)&proxy_addr, sizeof(struct sockaddr_in)); server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr = inet_addr(argv[2]); server_addr.sin_port = htons(atoi(argv[3])); initServerConnection(server_addr); if((s = socket(PF_INET, SOCK_STREAM, 0)) < 0) { printf("proxy : socket failed!\n"); exit(0); } //if((s = socket /* struct timeval tNow; gettimeofday(&tNow, NULL); addObserver1(200, 2, 1000, 800, tNow); usleep(10*1000); gettimeofday(&tNow, NULL); addObserver1(300, 3, 1000, 2000, tNow); usleep(25*1000); gettimeofday(&tNow, NULL); addObserver1(100, 1, 1000, 400, tNow); //dumpObserver(); //dumpObserver(); dumpObserver(); return;//while(1); */ //TODO: init proxy connection int option = 1; setsockopt( s, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(int) ); bzero((char *)&proxy_addr, sizeof(struct sockaddr_in)); proxy_addr.sin_family = AF_INET; proxy_addr.sin_addr.s_addr = htonl(INADDR_ANY); proxy_addr.sin_port = htons(atoi(argv[1])); if(bind(s, (struct sockaddr *)&proxy_addr, sizeof(struct sockaddr_in)) < 0) { printf("proxy : bind failed!\n"); exit(0); } listen(s, 5); g_piFdMax = s + 1; pthread_t threadId = 0; pthread_create(&threadId, NULL, pthreadWatchResource, (void *)NULL); sprintf(g_strProxyLog, "/tmp/proxy_%d.log", (int)getpid()); while(1) { FD_ZERO(&read_fds); FD_SET(s, &read_fds); for(i=0; i<g_iClientMax; i++) { FD_SET(g_piSocketClient[i], &read_fds); } //for(i=0; g_piFdMax = getFdMax(s) + 1; if(select(g_piFdMax, &read_fds, (fd_set *)0, (fd_set *)0, (struct timeval *)0) < 0) { printf("proxy : select failed\n"); exit(0); }//if(select if(FD_ISSET(s, &read_fds)) { client = sizeof(struct sockaddr_in); client_fd = accept(s, (struct sockaddr *)&client_addr, &client); if(client_fd == -1) { printf("proxy : accept failed!\n"); exit(0); } g_piSocketClient[g_iClientMax] = client_fd; g_iClientMax++; //printf("client_fd=%d, g_iClientMax=%d\n", client_fd, g_iClientMax); //send(client_fd, start, strlen(start), 0); printf("proxy : user#%d added!\n", g_iClientMax); }//if(FD_ISSET for(i=0; i<g_iClientMax; i++) { if(FD_ISSET(g_piSocketClient[i], &read_fds)) { memset(&rcv, 0x0, sizeof(struct __message)); if((n = recv(g_piSocketClient[i], &rcv, sizeof(struct __message), 0)) <= 0) { removeObserver(g_piSocketClient[i]); dumpObserver(); removeClient(i); continue; } if(rcv.cmd == 0x99999999) { removeClient(i); continue; } #if ENABLE_HANDLETHREAD struct timeval timeRecv; gettimeofday(&timeRecv, NULL); rcv.proxy_recved.tv_sec = timeRecv.tv_sec; rcv.proxy_recved.tv_usec = timeRecv.tv_usec; pthread_t ptId = 0; rcv.iFd = g_piSocketClient[i]; pthread_create(&ptId, NULL, pthreadHandleMessage, (void *)&rcv); //usleep(1); #else handleMessage(&rcv); memcpy(&trans, &rcv, sizeof(struct __message)); int temp = send(g_piSocketClient[i], &trans, sizeof(struct __message), 0); #endif } //if(FD_ISSET( } //for(i=0 } //while(1) return 0; }
int mal_init(void){ #ifdef NEED_MT_LOCK_INIT MT_lock_init( &mal_contextLock, "mal_contextLock"); MT_lock_init( &mal_namespaceLock, "mal_namespaceLock"); MT_lock_init( &mal_remoteLock, "mal_remoteLock"); MT_lock_init( &mal_profileLock, "mal_profileLock"); MT_lock_init( &mal_copyLock, "mal_copyLock"); MT_lock_init( &mal_delayLock, "mal_delayLock"); #endif /* "/2" is arbitrarily used / chosen, as on systems with * hyper-threading enabled, using all hardware threads rather than * "only" all physical cores does not necessarily yield a linear * performance benefit */ MT_sema_init( &mal_parallelism, (GDKnr_threads > 1 ? GDKnr_threads/2: 1), "mal_parallelism"); tstAligned(); MCinit(); if (mdbInit()) return -1; if (monet_memory == 0) monet_memory = MT_npages() * MT_pagesize(); initNamespace(); initParser(); initHeartbeat(); initResource(); #ifdef HAVE_JSONSTORE startHttpdaemon(); #endif RECYCLEinit(); if( malBootstrap() == 0) return -1; /* set up the profiler if needed, output sent to console */ /* Use the same shortcuts as stethoscope */ if ( mal_trace && *mal_trace) { char *s; setFilterAll(); openProfilerStream(mal_clients[0].fdout); for ( s= mal_trace; *s; s++) switch(*s){ case 'a': activateCounter("aggregate");break; case 'b': activateCounter("rbytes"); activateCounter("wbytes");break; case 'c': activateCounter("cpu");break; case 'e': activateCounter("event");break; case 'f': activateCounter("function");break; case 'i': activateCounter("pc");break; case 'm': activateCounter("memory");break; case 'p': activateCounter("process");break; case 'r': activateCounter("reads");break; case 's': activateCounter("stmt");break; case 't': activateCounter("ticks");break; case 'u': activateCounter("user");break; case 'w': activateCounter("writes");break; case 'y': activateCounter("type");break; case 'D': activateCounter("dot");break; case 'I': activateCounter("thread");break; case 'T': activateCounter("time");break; case 'S': activateCounter("start"); } startProfiling(); } else mal_trace =0; return 0; }