• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ IsOpen函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中IsOpen函数的典型用法代码示例。如果您正苦于以下问题:C++ IsOpen函数的具体用法?C++ IsOpen怎么用?C++ IsOpen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了IsOpen函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: open

void 
MTfile::Create (const char *filename)
{
	if (IsOpen()) {
		return;
	}
	fileHandle = open (filename, O_RDWR|O_BINARY);
	if (fileHandle >= 0) {
		close (fileHandle);
		return;
	}
	fileHandle = open (filename, O_BINARY|O_RDWR|O_CREAT|O_TRUNC, S_IREAD|S_IWRITE);
	if (fileHandle < 0) {
		return;
	}
	SetOpen (1);

	/* Reserve page 0 */
	char *page = new char[PageSize()];
	memset (page, 0, PageSize());
	memcpy (page, magic, sizeof(magic));
	write (fileHandle, page, PageSize());
	delete []page;
}
开发者ID:jsc0218,项目名称:MxTree,代码行数:24,代码来源:MTfile.cpp


示例2: _ASSERTE

BOOL CSqlite3Recordset::GetField(short iIndex, CString& Data)
{
   _ASSERTE(IsOpen());
   _ASSERTE(iIndex>=0 && iIndex<m_nCols);
   if( IsEOF() ) return FALSE;
   if( iIndex < 0 || iIndex >= m_nCols ) return FALSE;
   if( m_lType == DB_OPEN_TYPE_FORWARD_ONLY ) {
#if !defined(UNICODE)
      Data = (char*) ::sqlite3_column_text(m_pVm, iIndex);
#else  // UNICODE
      Data = ::sqlite3_column_text16(m_pVm, iIndex);
#endif // UNICODE
   }
   else {
      LPSTR pstr = m_ppSnapshot[ ((m_iPos + 1) * m_nCols) + iIndex ];
      if( pstr == NULL ) {
         Data = _T("");
      }
      else {
         Data = pstr;
      }
   }
   return TRUE;
}
开发者ID:okigan,项目名称:dblib,代码行数:24,代码来源:DbSqlite3.cpp


示例3: USRLOG

bool Ctrl::SetFocus0(bool activate)
{
	GuiLock __;
	USRLOG("      SETFOCUS " << Desc(this));
	LLOG("Ctrl::SetFocus " << Desc(this));
	LLOG("focusCtrlWnd " << UPP::Name(focusCtrlWnd));
	LLOG("Ctrl::SetFocus0 -> deferredSetFocus = NULL; was: " << UPP::Name(defferedSetFocus));
	defferedSetFocus = NULL;
	if(focusCtrl == this) return true;
	if(!IsOpen() || !IsEnabled() || !IsVisible()) return false;
	Ptr<Ctrl> pfocusCtrl = focusCtrl;
	Ptr<Ctrl> topwindow = GetTopWindow();
	Ptr<Ctrl> topctrl = GetTopCtrl();
	Ptr<Ctrl> _this = this;
	if(!topwindow) topwindow = topctrl;
	LLOG("SetFocus -> SetWndFocus: topwindow = " << UPP::Name(topwindow) << ", focusCtrlWnd = " << UPP::Name(focusCtrlWnd));
	if(!topwindow->HasWndFocus() && !topwindow->SetWndFocus()) return false;// cxl 31.1.2004
#ifdef PLATFORM_OSX11 // ugly temporary hack - popups not behaving right in MacOS
	// before 2012-9-2 was #ifdef GUI_X11, but that caused issues in most linux distros (cxl)
	// as parent window of popup always manages focus/keyboard for popup in X11
	if(activate) // Dolik/fudadmin 2011-5-1
		topctrl->SetWndForeground();
#else
	topwindow->SetWndForeground();  // cxl 2007-4-27
#endif
	LLOG("SetFocus -> focusCtrl = this: " << FormatIntHex(this) << ", _this = " << FormatIntHex(~_this) << ", " << UPP::Name(_this));
	focusCtrl = _this;
	focusCtrlWnd = topwindow;
	DoKillFocus(pfocusCtrl, _this);
	LLOG("SetFocus 2");
	DoDeactivate(pfocusCtrl, _this);
	DoSetFocus(pfocusCtrl, _this, activate);
	if(topwindow)
		lastActiveWnd = topwindow;
	return true;
}
开发者ID:guowei8412,项目名称:upp-mirror,代码行数:36,代码来源:CtrlKbd.cpp


