rv = nsComponentManager::CreateInstance( "@mozilla.org/network/memory-cache-transport;1", nsnull, NS_GET_IID(nsITransport), getter_AddRefs(transport));
transport = do_CreateInstance( "@mozilla.org/network/memory-cache-transport;1", &rv);
nsresult TestMCTransport(const char *filename){    nsresult rv = NS_OK;    nsCOMPtr<nsITransport> transport;#ifdef USE_CREATE_INSTANCE    rv = nsComponentManager::CreateInstance(                    "@mozilla.org/network/memory-cache-transport;1",                    nsnull,                    NS_GET_IID(nsITransport),                    getter_AddRefs(transport));    if (NS_FAILED(rv))        return rv;#else    nsCOMPtr<nsICacheService> serv(do_GetService(kCacheServiceCID, &rv));    if (NS_FAILED(rv)) return rv;    rv = serv->CreateSession("TestMCTransport",                             nsICache::STORE_IN_MEMORY, PR_TRUE,                             &session);    if (NS_FAILED(rv)) return rv;    rv = session->OpenCacheEntry(filename,                                 nsICache::ACCESS_READ_WRITE,                                 nsICache::BLOCKING,                                 &desc);    if (NS_FAILED(rv)) return rv;    rv = desc->MarkValid();    if (NS_FAILED(rv)) return rv;    rv = desc->GetTransport(getter_AddRefs(transport));    if (NS_FAILED(rv)) return rv;#endif    nsCOMPtr<nsIOutputStream> os;    rv = transport->OpenOutputStream(0, (PRUint32) -1, 0, getter_AddRefs(os));    if (NS_FAILED(rv)) return rv;    char *out = PR_smprintf("%s.out", filename);    nsCOMPtr<nsIStreamListener> listener = new TestListener(out);    if (!listener)        return NS_ERROR_OUT_OF_MEMORY;    nsCOMPtr<nsIRequest> req;    rv = transport->AsyncRead(listener, nsnull, 0, (PRUint32) -1, 0, getter_AddRefs(req));    if (NS_FAILED(rv)) return rv;    FILE *file = fopen(filename, "r");    if (!file)        return NS_ERROR_FILE_NOT_FOUND;    char buf[256];    PRUint32 count, total=0;    while ((count = fread(buf, 1, sizeof(buf), file)) > 0) {        printf("writing %u bytes\n", count);        total += count;        rv = os->Write(buf, count, &count);        if (NS_FAILED(rv)) return rv;        // process an event        PLEvent *event = nsnull;        gEventQ->GetEvent(&event);        if (event) gEventQ->HandleEvent(event);    }    printf("wrote %u bytes\n", total);    return rv;}