Skip to content

Commit

Permalink
Merge pull request #10658 from peak3d/ifileopen
Browse files Browse the repository at this point in the history
support reusing of CFile::m_pFile
  • Loading branch information
peak3d committed Oct 11, 2016
2 parents d7601d0 + ccbe5aa commit 4fe6cc2
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 2 deletions.
6 changes: 6 additions & 0 deletions xbmc/filesystem/CurlFile.cpp
Expand Up @@ -1196,6 +1196,12 @@ bool CCurlFile::CReadState::ReadString(char *szLine, int iLineLength)
return (bool)((pLine - szLine) > 0);
}

bool CCurlFile::ReOpen(const CURL& url)
{
Close();
return Open(url);
}

bool CCurlFile::Exists(const CURL& url)
{
// if file is already running, get info from it
Expand Down
1 change: 1 addition & 0 deletions xbmc/filesystem/CurlFile.h
Expand Up @@ -51,6 +51,7 @@ namespace XFILE
virtual ~CCurlFile();
virtual bool Open(const CURL& url);
virtual bool OpenForWrite(const CURL& url, bool bOverWrite = false);
virtual bool ReOpen(const CURL& url);
virtual bool Exists(const CURL& url);
virtual int64_t Seek(int64_t iFilePosition, int iWhence=SEEK_SET);
virtual int64_t GetPosition();
Expand Down
17 changes: 17 additions & 0 deletions xbmc/filesystem/File.cpp
Expand Up @@ -254,6 +254,19 @@ bool CFile::Open(const std::string& strFileName, const unsigned int flags)

bool CFile::Open(const CURL& file, const unsigned int flags)
{
if (m_pFile)
{
if ((flags & READ_REOPEN) == 0)
{
CLog::Log(LOGERROR, "File::Open - already open: %s", file.GetRedacted().c_str());
return false;
}
else
{
return m_pFile->ReOpen(URIUtils::SubstitutePath(file));
}
}

m_flags = flags;
try
{
Expand All @@ -280,6 +293,10 @@ bool CFile::Open(const CURL& file, const unsigned int flags)
{
// for internet stream, if it contains multiple stream, file cache need handle it specially.
m_pFile = new CFileCache(m_flags);

if (!m_pFile)
return false;

return m_pFile->Open(url);
}
}
Expand Down
17 changes: 15 additions & 2 deletions xbmc/filesystem/File.h
Expand Up @@ -64,12 +64,25 @@ class CFile
bool CURLAddOption(XFILE::CURLOPTIONTYPE type, const char* name, const char * value);
bool CURLOpen(unsigned int flags);

/**
* Attempt to open an IFile instance.
* @param file reference to CCurl file description
* @param flags see IFileTypes.h
* @return true on success, false otherwise
*
* Remarks: Open can only be called once. Calling
* Open() on an already opened file will fail
* exept flag READ_REOPEN is set and the underlying
* file has an implementation of ReOpen().
*/
bool Open(const CURL& file, const unsigned int flags = 0);
bool Open(const std::string& strFileName, const unsigned int flags = 0);

bool OpenForWrite(const CURL& file, bool bOverWrite = false);
bool OpenForWrite(const std::string& strFileName, bool bOverWrite = false);

ssize_t LoadFile(const CURL &file, auto_buffer& outputBuffer);

bool Open(const std::string& strFileName, const unsigned int flags = 0);
bool OpenForWrite(const std::string& strFileName, bool bOverWrite = false);
/**
* Attempt to read bufSize bytes from currently opened file into buffer bufPtr.
* @param bufPtr pointer to buffer
Expand Down
1 change: 1 addition & 0 deletions xbmc/filesystem/IFile.h
Expand Up @@ -61,6 +61,7 @@ class IFile

virtual bool Open(const CURL& url) = 0;
virtual bool OpenForWrite(const CURL& url, bool bOverWrite = false) { return false; };
virtual bool ReOpen(const CURL& url) { return false; };
virtual bool Exists(const CURL& url) = 0;
/**
* Fills struct __stat64 with information about file specified by url.
Expand Down
3 changes: 3 additions & 0 deletions xbmc/filesystem/IFileTypes.h
Expand Up @@ -49,6 +49,9 @@ namespace XFILE
/* indicate that caller will do write operations before reading */
static const unsigned int READ_AFTER_WRITE = 0x80;

/* indicate that caller want to reopen a file if its already open */
static const unsigned int READ_REOPEN = 0x100;

struct SNativeIoControl
{
unsigned long int request;
Expand Down

0 comments on commit 4fe6cc2

Please sign in to comment.