nsresult nsHttpPipeline::ReadSegments(nsAHttpSegmentReader *reader, uint32_t count, uint32_t *countRead) { LOG(("nsHttpPipeline::ReadSegments [this=%p count=%u]\n", this, count)); MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread); if (mClosed) { *countRead = 0; return mStatus; } nsresult rv; uint64_t avail = 0; if (mSendBufIn) { rv = mSendBufIn->Available(&avail); if (NS_FAILED(rv)) return rv; } if (avail == 0) { rv = FillSendBuf(); if (NS_FAILED(rv)) return rv; rv = mSendBufIn->Available(&avail); if (NS_FAILED(rv)) return rv; // return EOF if send buffer is empty if (avail == 0) { *countRead = 0; return NS_OK; } } // read no more than what was requested if (avail > count) avail = count; mReader = reader; // avail is under 4GB, so casting to uint32_t is safe rv = mSendBufIn->ReadSegments(ReadFromPipe, this, (uint32_t)avail, countRead); mReader = nullptr; return rv; }
nsresult nsHttpPipeline::ReadSegments(nsAHttpSegmentReader *reader, PRUint32 count, PRUint32 *countRead) { LOG(("nsHttpPipeline::ReadSegments [this=%x count=%u]\n", this, count)); NS_ASSERTION(PR_GetCurrentThread() == gSocketThread, "wrong thread"); if (mClosed) { *countRead = 0; return mStatus; } nsresult rv; PRUint32 avail = 0; if (mSendBufIn) { rv = mSendBufIn->Available(&avail); if (NS_FAILED(rv)) return rv; } if (avail == 0) { rv = FillSendBuf(); if (NS_FAILED(rv)) return rv; rv = mSendBufIn->Available(&avail); if (NS_FAILED(rv)) return rv; // return EOF if send buffer is empty if (avail == 0) { *countRead = 0; return NS_OK; } } // read no more than what was requested if (avail > count) avail = count; mReader = reader; rv = mSendBufIn->ReadSegments(ReadFromPipe, this, avail, countRead); mReader = nsnull; return rv; }