void MemoryMappedFile::flush(bool sync) { invariant(!(isOptionSet(Options::READONLY))); uassert(13056, "Async flushing not supported on windows", sync); if (!views.empty()) { WindowsFlushable f(this, viewForFlushing(), fd, _uniqueId, filename(), _flushMutex); f.flush(); } }
Error_t CCommandLineOptions::getOption( std::string argv, std::string& sResult ) const { if (!isOptionSet(argv)) return kNotInitializedError; int iIdx = getBufferIdx(argv); sResult = m_ppCClArgs[iIdx]->getArg(); return kNoError; }
bool MonolithicApplication::init() { if(!Quassel::init()) // parse args return false; if(isOptionSet("port")) { _internal->init(); _internalInitDone = true; } connect(Client::instance(), SIGNAL(newClientSyncer(ClientSyncer *)), this, SLOT(newClientSyncer(ClientSyncer *))); return QtUiApplication::init(); }
bool MonolithicApplication::init() { if (!Quassel::init()) // parse args return false; connect(Client::coreConnection(), SIGNAL(startInternalCore()), SLOT(startInternalCore())); // FIXME what's this for? if (isOptionSet("port")) { startInternalCore(); } return QtUiApplication::init(); }
bool Quassel::init() { if(_initialized) return true; // allow multiple invocations because of MonolithicApplication if (_handleCrashes) { // we have crashhandler for win32 and unix (based on execinfo). #if defined(Q_OS_WIN32) || defined(HAVE_EXECINFO) # ifndef Q_OS_WIN32 // we only handle crashes ourselves if coredumps are disabled struct rlimit *limit = (rlimit *) malloc(sizeof(struct rlimit)); int rc = getrlimit(RLIMIT_CORE, limit); if(rc == -1 || !((long)limit->rlim_cur > 0 || limit->rlim_cur == RLIM_INFINITY)) { # endif /* Q_OS_WIN32 */ signal(SIGABRT, handleSignal); signal(SIGSEGV, handleSignal); # ifndef Q_OS_WIN32 signal(SIGBUS, handleSignal); } free(limit); # endif /* Q_OS_WIN32 */ #endif /* Q_OS_WIN32 || HAVE_EXECINFO */ } _initialized = true; qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); registerMetaTypes(); Network::setDefaultCodecForServer("ISO-8859-1"); Network::setDefaultCodecForEncoding("UTF-8"); Network::setDefaultCodecForDecoding("ISO-8859-15"); if(isOptionSet("help")) { cliParser()->usage(); return false; } if(isOptionSet("version")) { std::cout << qPrintable("Quassel IRC: " + Quassel::buildInfo().plainVersionString) << std::endl; return false; } DEBUG = isOptionSet("debug"); // set up logging if(Quassel::runMode() != Quassel::ClientOnly) { if(isOptionSet("loglevel")) { QString level = optionValue("loglevel"); if(level == "Debug") _logLevel = DebugLevel; else if(level == "Info") _logLevel = InfoLevel; else if(level == "Warning") _logLevel= WarningLevel; else if(level == "Error") _logLevel = ErrorLevel; } QString logfilename = optionValue("logfile"); if(!logfilename.isEmpty()) { _logFile = new QFile(logfilename); if(!_logFile->open(QIODevice::Append | QIODevice::Text)) { qWarning() << "Could not open log file" << logfilename << ":" << _logFile->errorString(); _logFile->deleteLater(); _logFile = 0; } } #ifdef HAVE_SYSLOG _logToSyslog = isOptionSet("syslog"); #endif } return true; }
void* MemoryMappedFile::map(const char* filenameIn, unsigned long long& length) { verify(fd == 0 && len == 0); // can't open more than once setFilename(filenameIn); FileAllocator::get()->allocateAsap(filenameIn, length); /* big hack here: Babble uses db names with colons. doesn't seem to work on windows. temporary * perhaps. */ char filename[256]; strncpy(filename, filenameIn, 255); filename[255] = 0; { size_t len = strlen(filename); for (size_t i = len - 1; i >= 0; i--) { if (filename[i] == '/' || filename[i] == '\\') break; if (filename[i] == ':') filename[i] = '_'; } } updateLength(filename, length); const bool readOnly = isOptionSet(READONLY); { DWORD createOptions = FILE_ATTRIBUTE_NORMAL; if (isOptionSet(SEQUENTIAL)) createOptions |= FILE_FLAG_SEQUENTIAL_SCAN; DWORD desiredAccess = readOnly ? GENERIC_READ : (GENERIC_READ | GENERIC_WRITE); DWORD shareMode = readOnly ? FILE_SHARE_READ : (FILE_SHARE_WRITE | FILE_SHARE_READ); fd = CreateFileW(toWideString(filename).c_str(), desiredAccess, // desired access shareMode, // share mode NULL, // security OPEN_ALWAYS, // create disposition createOptions, // flags NULL); // hTempl if (fd == INVALID_HANDLE_VALUE) { DWORD dosError = GetLastError(); severe() << "CreateFileW for " << filename << " failed with " << errnoWithDescription(dosError) << " (file size is " << length << ")" << " in MemoryMappedFile::map" << endl; return 0; } } mapped += length; { DWORD flProtect = readOnly ? PAGE_READONLY : PAGE_READWRITE; maphandle = CreateFileMappingW(fd, NULL, flProtect, length >> 32 /*maxsizehigh*/, (unsigned)length /*maxsizelow*/, NULL /*lpName*/); if (maphandle == NULL) { DWORD dosError = GetLastError(); severe() << "CreateFileMappingW for " << filename << " failed with " << errnoWithDescription(dosError) << " (file size is " << length << ")" << " in MemoryMappedFile::map" << endl; close(); fassertFailed(16225); } } void* view = 0; { stdx::lock_guard<stdx::mutex> lk(mapViewMutex); DWORD access = readOnly ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS; int current_retry = 0; while (true) { LPVOID thisAddress = getNextMemoryMappedFileLocation(length); view = MapViewOfFileEx(maphandle, // file mapping handle access, // access 0, 0, // file offset, high and low 0, // bytes to map, 0 == all thisAddress); // address to place file if (view == 0) { DWORD dosError = GetLastError(); ++current_retry; // If we failed to allocate a memory mapped file, try again in case we picked // an address that Windows is also trying to use for some other VM allocations if (dosError == ERROR_INVALID_ADDRESS && current_retry < 5) { continue; } #ifndef _WIN64 // Warn user that if they are running a 32-bit app on 64-bit Windows if (dosError == ERROR_NOT_ENOUGH_MEMORY) { BOOL wow64Process; BOOL retWow64 = IsWow64Process(GetCurrentProcess(), &wow64Process); if (retWow64 && wow64Process) { log() << "This is a 32-bit MongoDB binary running on a 64-bit" " operating system that has run out of virtual memory for" " databases. Switch to a 64-bit build of MongoDB to open" " the databases."; } } #endif severe() << "MapViewOfFileEx for " << filename << " at address " << thisAddress << " failed with " << errnoWithDescription(dosError) << " (file size is " << length << ")" << " in MemoryMappedFile::map" << endl; close(); fassertFailed(16166); } break; } } views.push_back(view); len = length; return view; }