nsresult nsCacheEntryDescriptor::
nsInputStreamWrapper::Close()
{
    mozilla::MutexAutoLock lock(mLock);

    return Close_Locked();
}
NS_IMETHODIMP nsCacheEntryDescriptor::
nsOutputStreamWrapper::Close()
{
    mozilla::MutexAutoLock lock(mLock);

    return Close_Locked();
}
    void Process_Locked()
    {
        while (1) {
            mInputCondition = NS_OK; // reset

            PRUint32 n;
            nsresult rv = mOutput->WriteSegments(FillOutputBuffer, this, CHUNK_SIZE, &n);
            if (NS_FAILED(rv) || (n == 0)) {
                if (rv == NS_BASE_STREAM_WOULD_BLOCK)
                    mOutput->AsyncWait(this, 0, 0, nsnull);
                else if (mInputCondition == NS_BASE_STREAM_WOULD_BLOCK)
                    mInput->AsyncWait(this, 0, 0, nsnull);
                else
                    Close_Locked();
                break;
            }
        }
    }