зеркало из https://github.com/mozilla/pjs.git
add ability to reuse file transports r=dougt,sr=darin 74597
This commit is contained in:
Родитель
3db33a040e
Коммит
c65da247c9
|
@ -44,7 +44,8 @@ interface nsIFileTransportService : nsISupports
|
|||
nsITransport createTransportFromStream(in string name,
|
||||
in nsIInputStream fromStream,
|
||||
in string contentType,
|
||||
in long contentLength);
|
||||
in long contentLength,
|
||||
in boolean closeStreamWhenDone);
|
||||
|
||||
nsITransport createTransportFromStreamIO(in nsIStreamIO io);
|
||||
|
||||
|
|
|
@ -216,6 +216,7 @@ nsFileTransport::nsFileTransport()
|
|||
mSuspendCount(0),
|
||||
mLock(nsnull),
|
||||
mActive(PR_FALSE),
|
||||
mCloseStreamWhenDone(PR_TRUE),
|
||||
mStatus(NS_OK),
|
||||
mOffset(0),
|
||||
mTotalAmount(-1),
|
||||
|
@ -245,13 +246,14 @@ nsFileTransport::Init(nsFileTransportService *aService, nsIFile* file, PRInt32 i
|
|||
|
||||
nsresult
|
||||
nsFileTransport::Init(nsFileTransportService *aService, const char* name, nsIInputStream* inStr,
|
||||
const char* contentType, PRInt32 contentLength)
|
||||
const char* contentType, PRInt32 contentLength, PRBool closeStreamWhenDone)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIInputStreamIO> io;
|
||||
rv = NS_NewInputStreamIO(getter_AddRefs(io),
|
||||
name, inStr, contentType, contentLength);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
mCloseStreamWhenDone = closeStreamWhenDone;
|
||||
return Init(aService, io);
|
||||
}
|
||||
|
||||
|
@ -502,7 +504,6 @@ nsFileTransport::AsyncRead(nsIStreamListener *aListener,
|
|||
mBufferSegmentSize,
|
||||
mBufferMaxSize);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_ASSERTION(mContext == nsnull, "context not released");
|
||||
mContext = aContext;
|
||||
mOffset = aTransferOffset;
|
||||
|
@ -781,7 +782,7 @@ nsFileTransport::Process(void)
|
|||
LOG(("nsFileTransport: END_READ [this=%x %s] status=%x\n",
|
||||
this, mStreamName.get(), mStatus));
|
||||
|
||||
#if defined (DEBUG_dougt) || defined (DEBUG_warren)
|
||||
#if defined (DEBUG_dougt) || defined (DEBUG_warren) || defined (DEBUG_bienvenu)
|
||||
NS_ASSERTION(mTransferAmount <= 0 || NS_FAILED(mStatus), "didn't transfer all the data");
|
||||
#endif
|
||||
if (mTransferAmount > 0 && NS_SUCCEEDED(mStatus)) {
|
||||
|
@ -793,23 +794,31 @@ nsFileTransport::Process(void)
|
|||
mStatus = NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
if (mListener) {
|
||||
mListener->OnStopRequest(this, mContext, mStatus);
|
||||
mListener = 0;
|
||||
}
|
||||
if (mProgress) {
|
||||
nsAutoString fileName;
|
||||
fileName.AssignWithConversion(mStreamName);
|
||||
mProgress->OnStatus(this, mContext,
|
||||
NS_NET_STATUS_READ_FROM,
|
||||
fileName.GetUnicode());
|
||||
}
|
||||
mContext = 0;
|
||||
// need to close before calling OnStopRequest, in case the listener
|
||||
// is reusing the stream.
|
||||
mXferState = CLOSING;
|
||||
DoClose();
|
||||
nsCOMPtr <nsISupports> saveContext = mContext;
|
||||
nsCOMPtr <nsIStreamListener> saveListener = mListener;
|
||||
mListener = nsnull;
|
||||
mContext = nsnull;
|
||||
|
||||
// close the data source
|
||||
NS_IF_RELEASE(mSourceWrapper);
|
||||
mSourceWrapper = nsnull;
|
||||
mXferState = CLOSING;
|
||||
|
||||
if (saveListener) {
|
||||
saveListener->OnStopRequest(this, saveContext, mStatus);
|
||||
saveListener = 0;
|
||||
}
|
||||
if (mProgress) {
|
||||
nsAutoString fileName;
|
||||
fileName.AssignWithConversion(mStreamName);
|
||||
mProgress->OnStatus(this, saveContext,
|
||||
NS_NET_STATUS_READ_FROM,
|
||||
fileName.GetUnicode());
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1000,14 +1009,18 @@ nsFileTransport::Process(void)
|
|||
void
|
||||
nsFileTransport::DoClose(void)
|
||||
{
|
||||
LOG(("nsFileTransport: CLOSING [this=%x %s] status=%x\n",
|
||||
this, mStreamName.get(), mStatus));
|
||||
if (mCloseStreamWhenDone)
|
||||
{
|
||||
LOG(("nsFileTransport: CLOSING [this=%x %s] status=%x\n",
|
||||
this, mStreamName.get(), mStatus));
|
||||
|
||||
// XXX closing the stream io prevents this file transport from being reused
|
||||
if (mStreamIO) {
|
||||
nsresult rv = mStreamIO->Close(mStatus);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unexpected Close failure");
|
||||
mStreamIO = 0;
|
||||
// XXX closing the stream io prevents this file transport from being reused
|
||||
if (mStreamIO) {
|
||||
nsresult rv = NS_OK;
|
||||
rv = mStreamIO->Close(mStatus);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unexpected Close failure");
|
||||
mStreamIO = 0;
|
||||
}
|
||||
}
|
||||
mXferState = CLOSED;
|
||||
|
||||
|
|
|
@ -76,7 +76,8 @@ public:
|
|||
nsresult Init(nsFileTransportService *aService, const char* name,
|
||||
nsIInputStream* fromStream,
|
||||
const char* contentType,
|
||||
PRInt32 contentLength);
|
||||
PRInt32 contentLength,
|
||||
PRBool closeStreamWhenDone);
|
||||
nsresult Init(nsFileTransportService *aService, nsIStreamIO* io);
|
||||
|
||||
void Process(void);
|
||||
|
@ -124,6 +125,8 @@ protected:
|
|||
// The transport is active if it is currently being processed by a thread.
|
||||
PRBool mActive;
|
||||
|
||||
// If FALSE, then the caller can reuse the file transport
|
||||
PRBool mCloseStreamWhenDone;
|
||||
// state variables:
|
||||
nsresult mStatus;
|
||||
PRUint32 mOffset;
|
||||
|
|
|
@ -107,6 +107,7 @@ nsFileTransportService::CreateTransportFromStream(const char* name,
|
|||
nsIInputStream *fromStream,
|
||||
const char* contentType,
|
||||
PRInt32 contentLength,
|
||||
PRBool closeStreamWhenDone,
|
||||
nsITransport** result)
|
||||
{
|
||||
nsresult rv;
|
||||
|
@ -114,7 +115,7 @@ nsFileTransportService::CreateTransportFromStream(const char* name,
|
|||
if (trans == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(trans);
|
||||
rv = trans->Init(this, name, fromStream, contentType, contentLength);
|
||||
rv = trans->Init(this, name, fromStream, contentType, contentLength, closeStreamWhenDone);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(trans);
|
||||
return rv;
|
||||
|
|
Загрузка…
Ссылка в новой задаче