mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-29 17:40:42 +00:00
NuCache Streams now hold the filename for smoother reopening. Not in build as yet.
This commit is contained in:
parent
5254996718
commit
8eb4d30a1b
6
network/cache/nu/public/nsFileStream.h
vendored
6
network/cache/nu/public/nsFileStream.h
vendored
@ -28,11 +28,12 @@
|
||||
//#include "nsISupports.h"
|
||||
#include "nsStream.h"
|
||||
#include "prio.h" // PRFileDesc
|
||||
|
||||
class nsFileStream: public nsStream
|
||||
{
|
||||
|
||||
public:
|
||||
nsFileStream(PRFileDesc* i_pFile);
|
||||
nsFileStream(const char* i_Filename);
|
||||
virtual ~nsFileStream();
|
||||
/*
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID,
|
||||
@ -48,10 +49,13 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
PRBool Open(void);
|
||||
|
||||
private:
|
||||
nsFileStream(const nsFileStream& o);
|
||||
nsFileStream& operator=(const nsFileStream& o);
|
||||
PRFileDesc* m_pFile;
|
||||
char* m_pFilename;
|
||||
};
|
||||
|
||||
inline
|
||||
|
17
network/cache/nu/src/nsDiskModule.cpp
vendored
17
network/cache/nu/src/nsDiskModule.cpp
vendored
@ -295,25 +295,26 @@ nsStream* nsDiskModule::GetStreamFor(const nsCacheObject* i_pObject)
|
||||
MonitorLocker ml(this);
|
||||
if (i_pObject)
|
||||
{
|
||||
/*
|
||||
if (Contains((nsCacheObject*)i_pObject))
|
||||
{
|
||||
nsStream* pStream = i_pObject->Stream();
|
||||
if (pStream)
|
||||
return pStream;
|
||||
}
|
||||
*/
|
||||
|
||||
nsStream* pStream = i_pObject->Stream();
|
||||
if (pStream)
|
||||
return pStream;
|
||||
|
||||
PR_ASSERT(*i_pObject->Filename());
|
||||
|
||||
char* fullname = FullFilename(i_pObject->Filename());
|
||||
|
||||
// Set up a new stream for this object
|
||||
PRFileDesc* pFD = PR_Open(
|
||||
fullname ? fullname : i_pObject->Filename(),
|
||||
PR_CREATE_FILE | PR_RDWR,
|
||||
600);// Read and write by owner only
|
||||
|
||||
if (pFD)
|
||||
if (fullname)
|
||||
{
|
||||
return new nsFileStream(pFD);
|
||||
return new nsFileStream(fullname);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
52
network/cache/nu/src/nsFileStream.cpp
vendored
52
network/cache/nu/src/nsFileStream.cpp
vendored
@ -18,16 +18,27 @@
|
||||
*/
|
||||
|
||||
#include "nsFileStream.h"
|
||||
#include "plstr.h"
|
||||
#include "prlog.h"
|
||||
|
||||
nsFileStream::nsFileStream(PRFileDesc* i_pFile):m_pFile(i_pFile)
|
||||
nsFileStream::nsFileStream(const char* i_Filename):m_pFile(0),m_pFilename(0)
|
||||
{
|
||||
PR_ASSERT(m_pFile);
|
||||
PR_ASSERT(i_Filename);
|
||||
if (i_Filename)
|
||||
{
|
||||
m_pFilename = new char[PL_strlen(i_Filename)+1];
|
||||
PL_strcpy(m_pFilename, i_Filename);
|
||||
Open();
|
||||
}
|
||||
}
|
||||
|
||||
nsFileStream::~nsFileStream()
|
||||
{
|
||||
//close the file if not closed. todo
|
||||
if (m_pFilename)
|
||||
{
|
||||
delete[] m_pFilename;
|
||||
m_pFilename = 0;
|
||||
}
|
||||
if (m_pFile)
|
||||
PR_Close(m_pFile);
|
||||
}
|
||||
@ -54,27 +65,40 @@ nsresult nsFileStream::QueryInterface(const nsIID& aIID,
|
||||
}
|
||||
*/
|
||||
|
||||
PRInt32 nsFileStream::Read(void* o_Buffer, PRUint32 i_Len)
|
||||
PRBool nsFileStream::Open()
|
||||
{
|
||||
if (m_pFile)
|
||||
PR_Close(m_pFile);
|
||||
PR_ASSERT(m_pFilename);
|
||||
if (m_pFilename)
|
||||
{
|
||||
return PR_Read(m_pFile, o_Buffer, i_Len);
|
||||
m_pFile = PR_Open(
|
||||
m_pFilename,
|
||||
PR_CREATE_FILE | PR_RDWR,
|
||||
600);// Read and write by owner only
|
||||
|
||||
PR_ASSERT(m_pFile);
|
||||
if (m_pFile)
|
||||
return PR_TRUE;
|
||||
}
|
||||
return 0;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRInt32 nsFileStream::Read(void* o_Buffer, PRUint32 i_Len)
|
||||
{
|
||||
if (!m_pFile && !Open())
|
||||
return 0;
|
||||
return PR_Read(m_pFile, o_Buffer, i_Len);
|
||||
}
|
||||
|
||||
void nsFileStream::Reset()
|
||||
{
|
||||
return;
|
||||
if (m_pFile)
|
||||
PR_Close(m_pFile);
|
||||
Open();
|
||||
}
|
||||
|
||||
PRInt32 nsFileStream::Write(const void* i_Buffer, PRUint32 i_Len)
|
||||
{
|
||||
if (m_pFile)
|
||||
{
|
||||
return PR_Write(m_pFile, i_Buffer, i_Len);
|
||||
}
|
||||
return 0;
|
||||
if (!m_pFile && !Open())
|
||||
return 0;
|
||||
return PR_Write(m_pFile, i_Buffer, i_Len);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user