bool GroupDavGlobals::interpretAddressBookDownloadItemsJob( KABC::AddressBookAdaptor *adaptor, KIO::Job *job, const QString &jobData) { kdDebug(5800) << "GroupDavGlobals::interpretAddressBookDownloadItemsJob, vCard=" << endl; kdDebug(5800) << jobData << endl; if(!adaptor || !job) return false; KABC::VCardConverter conv; KABC::Addressee::List addrs(conv.parseVCards(jobData)); if(addrs.count() != 1) { kdError() << "Parsed vCard does not contain exactly one addressee." << endl; return false; } KABC::Addressee a = addrs.first(); KIO::SimpleJob *sjob = dynamic_cast<KIO::SimpleJob *>(job); KURL remoteId; if(sjob) remoteId = sjob->url(); QString fingerprint = extractFingerprint(job, jobData); adaptor->addressbookItemDownloaded(a, a.uid(), remoteId, fingerprint, remoteId.prettyURL()); return true; }
int main(int argc, char* argv[]) { int ch, cocurrent = 10; bool sync_check = false; acl::string addrs("www.sina.com.cn:80;www.263.net:80;www.qq.com:81"); acl::string proto("pop3"); // 初始化 acl 库 acl::acl_cpp_init(); // 日志输出至标准输出 acl::log::stdout_open(true); while ((ch = getopt(argc, argv, "hs:n:c:SP:")) > 0) { switch (ch) { case 'h': usage(argv[0]); return 0; case 's': addrs = optarg; break; case 'c': cocurrent = atoi(optarg); break; case 'n': __loop_count = atoi(optarg); break; case 'S': sync_check = true; break; case 'P': proto = optarg; break; default: usage(argv[0]); return 0; } } init(addrs, cocurrent, sync_check, proto); run(cocurrent); end(); #ifdef WIN32 printf("enter any key to exit...\r\n"); getchar(); #endif return 0; }
int main(const std::vector<std::string>& args) { InitPhone4sHeaderTmpl(); HtmlHelper::InitUrls(); PluginMgr::Current()->LoadPlugin(); if(this->config().has("ticket.watermark")) { Ticket::EXPIRE_WATER_MARK=this->config().getInt("ticket.watermark",2); } SiriTokenProvider::InitCache(); if (_helpRequested) { displayHelp(); } else { unsigned short port = (unsigned short) config().getInt("HttpSvr.port", 7777); string ipv4v6=config().getString("HttpSvr.IPv4v6"); uri_encrypt_token=config().getString("HttpSvr.admin.encrypt"); uri_encrypt_token=Poco::toLower(uri_encrypt_token); SocketAddress addrs(ipv4v6,port); ServerSocket ssock(addrs); HTTPServerParams *prams=new HTTPServerParams(); prams->setKeepAlive(true); HTTPServer httpsrv(new RequestHandlerFactoryImpl(),ssock,prams); httpsrv.start(); Poco::Logger& logger=this->logger(); logger.information(format("http服务器已经启动,绑定地址:%s,绑定端口:%d",ipv4v6,(int)port)); logger.information(format("http服务器管理地址为http://%s:%d/admin/%s/index.html",ipv4v6,(int)port,uri_encrypt_token)); RunAsTcpSvr(); httpsrv.stop(); } return Application::EXIT_OK; }
int main(int argc, char* argv[]) { int ch, n = 1, conn_timeout = 10, rw_timeout = 10; int max_threads = 10, nsleep = 500, nretry = 10; acl::string addrs("127.0.0.1:6379"), cmd; bool preset = false; while ((ch = getopt(argc, argv, "hs:n:C:I:c:a:w:r:p")) > 0) { switch (ch) { case 'h': usage(argv[0]); return 0; case 's': addrs = optarg; break; case 'n': n = atoi(optarg); break; case 'C': conn_timeout = atoi(optarg); break; case 'I': rw_timeout = atoi(optarg); break; case 'c': max_threads = atoi(optarg); break; case 'a': cmd = optarg; break; case 'w': nsleep = atoi(optarg); break; case 'r': nretry = atoi(optarg); break; case 'p': preset = true; break; default: break; } } acl::acl_cpp_init(); acl::log::stdout_open(true); acl::redis_client_cluster cluster(conn_timeout, rw_timeout); // 当某个连接池结点出问题,设置探测该连接结点是否恢复的时间间隔(秒),当该值 // 为 0 时,则不检测 cluster.set_retry_inter(1); // 设置重定向的最大阀值,若重定向次数超过此阀值则报错 cluster.set_redirect_max(nretry); // 当重定向次数 >= 2 时每次再重定向此函数设置休息的时间(毫秒) cluster.set_redirect_sleep(nsleep); cluster.init(NULL, addrs.c_str(), max_threads); // 是否需要将所有哈希槽的对应关系提前设置好,这样可以去掉运行时动态添加 // 哈希槽的过程,从而可以提高运行时的效率 if (preset) { const std::vector<acl::string>& token = addrs.split2(",; \t"); cluster.set_all_slot(token[0], max_threads); } struct timeval begin; gettimeofday(&begin, NULL); acl::locker locker; std::vector<test_thread*> threads; for (int i = 0; i < max_threads; i++) { test_thread* thread = new test_thread(locker, cluster, max_threads, cmd.c_str(), n); threads.push_back(thread); thread->set_detachable(true); thread->start(); } while (true) { locker.lock(); if (__threads_exit == max_threads) { locker.unlock(); printf("All threads over now!\r\n"); break; } locker.unlock(); //printf("max_threads: %d, threads_exit: %d\r\n", // max_threads, __threads_exit); sleep(1); } std::vector<test_thread*>::iterator it = threads.begin(); for (; it != threads.end(); ++it) { //(*it)->wait(); delete (*it); } struct timeval end; gettimeofday(&end, NULL); long long int total = max_threads * n; double inter = util::stamp_sub(&end, &begin); printf("total %s: %lld, spent: %0.2f ms, speed: %0.2f\r\n", cmd.c_str(), total, inter, (total * 1000) /(inter > 0 ? inter : 1)); #ifdef WIN32 printf("enter any key to exit\r\n"); getchar(); #endif return 0; }
int main(int argc, char* argv[]) { int ch, n = 1, conn_timeout = 10, rw_timeout = 10; int max_threads = 10; acl::disque_cond cond; acl::string addrs("127.0.0.1:7711,127.0.0.1:7712,127.0.0.1:7713"), cmd; while ((ch = getopt(argc, argv, "hs:n:C:I:c:a:D:R:r:T:M:A")) > 0) { switch (ch) { case 'h': usage(argv[0]); return 0; case 's': addrs = optarg; break; case 'n': n = atoi(optarg); break; case 'C': conn_timeout = atoi(optarg); break; case 'I': rw_timeout = atoi(optarg); break; case 'c': max_threads = atoi(optarg); break; case 'a': cmd = optarg; break; case 'D': cond.set_delay(atoi(optarg)); break; case 'R': cond.set_replicate(atoi(optarg)); break; case 'r': cond.set_retry(atoi(optarg)); break; case 'T': cond.set_ttl(atoi(optarg)); break; case 'M': cond.set_maxlen(atoi(optarg)); break; case 'A': cond.set_async(true); break; default: break; } } acl::acl_cpp_init(); acl::disque_client_cluster cluster(conn_timeout, rw_timeout); const std::vector<acl::string>& tokens = addrs.split2(",; \t"); std::vector<acl::string>::const_iterator cit; for (cit = tokens.begin(); cit != tokens.end(); ++cit) { printf("add disque-server: %s\r\n", (*cit).c_str()); cluster.set((*cit).c_str(), max_threads); } std::vector<test_thread*> threads; for (int i = 0; i < max_threads; i++) { test_thread* thread = new test_thread(cluster, cond, cmd.c_str(), n); threads.push_back(thread); thread->set_detachable(false); thread->start(); } std::vector<test_thread*>::iterator it = threads.begin(); for (; it != threads.end(); ++it) { (*it)->wait(); delete (*it); } #ifdef WIN32 printf("enter any key to exit\r\n"); getchar(); #endif return 0; }
static bool makerooms(void) { struct rectangle *rsp; int lx, ly, hx, hy, lowx, lowy, hix, hiy, dx, dy; int tryct = 0, xlim, ylim; /* init */ xlim = XLIM + secret; ylim = YLIM + secret; if(nroom == 0) { rsp = rs; rsp->rlx = rsp->rly = 0; rsp->rhx = COLNO-1; rsp->rhy = ROWNO-1; rsmax = 1; } rscnt = rsmax; /* make rooms until satisfied */ while(rscnt > 0 && nroom < MAXNROFROOMS-1) { if(!secret && nroom > (MAXNROFROOMS/3) && !rn2((MAXNROFROOMS-nroom)*(MAXNROFROOMS-nroom))) return(0); /* pick a rectangle */ rsp = &rs[rn2(rscnt)]; hx = rsp->rhx; hy = rsp->rhy; lx = rsp->rlx; ly = rsp->rly; /* find size of room */ if(secret) dx = dy = 1; else { dx = 2 + rn2((hx-lx-8 > 20) ? 12 : 8); dy = 2 + rn2(4); if(dx*dy > 50) dy = 50/dx; } /* look whether our room will fit */ if(hx-lx < dx + dx/2 + 2*xlim || hy-ly < dy + dy/3 + 2*ylim) { /* no, too small */ /* maybe we throw this area out */ if(secret || !rn2(MAXNROFROOMS+1-nroom-tryct)) { rscnt--; rs[rsmax] = *rsp; *rsp = rs[rscnt]; rs[rscnt] = rs[rsmax]; tryct = 0; } else tryct++; continue; } lowx = lx + xlim + rn2(hx - lx - dx - 2*xlim + 1); lowy = ly + ylim + rn2(hy - ly - dy - 2*ylim + 1); hix = lowx + dx; hiy = lowy + dy; if(maker(lowx, dx, lowy, dy)) { if(secret) return(1); addrs(lowx-1, lowy-1, hix+1, hiy+1); tryct = 0; } else if(tryct++ > 100) break; } return(0); /* failed to make vault - very strange */ }
naming::gid_type const& destination_locality() const { return addrs()[0].locality_; }
bool NetworkManager::start(bool isServer, Ogre::ushort serverPort, Ogre::String serverIP) { mServer = isServer; RakNet::Time waitTime = 10000; RakNet::Time prevTime = 0; if(isServer) { Ogre::LogManager::getSingletonPtr() ->logMessage(RealToys::logMessagePrefix + "Starting network as " + "server on port " + Ogre::StringConverter::toString(serverPort) ); } else { Ogre::LogManager::getSingletonPtr() ->logMessage(RealToys::logMessagePrefix + "Starting network as " + "client to server " + serverIP + " on port " + Ogre::StringConverter::toString(serverPort) ); } mAirplaneManager = AirplaneManager::getSingletonPtr(); upAndRunning = false; mConnectAtemp = false; mWaitForPong = false; RakNet::SocketDescriptor sd; mRakPeer = RakNet::RakPeerInterface::GetInstance(); if(isServer) { sd.port = serverPort; mReplicaManager = RT_ReplicaManager(mSceneMgr, mWorld); } else { sd.port = 0; mReplicaManager = RT_ReplicaManager(mSceneMgr); } mReplicaManager.SetDefaultPacketReliability(UNRELIABLE_SEQUENCED); mReplicaManager.SetDefaultPacketPriority(HIGH_PRIORITY); // The network ID authority is the system that creates the common numerical identifier used to lookup pointers (the server here). //mNetworkIdManager.SetIsNetworkIDAuthority(isServer); // ObjectMemberRPC, AutoRPC for objects, and ReplicaManager3 require that you call SetNetworkIDManager() mReplicaManager.SetNetworkIDManager(&mNetworkIdManager); // Setup RPC3 system and classes //mRPCIdManager.SetIsNetworkIDAuthority(true); mRPC3Inst.SetNetworkIDManager(&mRPCIdManager); this->SetNetworkIDManager(&mRPCIdManager); RakNet::NetworkID id0 = 0; this->SetNetworkID(id0); RPC3_REGISTER_FUNCTION(&mRPC3Inst, &NetworkManager::createAirplane); RPC3_REGISTER_FUNCTION(&mRPC3Inst, &NetworkManager::processAirplaneInput); // Start RakNet, up to 32 connections if the server if(!doStartup(isServer, sd)) { return false; } mRakPeer->AttachPlugin(&mReplicaManager); mRakPeer->AttachPlugin(&mRPC3Inst); mNetworkID = mRakPeer->GetGuidFromSystemAddress(RakNet::UNASSIGNED_SYSTEM_ADDRESS); // The server should allow systems to connect. Clients do not need to unless we want to transmit messages directly between systems or to use RakVoice if (isServer) { // mRakPeer->SetMaximumIncomingConnections(RealToys::maxClients-1); mRakPeer->SetMaximumIncomingConnections(0); //will not accept connections until setCurrentMap is called //mNetworkID = RealToys::serverPlayerID; } else { if(serverIP == "255.255.255.255") { if(mRakPeer->Ping( serverIP.c_str(), serverPort, true, 0 ) ) { Ogre::LogManager::getSingletonPtr() ->logMessage(RealToys::logMessagePrefix + "Client will try to search for servers on LAN"); mWaitForPong = true; } else { Ogre::LogManager::getSingletonPtr() ->logMessage(RealToys::logMessagePrefix + "Client PING failed"); return false; } } else { if(!doConnect(serverIP, serverPort)) { return false; } } } mIsStarted = true; if(isServer) { upAndRunning = true; } else { Ogre::LogManager::getSingletonPtr() ->logMessage(RealToys::logMessagePrefix + "Trying to connect to server" ); //"update" until receives a package saying if it was a successful connection or not prevTime = RakNet::GetTime(); while(!upAndRunning && (mConnectAtemp || mWaitForPong) && waitTime > 0) { update(); waitTime-=(RakNet::GetTime()-prevTime); prevTime = RakNet::GetTime(); } } if(upAndRunning) { mAirplaneManager->setPlayerID(mNetworkID); ScoresManager::getSingletonPtr()->setLocalSysAddress(mNetworkID); Ogre::String addrs( mNetworkID.ToString() ); if(mServer) addrs += " (server)"; Ogre::LogManager::getSingletonPtr() ->logMessage(RealToys::logMessagePrefix + "Network started " + addrs); } else { Ogre::LogManager::getSingletonPtr() ->logMessage(RealToys::logMessagePrefix + "Network failed to start" ); } return upAndRunning; }
//FIXME: This code could be greatly improved/simplifyied with // http://cairo.sourcearchive.com/documentation/1.9.4/backtrace-symbols_8c-source.html std::vector<std::string> resolveBacktrace( xbt_backtrace_location_t const* loc, std::size_t count) { std::vector<std::string> result; if (count == 0) return result; if (xbt_binary_name == nullptr) XBT_WARN("XBT not initialized, the backtrace will not be resolved."); // Drop the first one: loc++; count--; char** backtrace_syms = backtrace_symbols(loc, count); std::string binary_name = get_binary_path(); if (binary_name.empty()) { for (std::size_t i = 0; i < count; i++) result.push_back(simgrid::xbt::string_printf("%p", loc[i])); return std::move(result); } // Create the system command for add2line: std::ostringstream stream; stream << ADDR2LINE << " -f -e " << binary_name << ' '; std::vector<std::string> addrs(count); for (std::size_t i = 0; i < count; i++) { /* retrieve this address */ XBT_DEBUG("Retrieving address number %zd from '%s'", i, backtrace_syms[i]); char buff[256]; snprintf(buff, 256, "%s", strchr(backtrace_syms[i], '[') + 1); char* p = strchr(buff, ']'); *p = '\0'; if (strcmp(buff, "(nil)")) addrs[i] = buff; else addrs[i] = "0x0"; XBT_DEBUG("Set up a new address: %zd, '%s'", i, addrs[i].c_str()); /* Add it to the command line args */ stream << addrs[i] << ' '; } std::string cmd = stream.str(); /* size (in char) of pointers on this arch */ int addr_len = addrs[0].size(); XBT_VERB("Fire a first command: '%s'", cmd.c_str()); FILE* pipe = popen(cmd.c_str(), "r"); if (!pipe) { xbt_die("Cannot fork addr2line to display the backtrace"); } /* To read the output of addr2line */ char line_func[1024], line_pos[1024]; for (std::size_t i = 0; i < count; i++) { XBT_DEBUG("Looking for symbol %zd, addr = '%s'", i, addrs[i].c_str()); if (fgets(line_func, 1024, pipe)) { line_func[strlen(line_func) - 1] = '\0'; } else { XBT_VERB("Cannot run fgets to look for symbol %zd, addr %s", i, addrs[i].c_str()); strncpy(line_func, "???",3); } if (fgets(line_pos, 1024, pipe)) { line_pos[strlen(line_pos) - 1] = '\0'; } else { XBT_VERB("Cannot run fgets to look for symbol %zd, addr %s", i, addrs[i].c_str()); strncpy(line_pos, backtrace_syms[i],1024); } if (strcmp("??", line_func) != 0) { auto name = simgrid::xbt::demangle(line_func); XBT_DEBUG("Found static symbol %s at %s", name.get(), line_pos); result.push_back(simgrid::xbt::string_printf( "%s at %s, %p", name.get(), line_pos, loc[i] )); } else { /* Damn. The symbol is in a dynamic library. Let's get wild */ char maps_buff[512]; long int offset = 0; char *p, *p2; int found = 0; /* let's look for the offset of this library in our addressing space */ char* maps_name = bprintf("/proc/%d/maps", (int) getpid()); FILE* maps = fopen(maps_name, "r"); long int addr = strtol(addrs[i].c_str(), &p, 16); if (*p != '\0') { XBT_CRITICAL("Cannot parse backtrace address '%s' (addr=%#lx)", addrs[i].c_str(), addr); } XBT_DEBUG("addr=%s (as string) =%#lx (as number)", addrs[i].c_str(), addr); while (!found) { long int first, last; if (fgets(maps_buff, 512, maps) == nullptr) break; if (i == 0) { maps_buff[strlen(maps_buff) - 1] = '\0'; XBT_DEBUG("map line: %s", maps_buff); } sscanf(maps_buff, "%lx", &first); p = strchr(maps_buff, '-') + 1; sscanf(p, "%lx", &last); if (first < addr && addr < last) { offset = first; found = 1; } if (found) { XBT_DEBUG("%#lx in [%#lx-%#lx]", addr, first, last); XBT_DEBUG("Symbol found, map lines not further displayed (even if looking for next ones)"); } } fclose(maps); free(maps_name); addrs[i].clear(); if (!found) { XBT_VERB("Problem while reading the maps file. Following backtrace will be mangled."); XBT_DEBUG("No dynamic. Static symbol: %s", backtrace_syms[i]); result.push_back(simgrid::xbt::string_printf("?? (%s)", backtrace_syms[i])); continue; } /* Ok, Found the offset of the maps line containing the searched symbol. We now need to substract this from the address we got from backtrace. */ addrs[i] = simgrid::xbt::string_printf("0x%0*lx", addr_len - 2, addr - offset); XBT_DEBUG("offset=%#lx new addr=%s", offset, addrs[i].c_str()); /* Got it. We have our new address. Let's get the library path and we are set */ p = xbt_strdup(backtrace_syms[i]); if (p[0] == '[') { /* library path not displayed in the map file either... */ free(p); snprintf(line_func,3, "??"); } else { p2 = strrchr(p, '('); if (p2) *p2 = '\0'; p2 = strrchr(p, ' '); if (p2) *p2 = '\0'; /* Here we go, fire an addr2line up */ char* subcmd = bprintf("%s -f -e %s %s", ADDR2LINE, p, addrs[i].c_str()); free(p); XBT_VERB("Fire a new command: '%s'", subcmd); FILE* subpipe = popen(subcmd, "r"); if (!subpipe) { xbt_die("Cannot fork addr2line to display the backtrace"); } if (fgets(line_func, 1024, subpipe)) { line_func[strlen(line_func) - 1] = '\0'; } else { XBT_VERB("Cannot read result of subcommand %s", subcmd); strncpy(line_func, "???",3); } if (fgets(line_pos, 1024, subpipe)) { line_pos[strlen(line_pos) - 1] = '\0'; } else { XBT_VERB("Cannot read result of subcommand %s", subcmd); strncpy(line_pos, backtrace_syms[i],1024); } pclose(subpipe); free(subcmd); } /* check whether the trick worked */ if (strcmp("??", line_func)) { auto name = simgrid::xbt::demangle(line_func); XBT_DEBUG("Found dynamic symbol %s at %s", name.get(), line_pos); result.push_back(simgrid::xbt::string_printf( "%s at %s, %p", name.get(), line_pos, loc[i])); } else { /* damn, nothing to do here. Let's print the raw address */ XBT_DEBUG("Dynamic symbol not found. Raw address = %s", backtrace_syms[i]); result.push_back(simgrid::xbt::string_printf( "?? at %s", backtrace_syms[i])); } } addrs[i].clear(); /* Mask the bottom of the stack */ if (!strncmp("main", line_func, strlen("main")) || !strncmp("xbt_thread_context_wrapper", line_func, strlen("xbt_thread_context_wrapper")) || !strncmp("smx_ctx_sysv_wrapper", line_func, strlen("smx_ctx_sysv_wrapper"))) break; } pclose(pipe); free(backtrace_syms); return result; }