rv = gEventQ->WaitForEvent(&gEvent); rv = gEventQ->HandleEvent(gEvent); #endif
gEventQ->WaitForEvent(&gEvent); gEventQ->HandleEvent(gEvent);
main(int argc, char* argv[]){    nsresult rv;#ifdef XP_OS2_VACPP    signal(SIGSEGV, (_SigFunc)sighandler);#else    signal(SIGSEGV, sighandler);#endif#if defined(PR_LOGGING)    gTestSocketIOLog = PR_NewLogModule("TestSocketIO");#endif    if (argc < 3)        usage(argv);    char *hostName = argv[1];    char *fileName = argv[2];    int port = 80;    // Create the Event Queue for this thread...    nsCOMPtr<nsIEventQueueService> eventQService =              do_GetService(kEventQueueServiceCID, &rv);    if (NS_FAILED(rv)) {        NS_WARNING("failed to create: event queue service!");        return rv;    }    rv = eventQService->CreateMonitoredThreadEventQueue();    if (NS_FAILED(rv)) {        NS_WARNING("failed to create: thread event queue!");        return rv;    }    eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ);    // Create the Socket transport service...    nsCOMPtr<nsISocketTransportService> sts =              do_GetService(kSocketTransportServiceCID, &rv);    if (NS_FAILED(rv)) {        NS_WARNING("failed to create: socket transport service!");        return rv;    }    char *buffer = PR_smprintf("GET %s HTTP/1.1" CRLF                               "host: %s" CRLF                               "user-agent: Mozilla/5.0 (X11; N; Linux 2.2.16-22smp i686; en-US; m18) Gecko/20001220" CRLF                               "accept: */*" CRLF                               "accept-language: en" CRLF                               "accept-encoding: gzip,deflate,compress,identity" CRLF                               "keep-alive: 300" CRLF                               "connection: keep-alive" CRLF                                CRLF,                                fileName, hostName);    LOG(("Request [\n%s]\n", buffer));    // Create the socket transport...    nsCOMPtr<nsITransport> transport;    rv = sts->CreateTransport(hostName, port, nsnull, -1, 0, 0, getter_AddRefs(transport));    if (NS_FAILED(rv)) {        NS_WARNING("failed to create: socket transport!");        return rv;    }    gElapsedTime = PR_Now();    nsCOMPtr<nsIRequest> writeRequest, readRequest;    rv = transport->AsyncWrite(new TestProvider(buffer), nsnull, 0, 0, 0, getter_AddRefs(writeRequest));    if (NS_FAILED(rv)) {        NS_WARNING("failed calling: AsyncWrite!");        return rv;    }    rv = transport->AsyncRead(new TestListener(), nsnull, 0, 0, 0, getter_AddRefs(readRequest));    if (NS_FAILED(rv)) {        NS_WARNING("failed calling: AsyncWrite!");        return rv;    }    // Enter the message pump    while ( gKeepRunning ) {#ifdef WIN32        MSG msg;        if (GetMessage(&msg, NULL, 0, 0)) {            TranslateMessage(&msg);            DispatchMessage(&msg);        }        else            gKeepRunning = FALSE;#elif XP_MAC        /* Mac stuff is missing here! */#elif XP_OS2        QMSG qmsg;        if (WinGetMsg(0, &qmsg, 0, 0, 0))            WinDispatchMsg(0, &qmsg);        else            gKeepRunning = FALSE;#else        PLEvent *gEvent;        rv = gEventQ->WaitForEvent(&gEvent);        rv = gEventQ->HandleEvent(gEvent);#endif    }    PRTime endTime;     endTime = PR_Now();    LOG(("Elapsed time: %d\n", (PRInt32)(endTime/1000UL - gElapsedTime/1000UL)));    sts->Shutdown();    return 0;}