示例4: SPFSException

void 
SPFS::LoadFileAsString(LPCSTR spfsFileName,string& sResultStr)
	{
	if( !IsOpen() )
		throw new SPFSException(_T("pack file isn't opened !"),SPFS_FILE_IS_NOT_OPENED);
	
	DWORD offset  = 0; // offset of file.
	DWORD size    = 0; // size of file.
	DWORD written = 0; // size of written bytes.

	// find file in pack file.
	if( !FindFile(spfsFileName,offset,size) ) 
		throw new SPFSException(_T("not found file in pack !"),SPFS_FILE_IS_NOT_OPENED);

	char* lpBuff   = (char*)malloc(size+1);
	if( ReadFileData(offset,size,lpBuff,size,written) && written == size )
		{
		lpBuff[size] = 0x00;    
		sResultStr     = lpBuff;
		}
	else
		throw new SPFSException(_T("can't read file data !"),SPFS_FILE_CANT_READ);
	free(lpBuff);
	}
开发者ID:zqrtalent,项目名称:MercuryUI,代码行数:24,代码来源:SPFS.cpp


示例5: open

void 
GiSTfile::Open(const char *filename)
{
  char *page;

  if (IsOpen())
    return;

  fileHandle = open(filename, O_RDWR | O_BINARY);

  if (fileHandle < 0)
    return;

  // Verify that the magic words are there
  page = new char[PageSize()];
  read(fileHandle, page, PageSize());
  if (memcmp(page, magic, sizeof(magic))) {
    close(fileHandle);
	delete page;
    return;
  }
  delete page;
  SetOpen(1);
}
开发者ID:hkaiser,项目名称:TRiAS,代码行数:24,代码来源:GiSTfile.cpp


示例6: logic_error

   bool
   File::Open(const String &sFilename, OpenType ot)
   {
      if (IsOpen())
      {
         // The file should be closed, before we
         // try to open it again...
         throw std::logic_error(Formatter::FormatAsAnsi("The file {0} is already open.", sFilename));
      }

      std::wstring open_mode;

      switch (ot)
      {
      case OTReadOnly:
         open_mode = _T("rb");
         break;
      case OTCreate:
         open_mode = _T("wb");
         break;
      case OTAppend:
         open_mode = _T("ab");
         break;
      }

      file_ = _wfsopen(sFilename.c_str(), open_mode.c_str(), _SH_DENYNO);

      if (file_ == nullptr)
      {
         return false;
      }

      name_ = sFilename;

      return true;
   }
开发者ID:james-git,项目名称:hmailserver,代码行数:36,代码来源:File.cpp


示例7: LOGGER_WARNING

bool FileInputSource::Close(CFErrorRef *error)
{
	if(!IsOpen()) {
		LOGGER_WARNING("org.sbooth.AudioEngine.InputSource.File", "Close() called on an InputSource that hasn't been opened");
		return true;
	}

	memset(&mFilestats, 0, sizeof(mFilestats));

	if(nullptr != mFile) {
		int result = fclose(mFile);

		mFile = nullptr;

		if(-1 == result) {
			if(error)
				*error = CFErrorCreate(kCFAllocatorDefault, kCFErrorDomainPOSIX, errno, nullptr);
			return false;
		}
	}

	mIsOpen = false;
	return true;
}
开发者ID:doorxp,项目名称:SFBAudioEngine,代码行数:24,代码来源:FileInputSource.cpp


示例8: ASSERT

