PRUint32 read; rv = stream->ReadSegments(ReadSegCb, &state, aCount, &read);
PRUint32 avail, read, count; rv = stream->Available(&avail); if (NS_FAILED(rv)) return rv;  count = PR_MIN(avail, aCount);  rv = stream->ReadSegments(ReadSegCb, &state, count, &read);
nsMultiplexInputStream::ReadSegments(nsWriteSegmentFun aWriter, void *aClosure,                                     PRUint32 aCount, PRUint32 *_retval){    NS_ASSERTION(aWriter, "missing aWriter");    nsresult rv;    ReadSegmentsState state;    state.mThisStream = this;    state.mOffset = 0;    state.mWriter = aWriter;    state.mClosure = aClosure;    state.mDone = PR_FALSE;        PRUint32 len;    mStreams.Count(&len);    while (mCurrentStream < len) {        nsCOMPtr<nsIInputStream> stream(do_QueryElementAt(&mStreams,                                                          mCurrentStream));        PRUint32 read;        rv = stream->ReadSegments(ReadSegCb, &state, aCount, &read);        // If we got an NS_BASE_STREAM_WOULD_BLOCK error since the reader        // didn't want any more data. This might not be an error for us if        // data was read from a previous stream in this run        if (state.mDone && rv == NS_BASE_STREAM_WOULD_BLOCK &&            !read && state.mOffset)            break;        NS_ENSURE_SUCCESS(rv, rv);        NS_ASSERTION(aCount >= read, "Read more then requested");        mStartedReadingCurrent = PR_TRUE;        state.mOffset += read;        aCount -= read;        if (state.mDone || !aCount)            break;                ++mCurrentStream;        mStartedReadingCurrent = PR_FALSE;    }    *_retval = state.mOffset;    return NS_OK;}