BookmarkItem* IeImporter::importBookmarks() { BookmarkItem* root = new BookmarkItem(BookmarkItem::Folder); root->setTitle("Internet Explorer Import"); foreach (QFileInfo file, urls) { QSettings urlFile(file.absoluteFilePath(), QSettings::IniFormat, this); QUrl url = urlFile.value("InternetShortcut/URL").toUrl(); BookmarkItem* b = new BookmarkItem(BookmarkItem::Url, root); b->setTitle(file.baseName()); b->setUrl(url); }
int main(int argc, char *argv[]) { std::priority_queue<MyUrl> downloadQueue;//设置待下载队列 std::ifstream urlFile("url.txt");//打开种子url文件 std::string urlStream,urlsStream; std::string tmpHtmlFile = "out.html";//临时存储下载html文件 while(!urlFile.eof()) { urlStream.clear(); urlFile>>urlStream; urlsStream.append(urlStream); urlsStream.append("\r\n"); } if(urlFile.is_open()) urlFile.close(); PaserUrl paser(tmpHtmlFile); //paser.getUrl(downloadQueue); /*DownloadUrl download; download.init();*/ MyUrl tmpUrl("http://www.baidu.com",1); downloadQueue.push(tmpUrl); tmpUrl.setUrl("http://www.csdn.com"); downloadQueue.push(tmpUrl); tmpUrl.setUrl("http://www.bing.com"); downloadQueue.push(tmpUrl); curl_global_init(CURL_GLOBAL_WIN32); while(!downloadQueue.empty()) { DownloadUrl download(downloadQueue.top(),tmpHtmlFile); paser = PaserUrl(tmpHtmlFile,downloadQueue.top()); download.init(); //download = downloadQueue.top();//获取优先级最高的url download.run(); downloadQueue.pop(); paser.parser(download.htmlData(),downloadQueue);//从返回的html文件中筛选出URL,并将其加入到待下载队列 std::cout<<paser.getTitle()<<std::endl; std::cout<<paser.getContent()<<std::endl; } //QApplication a(argc, argv); //MainWindow w; //w.show(); curl_global_cleanup(); //return a.exec(); system("pause"); }
QVector<Bookmarks::Bookmark> IeImporter::exportBookmarks() { QVector<Bookmarks::Bookmark> bookmarks; foreach (QFileInfo file, urls) { QSettings urlFile(file.absoluteFilePath(), QSettings::IniFormat, this); QUrl url = urlFile.value("InternetShortcut/URL").toUrl(); Bookmarks::Bookmark bookmark; bookmark.folder = "Internet Explorer Import"; bookmark.title = file.baseName(); bookmark.url = url; bookmarks.append(bookmark); }
bool DVDPlayerCodec::Init(const CStdString &strFile, unsigned int filecache) { m_decoded = NULL;; m_nDecodedLen = 0; CStdString strFileToOpen = strFile; CURL urlFile(strFile); if (urlFile.GetProtocol() == "shout" ) strFileToOpen.Replace("shout://","http://"); m_pInputStream = CDVDFactoryInputStream::CreateInputStream(NULL, strFileToOpen, m_strContentType); if (!m_pInputStream) { CLog::Log(LOGERROR, "%s: Error creating input stream for %s", __FUNCTION__, strFileToOpen.c_str()); return false; } if (!m_pInputStream->Open(strFileToOpen.c_str(), m_strContentType)) { CLog::Log(LOGERROR, "%s: Error opening file %s", __FUNCTION__, strFileToOpen.c_str()); if (m_pInputStream) delete m_pInputStream; m_pInputStream = NULL; return false; } m_pDemuxer = NULL; try { m_pDemuxer = CDVDFactoryDemuxer::CreateDemuxer(m_pInputStream); if (!m_pDemuxer) { delete m_pInputStream; m_pInputStream = NULL; CLog::Log(LOGERROR, "%s: Error creating demuxer", __FUNCTION__); return false; } } catch(...) { CLog::Log(LOGERROR, "%s: Exception thrown when opeing demuxer", __FUNCTION__); if (m_pDemuxer) { delete m_pDemuxer; m_pDemuxer = NULL; } delete m_pInputStream; m_pInputStream = NULL; return false; } CDemuxStream* pStream = NULL; m_nAudioStream = -1; for (int i = 0; i < m_pDemuxer->GetNrOfStreams(); i++) { pStream = m_pDemuxer->GetStream(i); if (pStream && pStream->type == STREAM_AUDIO) { m_nAudioStream = i; break; } } if (m_nAudioStream == -1) { CLog::Log(LOGERROR, "%s: Could not find audio stream", __FUNCTION__); delete m_pDemuxer; m_pDemuxer = NULL; delete m_pInputStream; m_pInputStream = NULL; return false; } CDVDStreamInfo hint(*pStream, true); bool passthrough = AUDIO_IS_BITSTREAM(g_guiSettings.GetInt("audiooutput.mode")); m_pAudioCodec = CDVDFactoryCodec::CreateAudioCodec(hint, passthrough); if (!m_pAudioCodec) { CLog::Log(LOGERROR, "%s: Could not create audio codec", __FUNCTION__); delete m_pDemuxer; m_pDemuxer = NULL; delete m_pInputStream; m_pInputStream = NULL; return false; } // we have to decode initial data in order to get channels/samplerate // for sanity - we read no more than 10 packets int nErrors = 0; for (int nPacket=0; nPacket < 10 && (m_Channels == 0 || m_SampleRate == 0); nPacket++) { BYTE dummy[256]; int nSize = 256; if (ReadPCM(dummy, nSize, &nSize) == READ_ERROR) ++nErrors; m_DataFormat = m_pAudioCodec->GetDataFormat(); m_BitsPerSample = CAEUtil::DataFormatToBits(m_DataFormat); m_SampleRate = m_pAudioCodec->GetSampleRate(); m_EncodedSampleRate = m_pAudioCodec->GetEncodedSampleRate(); m_Channels = m_pAudioCodec->GetChannels(); m_ChannelInfo = m_pAudioCodec->GetChannelMap(); } if (nErrors >= 10) { CLog::Log(LOGDEBUG, "%s: Could not decode data", __FUNCTION__); return false; } m_nDecodedLen = 0; if (m_Channels == 0) // no data - just guess and hope for the best m_Channels = 2; if (m_SampleRate == 0) m_SampleRate = 44100; m_TotalTime = m_pDemuxer->GetStreamLength(); m_Bitrate = m_pAudioCodec->GetBitRate(); m_pDemuxer->GetStreamCodecName(m_nAudioStream,m_CodecName); return true; }
//#define DEBUG bool CFlashUpdate::selectHttpImage(void) { CHTTPTool httpTool; std::string url; std::string name; std::string version; std::string md5; std::vector<std::string> updates_lists, urls, names, versions, descriptions, md5s; char fileTypes[128]; int selected = -1; httpTool.setStatusViewer(this); showStatusMessageUTF(g_Locale->getText(LOCALE_FLASHUPDATE_GETINFOFILE)); // UTF-8 CMenuWidget SelectionWidget(LOCALE_FLASHUPDATE_SELECTIMAGE, "softupdate.raw", 600); SelectionWidget.addItem(GenericMenuSeparator); SelectionWidget.addItem(GenericMenuBack); std::ifstream urlFile(g_settings.softupdate_url_file); #ifdef DEBUG printf("[update] file %s\n", g_settings.softupdate_url_file); #endif unsigned int i = 0; while (urlFile >> url) { std::string::size_type startpos, endpos; #ifdef DEBUG printf("[update] url %s\n", url.c_str()); #endif /* extract domain name */ startpos = url.find("//"); if (startpos == std::string::npos) { startpos = 0; endpos = std::string::npos; updates_lists.push_back(url.substr(startpos, endpos - startpos)); } else { //startpos += 2; //endpos = url.find('/', startpos); startpos = url.find('/', startpos+2)+1; endpos = std::string::npos; updates_lists.push_back(url.substr(startpos, endpos - startpos)); } //updates_lists.push_back(url.substr(startpos, endpos - startpos)); SelectionWidget.addItem(new CNonLocalizedMenuSeparator(updates_lists.rbegin()->c_str(), LOCALE_FLASHUPDATE_SELECTIMAGE)); if (httpTool.downloadFile(url, gTmpPath LIST_OF_UPDATES_LOCAL_FILENAME, 20)) { std::ifstream in(gTmpPath LIST_OF_UPDATES_LOCAL_FILENAME); bool enabled; while (in >> url >> version >> md5 >> std::ws) { urls.push_back(url); versions.push_back(version); std::getline(in, name); names.push_back(name); //std::getline(in, md5); md5s.push_back(md5); enabled = true; #ifdef DEBUG printf("[update] url %s version %s md5 %s name %s\n", url.c_str(), version.c_str(), md5.c_str(), name.c_str()); #endif CFlashVersionInfo versionInfo(versions[i]); if(!allow_flash && (versionInfo.snapshot < '3')) enabled = false; fileTypes[i] = versionInfo.snapshot; std::string description = versionInfo.getType(); description += ' '; description += versionInfo.getDate(); description += ' '; description += versionInfo.getTime(); descriptions.push_back(description); /* workaround since CMenuForwarder does not store the Option String itself */ SelectionWidget.addItem(new CMenuForwarderNonLocalized(names[i].c_str(), enabled, descriptions[i].c_str(), new CUpdateMenuTarget(i, &selected))); i++; } } }
bool DVDPlayerCodec::Init(const CStdString &strFile, unsigned int filecache) { // take precaution if Init()ialized earlier if (m_bInited) { // keep things as is if Init() was done with known strFile if (m_strFileName == strFile) return true; // got differing filename, so cleanup before starting over DeInit(); } m_decoded = NULL; m_nDecodedLen = 0; CStdString strFileToOpen = strFile; CURL urlFile(strFile); if (urlFile.GetProtocol() == "shout" ) strFileToOpen.replace(0, 8, "http://"); m_pInputStream = CDVDFactoryInputStream::CreateInputStream(NULL, strFileToOpen, m_strContentType); if (!m_pInputStream) { CLog::Log(LOGERROR, "%s: Error creating input stream for %s", __FUNCTION__, strFileToOpen.c_str()); return false; } if (!m_pInputStream->Open(strFileToOpen.c_str(), m_strContentType)) { CLog::Log(LOGERROR, "%s: Error opening file %s", __FUNCTION__, strFileToOpen.c_str()); if (m_pInputStream) delete m_pInputStream; m_pInputStream = NULL; return false; } m_pDemuxer = NULL; try { m_pDemuxer = CDVDFactoryDemuxer::CreateDemuxer(m_pInputStream); if (!m_pDemuxer) { delete m_pInputStream; m_pInputStream = NULL; CLog::Log(LOGERROR, "%s: Error creating demuxer", __FUNCTION__); return false; } } catch(...) { CLog::Log(LOGERROR, "%s: Exception thrown when opening demuxer", __FUNCTION__); if (m_pDemuxer) { delete m_pDemuxer; m_pDemuxer = NULL; } delete m_pInputStream; m_pInputStream = NULL; return false; } CDemuxStream* pStream = NULL; m_nAudioStream = -1; for (int i = 0; i < m_pDemuxer->GetNrOfStreams(); i++) { pStream = m_pDemuxer->GetStream(i); if (pStream && pStream->type == STREAM_AUDIO) { m_nAudioStream = i; break; } } if (m_nAudioStream == -1) { CLog::Log(LOGERROR, "%s: Could not find audio stream", __FUNCTION__); delete m_pDemuxer; m_pDemuxer = NULL; delete m_pInputStream; m_pInputStream = NULL; return false; } CDVDStreamInfo hint(*pStream, true); m_pAudioCodec = CDVDFactoryCodec::CreateAudioCodec(hint); if (!m_pAudioCodec) { CLog::Log(LOGERROR, "%s: Could not create audio codec", __FUNCTION__); delete m_pDemuxer; m_pDemuxer = NULL; delete m_pInputStream; m_pInputStream = NULL; return false; } // Extract ReplayGain info // tagLoaderTagLib.Load will try to determine tag type by file extension, so set fallback by contentType CStdString strFallbackFileExtension = ""; if (m_strContentType.Equals("audio/aacp") || m_strContentType.Equals("audio/aacp" "audio/aac")) strFallbackFileExtension = "m4a"; else if (m_strContentType.Equals("audio/x-ms-wma")) strFallbackFileExtension = "wma"; else if (m_strContentType.Equals("audio/x-ape") || m_strContentType.Equals("audio/ape")) strFallbackFileExtension = "ape"; CTagLoaderTagLib tagLoaderTagLib; tagLoaderTagLib.Load(strFile, m_tag, strFallbackFileExtension); // we have to decode initial data in order to get channels/samplerate // for sanity - we read no more than 10 packets int nErrors = 0; for (int nPacket=0; nPacket < 10 && (m_Channels == 0 || m_SampleRate == 0); nPacket++) { BYTE dummy[256]; int nSize = 256; if (ReadPCM(dummy, nSize, &nSize) == READ_ERROR) ++nErrors; m_DataFormat = m_pAudioCodec->GetDataFormat(); m_BitsPerSample = CAEUtil::DataFormatToBits(m_DataFormat); m_SampleRate = m_pAudioCodec->GetSampleRate(); m_EncodedSampleRate = m_pAudioCodec->GetEncodedSampleRate(); m_Channels = m_pAudioCodec->GetChannels(); m_ChannelInfo = m_pAudioCodec->GetChannelMap(); m_BitsPerCodedSample = static_cast<CDemuxStreamAudio*>(pStream)->iBitsPerSample; } if (nErrors >= 10) { CLog::Log(LOGDEBUG, "%s: Could not decode data", __FUNCTION__); return false; } // test if seeking is supported if (Seek(1) != DVD_NOPTS_VALUE) { // rewind stream to beginning Seek(0); m_bCanSeek = true; } else { m_pInputStream->Seek(0, SEEK_SET); m_pDemuxer->Reset(); m_bCanSeek = false; } if (m_Channels == 0) // no data - just guess and hope for the best m_Channels = 2; if (m_SampleRate == 0) m_SampleRate = 44100; m_TotalTime = m_pDemuxer->GetStreamLength(); m_Bitrate = m_pAudioCodec->GetBitRate(); if (!m_Bitrate && m_TotalTime) { m_Bitrate = (int)(((m_pInputStream->GetLength()*1000) / m_TotalTime) * 8); } m_pDemuxer->GetStreamCodecName(m_nAudioStream,m_CodecName); m_strFileName = strFile; m_bInited = true; return true; }
ICodec* CodecFactory::CreateCodecDemux(const CStdString& strFile, const CStdString& strContent, unsigned int filecache) { CURL urlFile(strFile); if( strContent.Equals("audio/mpeg") || strContent.Equals("audio/mp3") ) return new MP3Codec(); else if (strContent.Left(9).Equals("audio/l16")) { PCMCodec * pcm_codec = new PCMCodec(); pcm_codec->SetMimeParams(strContent); return pcm_codec; } else if( strContent.Equals("audio/aac") || strContent.Equals("audio/aacp") ) { DVDPlayerCodec *pCodec = new DVDPlayerCodec; if (urlFile.GetProtocol() == "shout" ) pCodec->SetContentType(strContent); return pCodec; } else if( strContent.Equals("audio/x-ms-wma") ) return new DVDPlayerCodec(); else if( strContent.Equals("application/ogg") || strContent.Equals("audio/ogg")) return CreateOGGCodec(strFile,filecache); else if (strContent.Equals("audio/x-xbmc-pcm")) return (ICodec*)new BXACodec(); else if (strContent.Equals("audio/flac") || strContent.Equals("audio/x-flac") || strContent.Equals("application/x-flac")) return new FLACCodec(); if (urlFile.GetProtocol() == "lastfm" || urlFile.GetProtocol() == "shout") { return new MP3Codec(); // if we got this far with internet radio - content-type was wrong. gamble on mp3. } if (urlFile.GetFileType().Equals("wav")) { ICodec* codec; //lets see what it contains... //this kinda sucks 'cause if it's a plain wav file the file //will be opened, sniffed and closed 2 times before it is opened *again* for wav //would be better if the papcodecs could work with bitstreams instead of filenames. DVDPlayerCodec *dvdcodec = new DVDPlayerCodec(); dvdcodec->SetContentType("audio/x-spdif-compressed"); if (dvdcodec->Init(strFile, filecache)) { return dvdcodec; } delete dvdcodec; codec = new ADPCMCodec(); if (codec->Init(strFile, filecache)) { return codec; } delete codec; codec = new WAVCodec(); if (codec->Init(strFile, filecache)) { return codec; } delete codec; } if (urlFile.GetFileType().Equals("cdda")) { //lets see what it contains... //this kinda sucks 'cause if it's plain cdda the file //will be opened, sniffed and closed before it is opened *again* for cdda //would be better if the papcodecs could work with bitstreams instead of filenames. DVDPlayerCodec *dvdcodec = new DVDPlayerCodec(); dvdcodec->SetContentType("audio/x-spdif-compressed"); if (dvdcodec->Init(strFile, filecache)) { return dvdcodec; } delete dvdcodec; } else if (urlFile.GetFileType().Equals("ogg") || urlFile.GetFileType().Equals("oggstream") || urlFile.GetFileType().Equals("oga")) return CreateOGGCodec(strFile,filecache); //default return CreateCodec(urlFile.GetFileType()); }
ICodec* CodecFactory::CreateCodecDemux(const CStdString& strFile, const CStdString& strContent, unsigned int filecache) { CURL urlFile(strFile); if( strContent.Equals("audio/mpeg") || strContent.Equals("audio/mpeg3") || strContent.Equals("audio/mp3") ) { DVDPlayerCodec *dvdcodec = new DVDPlayerCodec(); dvdcodec->SetContentType(strContent); return dvdcodec; } else if (StringUtils::StartsWithNoCase(strContent, "audio/l16")) { PCMCodec * pcm_codec = new PCMCodec(); pcm_codec->SetMimeParams(strContent); return pcm_codec; } else if( strContent.Equals("audio/aac") || strContent.Equals("audio/aacp") || strContent.Equals("audio/x-ms-wma") || strContent.Equals("audio/x-ape") || strContent.Equals("audio/ape")) { DVDPlayerCodec *pCodec = new DVDPlayerCodec; pCodec->SetContentType(strContent); return pCodec; } else if( strContent.Equals("application/ogg") || strContent.Equals("audio/ogg")) return CreateOGGCodec(strFile,filecache); else if (strContent.Equals("audio/x-xbmc-pcm")) { // audio/x-xbmc-pcm this is the used codec for AirTunes // (apples audio only streaming) DVDPlayerCodec *dvdcodec = new DVDPlayerCodec(); dvdcodec->SetContentType(strContent); return dvdcodec; } else if (strContent.Equals("audio/flac") || strContent.Equals("audio/x-flac") || strContent.Equals("application/x-flac")) { DVDPlayerCodec *dvdcodec = new DVDPlayerCodec(); dvdcodec->SetContentType(strContent); return dvdcodec; } if (urlFile.GetProtocol() == "shout") { DVDPlayerCodec *dvdcodec = new DVDPlayerCodec(); dvdcodec->SetContentType("audio/mp3"); return dvdcodec; // if we got this far with internet radio - content-type was wrong. gamble on mp3. } if (urlFile.GetFileType().Equals("wav") || strContent.Equals("audio/wav") || strContent.Equals("audio/x-wav")) { //lets see what it contains... //this kinda sucks 'cause if it's a plain wav file the file //will be opened, sniffed and closed 2 times before it is opened *again* for wav //would be better if the papcodecs could work with bitstreams instead of filenames. DVDPlayerCodec *dvdcodec = new DVDPlayerCodec(); dvdcodec->SetContentType("audio/x-spdif-compressed"); if (dvdcodec->Init(strFile, filecache)) { return dvdcodec; } dvdcodec = new DVDPlayerCodec(); dvdcodec->SetContentType(strContent); return dvdcodec; } else if (urlFile.GetFileType().Equals("ogg") || urlFile.GetFileType().Equals("oggstream") || urlFile.GetFileType().Equals("oga")) return CreateOGGCodec(strFile,filecache); //default return CreateCodec(urlFile.GetFileType()); }
//#define DEBUG bool CFlashUpdate::selectHttpImage(void) { CHTTPTool httpTool; std::string url; std::string name; std::string version; std::string md5; std::vector<std::string> updates_lists, urls, names, versions, descriptions, md5s; char fileTypes[128]; int selected = -1, listWidth = w_max (80, 10); int curVer, newVer, newfound = 0; std::vector<CUpdateMenuTarget*> update_t_list; CConfigFile _configfile('\t'); const char * versionString = (_configfile.loadConfig("/.version")) ? (_configfile.getString( "version", "????????????????").c_str()) : "????????????????"; installedVersion = versionString; CFlashVersionInfo curInfo(versionString); printf("current flash-version: %s (%d)\n", installedVersion.c_str(), curInfo.getVersion()); curVer = curInfo.getVersion(); httpTool.setStatusViewer(this); showStatusMessageUTF(g_Locale->getText(LOCALE_FLASHUPDATE_GETINFOFILE)); // UTF-8 char current[200]; snprintf(current, 200, "%s: %s %s %s %s %s", g_Locale->getText(LOCALE_FLASHUPDATE_CURRENTVERSION_SEP), curInfo.getReleaseCycle(), g_Locale->getText(LOCALE_FLASHUPDATE_CURRENTVERSIONDATE), curInfo.getDate(), g_Locale->getText(LOCALE_FLASHUPDATE_CURRENTVERSIONTIME), curInfo.getTime()); CMenuWidget SelectionWidget(LOCALE_FLASHUPDATE_SELECTIMAGE, NEUTRINO_ICON_UPDATE, listWidth, MN_WIDGET_ID_IMAGESELECTOR); SelectionWidget.addItem(GenericMenuSeparator); SelectionWidget.addItem(GenericMenuBack); SelectionWidget.addItem(new CMenuSeparator(CMenuSeparator::LINE)); SelectionWidget.addItem(new CMenuForwarder(current, false)); std::ifstream urlFile(g_settings.softupdate_url_file.c_str()); #ifdef DEBUG printf("[update] file %s\n", g_settings.softupdate_url_file.c_str()); #endif unsigned int i = 0; while (urlFile >> url) { std::string::size_type startpos, endpos; #ifdef DEBUG printf("[update] url %s\n", url.c_str()); #endif /* extract domain name */ startpos = url.find("//"); if (startpos == std::string::npos) { startpos = 0; endpos = std::string::npos; updates_lists.push_back(url.substr(startpos, endpos - startpos)); } else { //startpos += 2; //endpos = url.find('/', startpos); startpos = url.find('/', startpos+2)+1; endpos = std::string::npos; updates_lists.push_back(url.substr(startpos, endpos - startpos)); } //updates_lists.push_back(url.substr(startpos, endpos - startpos)); SelectionWidget.addItem(new CMenuSeparator(CMenuSeparator::STRING | CMenuSeparator::LINE, updates_lists.rbegin()->c_str())); if (httpTool.downloadFile(url, gTmpPath LIST_OF_UPDATES_LOCAL_FILENAME, 20)) { std::ifstream in(gTmpPath LIST_OF_UPDATES_LOCAL_FILENAME); bool enabled; while (in >> url >> version >> md5 >> std::ws) { urls.push_back(url); versions.push_back(version); std::getline(in, name); names.push_back(name); //std::getline(in, md5); md5s.push_back(md5); enabled = true; CFlashVersionInfo versionInfo(versions[i]); newVer = versionInfo.getVersion(); #ifdef DEBUG printf("[update] url %s version %s (%d) md5 %s name %s\n", url.c_str(), version.c_str(), newVer, md5.c_str(), name.c_str()); #endif if(newVer > curVer) newfound = 1; if(!allow_flash && (versionInfo.snapshot < '3')) enabled = false; fileTypes[i] = versionInfo.snapshot; //std::string description = versionInfo.getType(); std::string description = versionInfo.getReleaseCycle(); description += ' '; description += versionInfo.getType(); description += ' '; description += versionInfo.getDate(); description += ' '; description += versionInfo.getTime(); descriptions.push_back(description); /* workaround since CMenuForwarder does not store the Option String itself */ //SelectionWidget.addItem(new CMenuForwarder(names[i].c_str(), enabled, descriptions[i].c_str(), new CUpdateMenuTarget(i, &selected))); CUpdateMenuTarget * up = new CUpdateMenuTarget(i, &selected); update_t_list.push_back(up); SelectionWidget.addItem(new CMenuForwarder(descriptions[i].c_str(), enabled, names[i].c_str(), up)); i++; } } }
/** * Get the list of server URLs from the file. */ void xfer_read_server_url_file(const char *path, std::vector<std::string> &urlbuf, MPI_Comm comm) { log_level debug_level = xfer_debug_level; int rank, np; struct stat sbuf; MPI_Comm_rank(comm, &rank); MPI_Comm_size(comm, &np); // variables for the serverURLs int numServers = 0; // Open the file and get all the server urls if (rank == 0) { while (stat(path, &sbuf)) { log_debug(debug_level, "%s: %s", path, strerror(errno)); sleep(1); } // try to open the file std::ifstream urlFile(path); if (urlFile.is_open()) { if (urlFile.good()) { std::string line; std::getline(urlFile, line); numServers = std::atoi(line.c_str()); } urlbuf.resize(numServers, std::string(NSSI_URL_LEN, '\0')); for (int i=0; i<numServers; i++) { if (urlFile.good()) { std::getline(urlFile, urlbuf[i]); log_debug(debug_level, "URL %d = %s", i, urlbuf[i].c_str()); } else { log_error(debug_level, "Unexpected EOF in %s", path); MPI_Abort(MPI_COMM_WORLD, 1); } } } else { log_error(debug_level, "Could not open serverURL = %s", path); MPI_Abort(comm, 1); } urlFile.close(); } // broadcast the number of servers MPI_Bcast(&numServers, 1, MPI_INT, 0, comm); if (rank != 0) urlbuf.resize(numServers, std::string(NSSI_URL_LEN, '\0')); // allocate space for URLs // broadcast the list of URls to the other clients for (int i=0; i<numServers; i++) { MPI_Bcast(&urlbuf[i][0], NSSI_URL_LEN, MPI_CHAR, 0, comm); } }