void CNamedPipe::SetMode(BOOL bByteMode, BOOL bBlockingMode)
{
  //Validate our parameters
  ASSERT(IsOpen()); //Pipe must be open

  DWORD dwMode;
  if (bByteMode)
  {
    if (bBlockingMode)
      dwMode = PIPE_READMODE_BYTE | PIPE_WAIT;
    else
      dwMode = PIPE_READMODE_BYTE | PIPE_NOWAIT;
  }
  else
  {
    if (bBlockingMode)
      dwMode = PIPE_READMODE_MESSAGE | PIPE_WAIT;
    else
      dwMode = PIPE_READMODE_MESSAGE | PIPE_NOWAIT;
  }

  if (!::SetNamedPipeHandleState(m_hPipe, &dwMode, NULL, NULL))
    ThrowNamedPipeException();
}
开发者ID:KnowNo,项目名称:test-code-backup,代码行数:24,代码来源:npipe.cpp


示例9: mxAssert

/* MX_OVERRIDDEN */ mx::Size mx::FileStream::PrintfV(
        const Char * const sFormat, va_list pArguments)
{
    mxAssert(IsOpen());
    mxAssert(sFormat != NULL);

    int iCharsWritten;
    if ((iCharsWritten =
#ifndef MXCPP_UNICODE
                     ::vfprintf
#else
                     ::vfwprintf
#endif
                 (m_hFileDescriptor, sFormat, pArguments))
        < 0)
    {
        // We cannot reach eof during write (check it).
        mxAssert(!feof(m_hFileDescriptor));
        // File I/O error other than EOF.
        mxThrow(GenericIOException(ferror(m_hFileDescriptor)));
    }

    return iCharsWritten;
}
开发者ID:emaskovsky,项目名称:examples-cpp-framework,代码行数:24,代码来源:FileStrm.cpp


示例10: CoreAssert

int CoreIOWriter::WriteU32(uint32_t _data)
{
    CoreAssert(this != NULL);
    if (!IsOpen()) return 0;

#ifndef __GNUC__
    MutexHolder mh(&m_ioMutex);
#endif
    switch (m_endianness)
    {
    case CC_ENDIAN_LITTLE:
        _data = CC_SwapBE32(_data);
        break;
    case CC_ENDIAN_BIG:
        _data = CC_SwapLE32(_data);
        break;
    case CC_ENDIAN_NATIVE:
        /* Do nothing */
        break;
    }
    size_t ret = fwrite(&_data, sizeof(uint32_t), 1, m_fileOutputPointer);

    return ret;
}
开发者ID:amoylel,项目名称:crisscross,代码行数:24,代码来源:core_io_writer.cpp


示例11: Read

////////////////////////////////////////////////////////////////////////////////
/// Lecture dans le fichier
///
/// Parametres : 
/// \param buffer     [out]buffer dans lequel a ete ecrit le contenu du fichier
/// \param count      [in]nombre max d'octets a lire
///
/// \return taille du fichier ou -1 si probleme de lecture
////////////////////////////////////////////////////////////////////////////////
int CAdeReadOnlyBinaryFileWithCRC::Read(void* buffer, unsigned int count)
{
    if (IsOpen() == false)
    {
        // fichier non ouvert
        return -1;
    }
    if (m_currPos >= m_lengthWithoutCRC)
    {
        // fin de fichier
        return 0;
    }
    // On limite eventuellement si ce qui reste a lire dans le fichier est inferieur a ce qui est demande
    if (count > static_cast<unsigned int>(m_lengthWithoutCRC - m_currPos))
    {
        count = m_lengthWithoutCRC - m_currPos;
    }
    // On copie les donnees
    memcpy(buffer, &m_fileContent[m_currPos], count);
    // On "avance" dans le fichier
    m_currPos += count;
    // On renvoie le nombre d'octets effectivement lus
    return count;
}
开发者ID:drupalhunter-team,项目名称:TrackMonitor,代码行数:33,代码来源:AdeFile.cpp


示例12: sizeof

