rv = Flush(); if (rv == NS_BASE_STREAM_WOULD_BLOCK || NS_FAILED(rv))
nsresult rv2 = Flush(); if (rv2 == NS_BASE_STREAM_WOULD_BLOCK || NS_FAILED(rv2))
nsPipe::nsPipeOutputStream::WriteSegments(nsReadSegmentFun reader,                                          void* closure,                                          PRUint32 count,                                          PRUint32 *writeCount){    nsresult rv;    nsPipe* pipe = GET_OUTPUTSTREAM_PIPE(this);    {        nsAutoCMonitor mon(pipe);        if (NS_FAILED(pipe->mCondition)) {            rv = pipe->mCondition;            goto done;        }        *writeCount = 0;        while (count > 0) {            PRUint32 writeBufLen;            char* writeBuf;            rv = pipe->GetWriteSegment(&writeBuf, &writeBufLen);            if (NS_FAILED(rv))                goto done;            if (writeBufLen == 0) {                rv = Flush();                if (rv == NS_BASE_STREAM_WOULD_BLOCK || NS_FAILED(rv))                    goto done;                // else we flushed, so go around again                continue;            }            writeBufLen = PR_MIN(writeBufLen, count);            while (writeBufLen > 0) {                PRUint32 readCount = 0;                rv = reader(closure, writeBuf, *writeCount, writeBufLen, &readCount);                if (NS_FAILED(rv)) {                    // save the failure condition so that we can get it again later                    pipe->mCondition = rv;                    goto done;                }                if (readCount == 0) {                    // if the place we're putting the data would block (probably ran                    // out of room) just return what we were able to write so far                    rv = Flush();                    if (rv == NS_BASE_STREAM_WOULD_BLOCK || NS_FAILED(rv))                        goto done;                    // else we flushed, so go around again                    continue;                }                NS_ASSERTION(readCount <= writeBufLen, "reader returned bad readCount");                writeBuf += readCount;                writeBufLen -= readCount;                *writeCount += readCount;                count -= readCount;                pipe->mWriteCursor += readCount;            }            if (pipe->mWriteCursor == pipe->mWriteLimit) {                pipe->mWriteCursor =  nsnull;                pipe->mWriteLimit =  nsnull;            }        }      done:        if (mBlocking && rv == NS_BASE_STREAM_WOULD_BLOCK && *writeCount > 0) {            mon.Notify();       // wake up reader        }    }   // exit monitor    if (pipe->mObserver && *writeCount > 0) {        pipe->mObserver->OnWrite(*writeCount);    }    return *writeCount == 0 ? rv : NS_OK;}