int64_t CSimpleFileCache::WaitForData(unsigned int iMinAvail, unsigned int iMillis) { if( iMillis == 0 || IsEndOfInput() ) return GetAvailableRead(); XbmcThreads::EndTime endTime(iMillis); while (!IsEndOfInput()) { int64_t iAvail = GetAvailableRead(); if (iAvail >= iMinAvail) return iAvail; if (!m_hDataAvailEvent->WaitMSec(endTime.MillisLeft())) return CACHE_RC_TIMEOUT; } return GetAvailableRead(); }
int64_t CSimpleFileCache::WaitForData(unsigned int iMinAvail, unsigned int iMillis) { if( iMillis == 0 || IsEndOfInput() ) return GetAvailableRead(); XbmcThreads::EndTime endTime(iMillis); unsigned int millisLeft; while ( !IsEndOfInput() && (millisLeft = endTime.MillisLeft()) > 0 ) { int64_t iAvail = GetAvailableRead(); if (iAvail >= iMinAvail) return iAvail; // busy look (sleep max 1 sec each round) if (!m_hDataAvailEvent->WaitMSec(millisLeft>1000?millisLeft:1000 )) return CACHE_RC_ERROR; } if( IsEndOfInput() ) return GetAvailableRead(); return CACHE_RC_TIMEOUT; }
int64_t CSimpleFileCache::WaitForData(unsigned int iMinAvail, unsigned int iMillis) { if( iMillis == 0 || IsEndOfInput() ) return GetAvailableRead(); unsigned int timeout = XbmcThreads::SystemClockMillis() + iMillis; unsigned int time; while ( !IsEndOfInput() && (time = XbmcThreads::SystemClockMillis()) < timeout ) { int64_t iAvail = GetAvailableRead(); if (iAvail >= iMinAvail) return iAvail; // busy look (sleep max 1 sec each round) if (!m_hDataAvailEvent->WaitMSec((timeout - time)>1000?(timeout - time):1000 )) return CACHE_RC_ERROR; } if( IsEndOfInput() ) return GetAvailableRead(); return CACHE_RC_TIMEOUT; }
int64_t CSimpleFileCache::WaitForData(unsigned int iMinAvail, unsigned int iMillis) { if( iMillis == 0 || IsEndOfInput() ) return GetAvailableRead(); unsigned int timeout = CTimeUtils::GetTimeMS() + iMillis; unsigned int time; while ( !IsEndOfInput() && (time = CTimeUtils::GetTimeMS()) < timeout ) { int64_t iAvail = GetAvailableRead(); if (iAvail >= iMinAvail) return iAvail; // busy look (sleep max 1 sec each round) DWORD dwRc = WaitForSingleObject(m_hDataAvailEvent, (timeout - time)>1000?(timeout - time):1000 ); if (dwRc == WAIT_FAILED || dwRc == WAIT_ABANDONED) return CACHE_RC_ERROR; } if( IsEndOfInput() ) return GetAvailableRead(); return CACHE_RC_TIMEOUT; }
int CSimpleFileCache::ReadFromCache(char *pBuffer, size_t iMaxSize) { int64_t iAvailable = GetAvailableRead(); if ( iAvailable <= 0 ) { return m_bEndOfInput?CACHE_RC_EOF : CACHE_RC_WOULD_BLOCK; } if ((int64_t) iMaxSize > iAvailable) iMaxSize = (size_t)iAvailable; DWORD iRead = 0; if (!ReadFile(m_hCacheFileRead, pBuffer, iMaxSize, &iRead, NULL)) { CLog::Log(LOGERROR,"CSimpleFileCache::ReadFromCache - failed to read %"PRIdS" bytes.", iMaxSize); return CACHE_RC_ERROR; } m_nReadPosition += iRead; return iRead; }