GiSTpage 
MTfile::Allocate()
{
	GiSTpage page;
	char *buf;

	if(!IsOpen()) return (0);
	// See if there's a deleted page
	buf=new char[PageSize()];
	Read(0, buf);
	memcpy(&page, buf+sizeof(magic), sizeof(GiSTpage));
	if(page) {
		// Reclaim this page
		Read(page, buf);
		Write(0, buf);
	}
	else {
		page=lseek(fileHandle, 0, SEEK_END)/PageSize();
		memset(buf, 0, PageSize());
		write(fileHandle, buf, PageSize());
	}
	delete buf;
	return page;
}
开发者ID:voidcycles,项目名称:m3,代码行数:24,代码来源:MTfile.cpp


示例13: ASSERT

ALERROR CDataFile::AddEntry (const CString &sData, int *retiEntry)

//	AddEntry
//
//	Does some stuff

	{
	ALERROR error;
	int i, iEntry;
	DWORD dwStartingBlock;
	DWORD dwBlockCount;

	ASSERT(IsOpen());
	ASSERT(!m_fReadOnly);

	//	Look for a free entry

	for (i = 0; i < m_iEntryTableCount; i++)
		if (m_pEntryTable[i].dwBlock == FREE_ENTRY)
			break;

	//	If we could not find a free entry, grow the entry table

	if (i == m_iEntryTableCount)
		{
		if ((error = GrowEntryTable(&iEntry)))
			goto Fail;
		}
	else
		iEntry = i;

	//	Figure out how many blocks we need

	dwBlockCount = (sData.GetLength() / m_iBlockSize) + 1;

	//	Allocate a block chain large enough to contain the entry

	if ((error = AllocBlockChain(dwBlockCount, &dwStartingBlock)))
		goto Fail;

	//	Write the block chain

	if ((error = WriteBlockChain(dwStartingBlock, sData.GetPointer(), sData.GetLength())))
		{
		FreeBlockChain(dwStartingBlock, dwBlockCount);
		goto Fail;
		}

	//	Set the entry

	m_pEntryTable[iEntry].dwBlock = dwStartingBlock;
	m_pEntryTable[iEntry].dwBlockCount = dwBlockCount;
	m_pEntryTable[iEntry].dwSize = (DWORD)sData.GetLength();
	m_pEntryTable[iEntry].dwFlags = 0;
	m_fEntryTableModified = TRUE;

	//	Flush

	if ((error = Flush()))
		goto Fail;

	//	Done

	*retiEntry = iEntry;

	return NOERROR;

Fail:

	return error;
	}
开发者ID:alanhorizon,项目名称:Transport,代码行数:71,代码来源:CDataFile.cpp


示例14: LOGGER_WARNING

