nsCOMPtr<nsISocketTransportService> sts =
nsCOMPtr<nsPISocketTransportService> sts =
main(int argc, char* argv[]){    if (test_common_init(&argc, &argv) != 0)        return -1;    nsresult rv;    if (argc < 4) {        printf("usage: TestSocketTransport <host> <port> <path>\n");        return -1;    }    {        nsCOMPtr<nsIServiceManager> servMan;        NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull);        nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);        NS_ASSERTION(registrar, "Null nsIComponentRegistrar");        if (registrar)            registrar->AutoRegister(nsnull);#if defined(PR_LOGGING)        gTestLog = PR_NewLogModule("Test");#endif        nsCOMPtr<nsIEventQueueService> eventQService =                 do_GetService(kEventQueueServiceCID, &rv);        if (NS_FAILED(rv)) return rv;        rv = eventQService->CreateMonitoredThreadEventQueue();        if (NS_FAILED(rv)) return rv;        rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ);        if (NS_FAILED(rv)) return rv;        nsCOMPtr<nsISocketTransportService> sts =            do_GetService(kSocketTransportServiceCID, &rv);        if (NS_FAILED(rv)) return rv;        LOG(("phase 1 tests...\n"));        LOG(("flags = { OPEN_UNBUFFERED, OPEN_UNBUFFERED }\n"));        rv = RunCloseTest(sts, argv[1], atoi(argv[2]),                          nsITransport::OPEN_UNBUFFERED,                          nsITransport::OPEN_UNBUFFERED);        NS_ASSERTION(NS_SUCCEEDED(rv), "RunCloseTest failed");        LOG(("flags = { OPEN_BUFFERED, OPEN_UNBUFFERED }\n"));        rv = RunCloseTest(sts, argv[1], atoi(argv[2]),                          0 /* nsITransport::OPEN_BUFFERED */,                          nsITransport::OPEN_UNBUFFERED);        NS_ASSERTION(NS_SUCCEEDED(rv), "RunCloseTest failed");        LOG(("flags = { OPEN_UNBUFFERED, OPEN_BUFFERED }\n"));        rv = RunCloseTest(sts, argv[1], atoi(argv[2]),                          nsITransport::OPEN_UNBUFFERED,                          0 /*nsITransport::OPEN_BUFFERED */);        NS_ASSERTION(NS_SUCCEEDED(rv), "RunCloseTest failed");        LOG(("flags = { OPEN_BUFFERED, OPEN_BUFFERED }\n"));        rv = RunCloseTest(sts, argv[1], atoi(argv[2]),                          0 /*nsITransport::OPEN_BUFFERED */,                          0 /*nsITransport::OPEN_BUFFERED */);        NS_ASSERTION(NS_SUCCEEDED(rv), "RunCloseTest failed");        LOG(("calling Shutdown on socket transport service:\n"));        sts->Shutdown();        LOG(("calling Init on socket transport service:\n"));        sts->Init();        LOG(("phase 2 tests...\n"));        LOG(("flags = { OPEN_UNBUFFERED, OPEN_UNBUFFERED }\n"));        rv = RunTest(sts, argv[1], atoi(argv[2]), argv[3],                     nsITransport::OPEN_UNBUFFERED,                     nsITransport::OPEN_UNBUFFERED);        NS_ASSERTION(NS_SUCCEEDED(rv), "RunTest failed");        LOG(("flags = { OPEN_BUFFERED, OPEN_UNBUFFERED }\n"));        rv = RunTest(sts, argv[1], atoi(argv[2]), argv[3],                     0 /* nsITransport::OPEN_BUFFERED */,                     nsITransport::OPEN_UNBUFFERED);        NS_ASSERTION(NS_SUCCEEDED(rv), "RunTest failed");        LOG(("flags = { OPEN_UNBUFFERED, OPEN_BUFFERED }\n"));        rv = RunTest(sts, argv[1], atoi(argv[2]), argv[3],                     nsITransport::OPEN_UNBUFFERED,                     0 /*nsITransport::OPEN_BUFFERED */);        NS_ASSERTION(NS_SUCCEEDED(rv), "RunTest failed");        LOG(("flags = { OPEN_BUFFERED, OPEN_BUFFERED }\n"));        rv = RunTest(sts, argv[1], atoi(argv[2]), argv[3],                     0 /*nsITransport::OPEN_BUFFERED */,                     0 /*nsITransport::OPEN_BUFFERED */);        NS_ASSERTION(NS_SUCCEEDED(rv), "RunTest failed");        LOG(("waiting 1 second before calling Shutdown...\n"));        PR_Sleep(PR_SecondsToInterval(1));        LOG(("calling Shutdown on socket transport service:\n"));        sts->Shutdown();        NS_RELEASE(gEventQ);        // give background threads a chance to finish whatever work they may        // be doing.        LOG(("waiting 1 second before exiting...\n"));        PR_Sleep(PR_SecondsToInterval(1));    } // this scopes the nsCOMPtrs    // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM    rv = NS_ShutdownXPCOM(nsnull);    NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");    return NS_OK;}