printf("wrote %d bytes\n", total);
TestShortWrites(nsIInputStream* in, nsIOutputStream* out){    nsresult rv;    nsIThread* thread;    nsShortReader* receiver = new nsShortReader(in);    if (receiver == nsnull) return NS_ERROR_OUT_OF_MEMORY;    NS_ADDREF(receiver);    rv = NS_NewThread(&thread, receiver);    if (NS_FAILED(rv)) return rv;    for (PRUint32 i = 0; i < ITERATIONS/100; i++) {        PRUint32 writeCount;        char* buf = PR_smprintf("%d %s", i, kTestPattern);        PRUint32 len = nsCRT::strlen(buf);        len = len * rand() / RAND_MAX;        len = PR_MAX(1, len);        rv = out->Write(buf, len, &writeCount);        if (NS_FAILED(rv)) return rv;        NS_ASSERTION(writeCount == len, "didn't write enough");        if (gTrace)            printf("wrote %d bytes: %s\n", writeCount, buf);        PR_smprintf_free(buf);        out->Flush();        PRUint32 received = receiver->WaitForReceipt();        NS_ASSERTION(received == writeCount, "received wrong amount");    }    rv = out->Close();    if (NS_FAILED(rv)) return rv;    thread->Join();    NS_RELEASE(thread);    NS_RELEASE(receiver);    return NS_OK;}