bool OggSpeexDecoder::Open(CFErrorRef *error)
{
	if(IsOpen()) {
		LOGGER_WARNING("org.sbooth.AudioEngine.AudioDecoder.OggSpeex", "Open() called on an AudioDecoder that is already open");		
		return true;
	}

	// Ensure the input source is open
	if(!mInputSource->IsOpen() && !mInputSource->Open(error))
		return false;

	// Initialize Ogg data struct
	ogg_sync_init(&mOggSyncState);

	// Get the ogg buffer for writing
	char *data = ogg_sync_buffer(&mOggSyncState, READ_SIZE_BYTES);
	
	// Read bitstream from input file
	ssize_t bytesRead = GetInputSource()->Read(data, READ_SIZE_BYTES);
	if(-1 == bytesRead) {
		if(error) {
			CFMutableDictionaryRef errorDictionary = CFDictionaryCreateMutable(kCFAllocatorDefault, 
																			   0,
																			   &kCFTypeDictionaryKeyCallBacks,
																			   &kCFTypeDictionaryValueCallBacks);
			
			CFStringRef displayName = CreateDisplayNameForURL(mInputSource->GetURL());
			CFStringRef errorString = CFStringCreateWithFormat(kCFAllocatorDefault, 
															   NULL, 
															   CFCopyLocalizedString(CFSTR("The file “%@” could not be read."), ""), 
															   displayName);
			
			CFDictionarySetValue(errorDictionary, 
								 kCFErrorLocalizedDescriptionKey, 
								 errorString);
			
			CFDictionarySetValue(errorDictionary, 
								 kCFErrorLocalizedFailureReasonKey, 
								 CFCopyLocalizedString(CFSTR("Read error"), ""));
			
			CFDictionarySetValue(errorDictionary, 
								 kCFErrorLocalizedRecoverySuggestionKey, 
								 CFCopyLocalizedString(CFSTR("Unable to read from the input file."), ""));
			
			CFRelease(errorString), errorString = NULL;
			CFRelease(displayName), displayName = NULL;
			
			*error = CFErrorCreate(kCFAllocatorDefault, 
								   AudioDecoderErrorDomain, 
								   AudioDecoderInputOutputError, 
								   errorDictionary);
			
			CFRelease(errorDictionary), errorDictionary = NULL;				
		}
		
		ogg_sync_destroy(&mOggSyncState);
		return false;
	}
	
	// Tell the sync layer how many bytes were written to its internal buffer
	int result = ogg_sync_wrote(&mOggSyncState, bytesRead);
	if(-1 == result) {
		if(error) {
			CFMutableDictionaryRef errorDictionary = CFDictionaryCreateMutable(kCFAllocatorDefault, 
																			   0,
																			   &kCFTypeDictionaryKeyCallBacks,
																			   &kCFTypeDictionaryValueCallBacks);
			
			CFStringRef displayName = CreateDisplayNameForURL(mInputSource->GetURL());
			CFStringRef errorString = CFStringCreateWithFormat(kCFAllocatorDefault, 
															   NULL, 
															   CFCopyLocalizedString(CFSTR("The file “%@” does not appear to be an Ogg file."), ""), 
															   displayName);
			
			CFDictionarySetValue(errorDictionary, 
								 kCFErrorLocalizedDescriptionKey, 
								 errorString);
			
			CFDictionarySetValue(errorDictionary, 
								 kCFErrorLocalizedFailureReasonKey, 
								 CFCopyLocalizedString(CFSTR("Not an Ogg file"), ""));
			
			CFDictionarySetValue(errorDictionary, 
								 kCFErrorLocalizedRecoverySuggestionKey, 
								 CFCopyLocalizedString(CFSTR("The file's extension may not match the file's type."), ""));
			
			CFRelease(errorString), errorString = NULL;
			CFRelease(displayName), displayName = NULL;
			
			*error = CFErrorCreate(kCFAllocatorDefault, 
								   AudioDecoderErrorDomain, 
								   AudioDecoderFileFormatNotRecognizedError, 
								   errorDictionary);
			
			CFRelease(errorDictionary), errorDictionary = NULL;				
		}
		
		ogg_sync_destroy(&mOggSyncState);
		return false;
	}
//.........这里部分代码省略.........
开发者ID:hjzc,项目名称:SFBAudioEngine,代码行数:101,代码来源:OggSpeexDecoder.cpp


示例15:

OggSpeexDecoder::~OggSpeexDecoder()
{
	if(IsOpen())
		Close();
}
开发者ID:hjzc,项目名称:SFBAudioEngine,代码行数:5,代码来源:OggSpeexDecoder.cpp


示例16: ReadAudio

UInt32 OggSpeexDecoder::ReadAudio(AudioBufferList *bufferList, UInt32 frameCount)
{
	if(!IsOpen() || NULL == bufferList || bufferList->mNumberBuffers != mFormat.mChannelsPerFrame || 0 == frameCount)
		return 0;

	UInt32 framesRead = 0;
	
	// Reset output buffer data size
	for(UInt32 i = 0; i < bufferList->mNumberBuffers; ++i)
		bufferList->mBuffers[i].mDataByteSize = 0;

	for(;;) {
		
		UInt32	framesRemaining	= frameCount - framesRead;
		UInt32	framesToSkip	= static_cast<UInt32>(bufferList->mBuffers[0].mDataByteSize / sizeof(float));
		UInt32	framesInBuffer	= static_cast<UInt32>(mBufferList->mBuffers[0].mDataByteSize / sizeof(float));
		UInt32	framesToCopy	= std::min(framesInBuffer, framesRemaining);
		
		// Copy data from the buffer to output
		for(UInt32 i = 0; i < mBufferList->mNumberBuffers; ++i) {
			float *floatBuffer = static_cast<float *>(bufferList->mBuffers[i].mData);
			memcpy(floatBuffer + framesToSkip, mBufferList->mBuffers[i].mData, framesToCopy * sizeof(float));
			bufferList->mBuffers[i].mDataByteSize += static_cast<UInt32>(framesToCopy * sizeof(float));
			
			// Move remaining data in buffer to beginning
			if(framesToCopy != framesInBuffer) {
				floatBuffer = static_cast<float *>(mBufferList->mBuffers[i].mData);
				memmove(floatBuffer, floatBuffer + framesToCopy, (framesInBuffer - framesToCopy) * sizeof(float));
			}
			
			mBufferList->mBuffers[i].mDataByteSize -= static_cast<UInt32>(framesToCopy * sizeof(float));
		}
		
		framesRead += framesToCopy;
		
		// All requested frames were read
		if(framesRead == frameCount)
			break;
		
		// EOS reached
		if(mSpeexEOSReached)
			break;

		// Attempt to process the desired number of packets
		unsigned packetsDesired = 1;
		while(0 < packetsDesired && !mSpeexEOSReached) {

			// Process any packets in the current page
			while(0 < packetsDesired && !mSpeexEOSReached) {

				// Grab a packet from the streaming layer
				ogg_packet oggPacket;
				int result = ogg_stream_packetout(&mOggStreamState, &oggPacket);
				if(-1 == result) {
					LOGGER_ERR("org.sbooth.AudioEngine.AudioDecoder.OggSpeex", "Ogg Speex decoding error: Ogg loss of streaming");
					break;
				}
				
				// If result is 0, there is insufficient data to assemble a packet
				if(0 == result)
					break;

				// Otherwise, we got a valid packet for processing
				if(1 == result) {
					if(5 <= oggPacket.bytes && !memcmp(oggPacket.packet, "Speex", 5))
						mSpeexSerialNumber = mOggStreamState.serialno;
					
					if(-1 == mSpeexSerialNumber || mOggStreamState.serialno != mSpeexSerialNumber)
						break;
					
					// Ignore the following:
					//  - Speex comments in packet #2
					//  - Extra headers (optionally) in packets 3+
					if(1 != mOggPacketCount && 1 + mExtraSpeexHeaderCount <= mOggPacketCount) {
						// Detect Speex EOS
						if(oggPacket.e_o_s && mOggStreamState.serialno == mSpeexSerialNumber)
							mSpeexEOSReached = true;

						// SPEEX_GET_FRAME_SIZE is in samples
						spx_int32_t speexFrameSize;
						speex_decoder_ctl(mSpeexDecoder, SPEEX_GET_FRAME_SIZE, &speexFrameSize);
						float buffer [(2 == mFormat.mChannelsPerFrame) ? 2 * speexFrameSize : speexFrameSize];
						
						// Copy the Ogg packet to the Speex bitstream
						speex_bits_read_from(&mSpeexBits, (char *)oggPacket.packet, static_cast<int>(oggPacket.bytes));
						
						// Decode each frame in the Speex packet
						for(spx_int32_t i = 0; i < mSpeexFramesPerOggPacket; ++i) {
							
							result = speex_decode(mSpeexDecoder, &mSpeexBits, buffer);

							// -1 indicates EOS
							if(-1 == result)
								break;
							else if(-2 == result) {
								LOGGER_ERR("org.sbooth.AudioEngine.AudioDecoder.OggSpeex", "Ogg Speex decoding error: possible corrupted stream");
								break;
							}
							
							if(0 > speex_bits_remaining(&mSpeexBits)) {
//.........这里部分代码省略.........
开发者ID:hjzc,项目名称:SFBAudioEngine,代码行数:101,代码来源:OggSpeexDecoder.cpp


示例17: LOG4CXX_WARN

bool MemoryMappedFileInputSource::Open(CFErrorRef *error)
{
	if(IsOpen()) {
		log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger("org.sbooth.AudioEngine.InputSource.MemoryMappedFile");
		LOG4CXX_WARN(logger, "Open() called on an InputSource that is already open");
		return true;
	}
	
	UInt8 buf [PATH_MAX];
	Boolean success = CFURLGetFileSystemRepresentation(mURL, FALSE, buf, PATH_MAX);
	if(!success) {
		if(error)
			*error = CFErrorCreate(kCFAllocatorDefault, kCFErrorDomainPOSIX, EIO, NULL);
		return false;
	}
	
	int fd = open(reinterpret_cast<const char *>(buf), O_RDONLY);
	
	if(-1 == fd) {
		if(error)
			*error = CFErrorCreate(kCFAllocatorDefault, kCFErrorDomainPOSIX, errno, NULL);
		return false;
	}
	
	if(-1 == fstat(fd, &mFilestats)) {
		if(error)
			*error = CFErrorCreate(kCFAllocatorDefault, kCFErrorDomainPOSIX, errno, NULL);

		if(-1 == close(fd)) {
			log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger("org.sbooth.AudioEngine.InputSource.MemoryMappedFile");
			LOG4CXX_WARN(logger, "Unable to close the file: " << strerror(errno));
		}

		return false;
	}
	
	// Only regular files can be mapped
	if(!S_ISREG(mFilestats.st_mode)) {
		if(error)
			*error = CFErrorCreate(kCFAllocatorDefault, kCFErrorDomainPOSIX, EBADF, NULL);
		
		if(-1 == close(fd)) {
			log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger("org.sbooth.AudioEngine.InputSource.MemoryMappedFile");
			LOG4CXX_WARN(logger, "Unable to close the file: " << strerror(errno));
		}
		
		memset(&mFilestats, 0, sizeof(mFilestats));

		return false;
	}
	
	mMemory = static_cast<int8_t *>(mmap(0, mFilestats.st_size, PROT_READ, MAP_FILE | MAP_SHARED, fd, 0));
	
	if(MAP_FAILED == mMemory) {
		if(error)
			*error = CFErrorCreate(kCFAllocatorDefault, kCFErrorDomainPOSIX, errno, NULL);
		
		if(-1 == close(fd)) {
			log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger("org.sbooth.AudioEngine.InputSource.MemoryMappedFile");
			LOG4CXX_WARN(logger, "Unable to close the file: " << strerror(errno));
		}
		
		memset(&mFilestats, 0, sizeof(mFilestats));

		return false;
	}
	
	if(-1 == close(fd)) {
		if(error)
			*error = CFErrorCreate(kCFAllocatorDefault, kCFErrorDomainPOSIX, errno, NULL);

		memset(&mFilestats, 0, sizeof(mFilestats));

		return false;
	}

	mCurrentPosition = mMemory;

	mIsOpen = true;
	return true;
}
开发者ID:bookshelfapps,项目名称:SFBAudioEngine,代码行数:81,代码来源:MemoryMappedFileInputSource.cpp


示例18: Exec

dbiplus::Dataset* BXDatabase::Exec(const char *query, ...)
{
  if (!IsOpen()) {
    return NULL;
  }
  
  std::string strQuery = query;
  BXUtils::StringReplace(strQuery, "%s", "%q");
  BXUtils::StringReplace(strQuery, "%I64", "%ll");

  va_list args;
  va_start(args, query);
  char *szSql = sqlite3_vmprintf(strQuery.c_str(), args);
  va_end(args);

  std::string strResult;
  if (szSql) {
    strResult = szSql;
    sqlite3_free(szSql);
  }

  Dataset* pDataset = m_pDatabase->CreateDataset();
  if (pDataset == NULL)
  {
    LOG(LOG_LEVEL_ERROR, "Could not create dataset, query %s not executed", strResult.c_str());
    return NULL;
  }

  int iRetries = MEDIA_DATABSE_LOCK_RETRIES;

  while (iRetries > 0)
  {
    try 
    {
      pDataset->exec(strResult.c_str());
      return pDataset;
    }
    catch(dbiplus::DbErrors& e) {
      if (GetLastErrorCode() == SQLITE_LOCKED || GetLastErrorCode() == SQLITE_BUSY || GetLastErrorCode() == SQLITE_CANTOPEN)
      {
        LOG(LOG_LEVEL_DEBUG, "Database was locked, retry. Error = %s, msg= %s", GetLastErrorMessage(), e.getMsg());

        SDL_Delay(BXUtils::GetRandInt(10) + 10);
        iRetries--;
        
        // log the last attempt as error
        if (iRetries == 0)
          LOG(LOG_LEVEL_ERROR, "Exception caught, could not execute query. Error = %s, msg= %s", GetLastErrorMessage(), e.getMsg());

        continue;
      }
      else
      {
        // Some other error
        LOG(LOG_LEVEL_ERROR, "Exception caught, could not execute query. Error = %s, msg= %s", GetLastErrorMessage(), e.getMsg());
        iRetries = 0;
      }
    }
  }

  delete pDataset;
  return NULL;
}
开发者ID:flyingtime,项目名称:boxee,代码行数:63,代码来源:bxdatabase.cpp


示例19:

CFirmaSet :: ~CFirmaSet ()
{
	if (IsOpen ())
		Close ();
}
开发者ID:hkaiser,项目名称:TRiAS,代码行数:5,代码来源:FIRMASET.CPP


示例20: lock

bool BaseTCPServer::Open( uint16 port, char* errbuf )
{
    if( errbuf != NULL )
        errbuf[0] = 0;

    // mutex lock
    MutexLock lock( mMSock );

    if( IsOpen() )
    {
        if( errbuf != NULL )
            snprintf( errbuf, TCPSRV_ERRBUF_SIZE, "Listening socket already open" );
        return false;
    }
    else
    {
        mMSock.Unlock();

        // Wait for thread to terminate
        WaitLoop();

        mMSock.Lock();
    }

    // Setting up TCP port for new TCP connections
    mSock = new Socket( AF_INET, SOCK_STREAM, 0 );

    // Quag: don't think following is good stuff for TCP, good for UDP
    // Mis: SO_REUSEADDR shouldn't be a problem for tcp - allows you to restart
    //      without waiting for conn's in TIME_WAIT to die
    unsigned int reuse_addr = 1;
    mSock->setopt( SOL_SOCKET, SO_REUSEADDR, &reuse_addr, sizeof( reuse_addr ) );

    // Setup internet address information.
    // This is used with the bind() call
    sockaddr_in address;
    memset( &address, 0, sizeof( address ) );

    address.sin_family = AF_INET;
    address.sin_port = htons( port );
    address.sin_addr.s_addr = htonl( INADDR_ANY );

    if( mSock->bind( (sockaddr*)&address, sizeof( address ) ) < 0 )
    {
        if( errbuf != NULL )
            snprintf( errbuf, TCPSRV_ERRBUF_SIZE, "bind(): < 0" );

        SafeDelete( mSock );
        return false;
    }

    unsigned int bufsize = 64 * 1024; // 64kbyte receive buffer, up from default of 8k
    mSock->setopt( SOL_SOCKET, SO_RCVBUF, &bufsize, sizeof( bufsize ) );

#ifdef WIN32
    unsigned long nonblocking = 1;
    mSock->ioctl( FIONBIO, &nonblocking );
#else
    mSock->fcntl( F_SETFL, O_NONBLOCK );
#endif

    if( mSock->listen() == SOCKET_ERROR )
    {
        if( errbuf != NULL )
#ifdef WIN32
            snprintf( errbuf, TCPSRV_ERRBUF_SIZE, "listen() failed, Error: %u", WSAGetLastError() );
#else
            snprintf( errbuf, TCPSRV_ERRBUF_SIZE, "listen() failed, Error: %s", strerror( errno ) );
#endif

        SafeDelete( mSock );
        return false;
    }

    mPort = port;

    // Start processing thread
    StartLoop();

    return true;
}
开发者ID:Almamu,项目名称:evemu_apocrypha,代码行数:81,代码来源:TCPServer.cpp



注:本文中的IsOpen函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ IsOpened函数代码示例发布时间:2022-05-30
下一篇:
C++ IsOnline函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap