⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cache.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        else if (pCacheUsage)        {             LOG ("    Evergreen content");             LOGX ((szDbgTemp, "    ulFlags=0x%08X", pCacheUsage->m_ulFlags));        }        else        {             LOG ("    No usage stats");        }#endif // ENFORCE_SIZE_LIMIT    }    if (rc != DB_NOTFOUND)    {        LOGX ((szDbgTemp, "*** DB sequential get failed *** [%d]", (int)rc));    }    #ifdef ENFORCE_SIZE_LIMIT    // The ranked list of deletion candidates already exists, use it    if (ulDbSize < m_ulMaxCacheSize)    {        LOGX ((szDbgTemp, "$$$ The cache size is within bounds [%lu vs %lu]", ulDbSize, m_ulMaxCacheSize));    }    else    // the array needs to be sorted    {        //FNH Find PN routine to sort list        for (INT32 ulOne = 0; ulOne < BUMP_LIMIT; ulOne++)        {             for (INT32 ulTwo = ulOne + 1; ulTwo < BUMP_LIMIT; ulTwo++)             {                 if (bumpList[ulOne].ulRank < bumpList[ulTwo].ulRank)                 {                  UINT32 ulTempRank      = bumpList[ulOne].ulRank;                  UINT32 ulTempSize      = bumpList[ulOne].ulSize;                  char*  pszTempUrl      = bumpList[ulOne].pszUrl;                  bumpList[ulOne].ulRank = bumpList[ulTwo].ulRank;                  bumpList[ulOne].ulSize = bumpList[ulTwo].ulSize;                  bumpList[ulOne].pszUrl = bumpList[ulTwo].pszUrl;                  bumpList[ulTwo].ulRank = ulTempRank;                  bumpList[ulTwo].ulSize = ulTempSize;                  bumpList[ulTwo].pszUrl = pszTempUrl;                 }             }        }    }    // start purging entries until the size is right    for (INT32 ulVictim = 0; ulVictim < BUMP_LIMIT; ulVictim++)    {        if (bumpList[ulVictim].pszUrl == NULL)             break;        if (ulDbSize < m_ulMaxCacheSize - (m_ulMaxCacheSize / 20))              break;        LOGX ((szDbgTemp, "$$$ Bumping cache entry ranked %6d, Size = %6d, '%s'",                bumpList[ulVictim].ulRank, bumpList[ulVictim].ulSize, bumpList[ulVictim].pszUrl));        ulDbSize -= bumpList[ulVictim].ulSize;        DBT dbtDelKey   = { bumpList[ulVictim].pszUrl, strlen(bumpList[ulVictim].pszUrl) };        m_pDbData->del(m_pDbData, &dbtDelKey, 0);        // Remove expired entry from cache        m_pDbUsage->del(m_pDbUsage, &dbtDelKey, 0);      // Remove expired entry from cache        m_pDbHeader->del(m_pDbHeader, &dbtDelKey, 0);    // Remove expired entry from cache    }    #endif // ENFORCE_SIZE_LIMIT    sync(0);  // Update disk file    // delete any urls still left in the bumpList    for (ulIndex = 0; ulIndex < BUMP_LIMIT; ulIndex++)    {	HX_VECTOR_DELETE(bumpList[ulIndex].pszUrl);    }    LOG ("... CleanCache() returns OK");    return(HXR_OK);}/* * These are wrappers for the Berkeley DB C API.  They are fairly thin, but do * have defaults for several parameters. * * *** Note *** * In order to make the DB_TXN* argument optional, its location had to be moved * to be after the DBT* arguments.  This means the functions are not drop-in * replacements for Berkeley DB calls, the arguments are in a different order. * (Of course, the lack of a DB* argument already changed the arg list.) */HX_RESULTCCacheEntry::get (DBT *pdbtKey, DBT *pdbtHeader, DBT *pdbtContent, DB_TXN* pTxnid, UINT32 ulFlags){    HX_RESULT rc = HXR_OK;        LOG ("get()");    if (m_pDbHeader == NULL || m_pDbData == NULL)    {        rc = HXR_FAIL;    }    else if ((rc = m_pDbHeader->get (m_pDbHeader, pdbtKey, pdbtHeader, ulFlags)) != 0)    {        LOG ("*** Get of header failed");    }    else if ((rc = m_pDbData->get (m_pDbData, pdbtKey, pdbtContent, ulFlags)) != 0)    {        LOG ("*** Get of content failed");    }    else    {        // This may not be needed        m_pCacheHeader = (PCacheHeader) pdbtHeader->data;    }        LOG (rc ? "    Miss" : "    Hit");    return(rc);}HX_RESULTCCacheEntry::put (DB* pDb, DBT *pdbtKey, DBT *pdbtHeader, DBT *pdbtContent, DB_TXN* pTxnid, UINT32 ulFlags){    HX_RESULT rc = HXR_FAIL;        if (m_pDbHeader == NULL || m_pDbData == NULL)    {        LOG ("*** Error putting cache entry (NULL database handles)");        return(HXR_FAIL);    }    if (pdbtHeader == NULL || pdbtContent == NULL)    {        LOG ("*** Error putting cache entry (NULL parameters)");        return(HXR_FAIL);    }    if ((rc = m_pDbHeader->put (m_pDbHeader, pdbtKey, pdbtHeader, ulFlags)) == HXR_OK)    {        rc = m_pDbData->put (m_pDbData, pdbtKey, pdbtContent, ulFlags);    }    if (rc != HXR_OK)        {        LOG ("*** Put failed");    }    sync (0);        return(rc);}#if 0        int (*close)    __P((struct __db *));        int (*del)      __P((const struct __db *, const DBT *, UINT32));        int (*get)      __P((const struct __db *, const DBT *, DBT *, UINT32));        int (*put)      __P((const struct __db *, DBT *, const DBT *, UINT32));        int (*seq)      __P((const struct __db *, DBT *, DBT *, UINT32));        int (*sync)     __P((const struct __db *, UINT32));#endifUINT32CCacheEntry::del (DBT* pdbtKey, DB_TXN* pTxnid, UINT32 ulFlags){       if (m_pDbHeader)	m_pDbHeader->del (m_pDbHeader, pdbtKey, ulFlags);    if (m_pDbData)	m_pDbData->del (m_pDbData, pdbtKey, ulFlags);    if (m_pDbUsage)	m_pDbUsage->del (m_pDbUsage, pdbtKey, ulFlags);    return HXR_OK;}UINT32CCacheEntry::close (UINT32 ulFlags){    if (m_pDbHeader)    {	m_pDbHeader->close (m_pDbHeader);	m_pDbHeader = NULL;    }    if (m_pDbData)    {	m_pDbData->close (m_pDbData);	m_pDbData = NULL;    }    if (m_pDbUsage)    {	m_pDbUsage->close (m_pDbUsage);	m_pDbUsage = NULL;    }    return HXR_OK;}UINT32CCacheEntry::sync (UINT32 ulFlags){    if (m_pDbHeader)	m_pDbHeader->sync (m_pDbHeader, ulFlags);    if (m_pDbData)	m_pDbData->sync (m_pDbData, ulFlags);    if (m_pDbUsage)	m_pDbUsage->sync (m_pDbUsage, ulFlags);    return HXR_OK;}#ifdef _WIN32UINT32GetFreeMbyteCount (const char *pDirectoryName){    BOOL	bOK                           = FALSE;    BOOL	bUseExtFunc		      = FALSE;    ULONG32	ulFreeMbytes                  = 0;    ULONGLONG	ullFreeBytesAvailableToCaller = 0;    ULONGLONG	ullTotalNumberOfBytes         = 0;    ULONGLONG	ullTotalNumberOfFreeBytes     = 0;    DWORD	dwSectorsPerCluster = 0;	    // pointer to sectors per cluster    DWORD	dwBytesPerSector = 0;		    // pointer to bytes per sector    DWORD	dwNumberOfFreeClusters = 0;	    // pointer to number of free clusters    DWORD	dwTotalNumberOfClusters = 0;	    // pointer to total number of clusters	    LPVOID	lpMsgBuf = NULL;    CHAR	pucDisk[4]                    = { 0 };        GETDISKFREESPACEEX	_getDiskFreeSpaceEx = NULL;    HINSTANCE		hLib		    = NULL;        /*      * If there is an error creating the database, we do not store the      * directory name in m_pszDbDir in CCacheEntry constructor     */    HX_ASSERT(pDirectoryName != NULL);    if (pDirectoryName == NULL)    {	return 0;    }    strncpy (pucDisk, pDirectoryName, 3); /* Flawfinder: ignore */    pucDisk[3] = '\0';    // Windows 95 OSR2: The GetDiskFreeSpaceEx function is available on Windows 95     // systems beginning with OEM Service Release 2 (OSR2).     //    // To determine whether GetDiskFreeSpaceEx is available, call the LoadLibrary     // load the KERNEL32.DLL file, then call the GetProcAddress function to obtain     // an address for GetDiskFreeSpaceEx. If GetProcAddress fails, use the     // GetDiskFreeSpace function instead of GetDiskFreeSpaceEx.    //    // NOTE: if we don't do so, the httpfsys will not be loaded by the plugin handler!!    if (!(hLib = LoadLibrary(OS_STRING("kernel32.dll"))))    {	goto cleanup;    }        _getDiskFreeSpaceEx = (GETDISKFREESPACEEX)GetProcAddress(hLib, OS_STRING("GetDiskFreeSpaceExA"));    if (_getDiskFreeSpaceEx)    {	bOK = _getDiskFreeSpaceEx(OS_STRING(pucDisk),				  (PULARGE_INTEGER) &ullFreeBytesAvailableToCaller,				  (PULARGE_INTEGER) &ullTotalNumberOfBytes,				  (PULARGE_INTEGER) &ullTotalNumberOfFreeBytes);	if (bOK)	{	    ulFreeMbytes = (ULONG32)(ullTotalNumberOfFreeBytes >> 20);	    goto cleanup;	}    }#ifndef _WINCE    bOK = GetDiskFreeSpace(OS_STRING(pucDisk),                          (LPDWORD) &dwSectorsPerCluster,                          (LPDWORD) &dwBytesPerSector,                          (LPDWORD) &dwNumberOfFreeClusters,			  (LPDWORD) &dwTotalNumberOfClusters);    if (bOK)    {        ulFreeMbytes = (ULONG32)(dwBytesPerSector * dwSectorsPerCluster * dwNumberOfFreeClusters);    }#endif /* _WINCE */cleanup:    if (hLib)    {	FreeLibrary(hLib);    }    return(ulFreeMbytes);}            #elif defined(_MACINTOSH)UINT32GetFreeMbyteCount (const char *pDirectoryName){    ULONG32     ulFreeMbytes                = 0;    HParamBlockRec	volPB;    OSErr	error;    UCHAR volName[256];    ULONG32 ullTotalNumberOfFreeBytes     = 0;    size_t len;        /*      * If there is an error creating the database, we do not store the      * directory name in m_pszDbDir in CCacheEntry constructor     */    HX_ASSERT(pDirectoryName != NULL);    if (pDirectoryName == NULL)    {      return 0;    }	/*	 * Volume name is length delimited! (Note that this is not used as an input parameter.)	 * Note also that this routine always returns the free byte of the first mounted volume	 * (default volume, don't confuse the directory with the volume name).  --wy 2/9/00 	 */	len = strlen(pDirectoryName);	if(len > 255)		len = 255;	memcpy(volName+1, pDirectoryName, len); /* Flawfinder: ignore */	volName[0] = (UCHAR)len;    volPB.volumeParam.ioNamePtr = volName;    volPB.volumeParam.ioVRefNum = 0;    volPB.volumeParam.ioVolIndex = 1;	        error = PBHGetVInfo(&volPB,false);        if(error == noErr)    {	ullTotalNumberOfFreeBytes = volPB.volumeParam.ioVFrBlk * volPB.volumeParam.ioVAlBlkSiz;        ulFreeMbytes = (ULONG32)(ullTotalNumberOfFreeBytes >> 20);    }    return(ulFreeMbytes);} #elseUINT32GetFreeMbyteCount (const char *pDirectoryName){    return(DISK_FREE_LOW * 2);}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -