if (NS_FAILED(rv))
if (rv == NS_BASE_STREAM_WOULD_BLOCK || NS_FAILED(rv))
nsPipe::nsPipeInputStream::ReadSegments(nsWriteSegmentFun writer,                                         void* closure,                                         PRUint32 count,                                        PRUint32 *readCount){    nsPipe* pipe = GET_INPUTSTREAM_PIPE(this);    nsAutoCMonitor mon(pipe);    nsresult rv = NS_OK;    PRUint32 readBufferLen;    const char* readBuffer;    *readCount = 0;    while (count > 0) {        rv = pipe->GetReadSegment(0, &readBuffer, &readBufferLen);        if (NS_FAILED(rv))            goto done;        if (readBufferLen == 0) {            rv = pipe->mCondition;            if (*readCount > 0 || NS_FAILED(rv))                goto done;      // don't Fill if we've got something            rv = Fill();            if (NS_FAILED(rv))                 goto done;            // else we filled the pipe, so go around again            continue;        }        readBufferLen = PR_MIN(readBufferLen, count);        while (readBufferLen > 0) {            PRUint32 writeCount;            rv = writer(closure, readBuffer, *readCount, readBufferLen, &writeCount);            NS_ASSERTION(rv != NS_BASE_STREAM_EOF, "Write should not return EOF");            if (NS_FAILED(rv))                 goto done;            if (writeCount == 0) {                rv = pipe->mCondition;                if (*readCount > 0 || NS_FAILED(rv))                    goto done;      // don't Fill if we've got something                rv = Fill();                if (NS_FAILED(rv))                    goto done;                // else we filled the pipe, so go around again                continue;            }            NS_ASSERTION(writeCount <= readBufferLen, "writer returned bad writeCount");            readBuffer += writeCount;            readBufferLen -= writeCount;            *readCount += writeCount;            count -= writeCount;            pipe->mReadCursor += writeCount;        }        if (pipe->mReadCursor == pipe->mReadLimit) {            pipe->mReadCursor = nsnull;            pipe->mReadLimit = nsnull;            PRBool empty = pipe->mBuffer.DeleteFirstSegment();            if (empty && pipe->mObserver) {                rv = pipe->mObserver->OnEmpty();                if (NS_FAILED(rv))                    goto done;            }        }    }  done:    if (mBlocking && rv == NS_BASE_STREAM_WOULD_BLOCK && *readCount > 0) {        mon.Notify();   // wake up writer    }    return *readCount == 0 ? rv : NS_OK;}