char* hostName = argv[1]; char* fileName = argv[2]; int port = 80;
gTestSocketIOLog = PR_NewLogModule("TestSocketIO");
main(int argc, char* argv[]){  nsresult rv;  if (argc < 3) {      printf("usage: %s <host> <path>\n", argv[0]);      return -1;  }  char* hostName = argv[1];  char* fileName = argv[2];  int port = 80;  rv =  NS_AutoregisterComponents();  if (NS_FAILED(rv)) return rv;  // Create the Event Queue for this thread...  NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueServiceCID, &rv);  if (NS_FAILED(rv)) return rv;  rv = eventQService->CreateThreadEventQueue();  if (NS_FAILED(rv)) return rv;  eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ);  // Create the Socket transport service...  NS_WITH_SERVICE(nsISocketTransportService, sts, kSocketTransportServiceCID, &rv);  if (NS_FAILED(rv)) return rv;  // Create a stream for the data being written to the server...  nsIInputStream* stream;  PRUint32 bytesWritten;  nsCOMPtr<nsIOutputStream> out;  rv = NS_NewPipe(&stream, getter_AddRefs(out), 1024, 4096);  if (NS_FAILED(rv)) return rv;  char *buffer = PR_smprintf("GET %s HTML/1.0%s%s", fileName, CRLF, CRLF);  out->Write(buffer, strlen(buffer), &bytesWritten);  printf("\n+++ Request is: %s\n", buffer);  // Create the socket transport...  nsIChannel* transport;  rv = sts->CreateTransport(hostName, port, nsnull, -1, 0, 0, &transport);// This stuff is used to test the output stream#if 0  nsIOutputStream* outStr = nsnull;  rv = transport->OpenOutputStream(&outStr);  if (NS_SUCCEEDED(rv)) {    PRUint32 bytes;    rv = outStr->Write("test", 4, &bytes);    if (NS_FAILED(rv)) return rv;  }  rv = outStr->Close();#else  if (NS_SUCCEEDED(rv)) {    TestWriteObserver* observer = new TestWriteObserver(transport);    gElapsedTime = PR_Now();    rv = transport->SetTransferCount(bytesWritten);    if (NS_SUCCEEDED(rv)) {      rv = transport->AsyncWrite(stream, nsnull, observer);    }    NS_RELEASE(transport);  }#endif  if (NS_FAILED(rv)) return rv;  // Enter the message pump to allow the URL load to proceed.  while ( gKeepRunning ) {#ifdef WIN32    MSG msg;    if (GetMessage(&msg, NULL, 0, 0)) {      TranslateMessage(&msg);      DispatchMessage(&msg);    } else {      gKeepRunning = FALSE;    }#else#ifdef XP_MAC    /* Mac stuff is missing here! */#else#ifdef XP_OS2    QMSG qmsg;    if (WinGetMsg(0, &qmsg, 0, 0, 0))      WinDispatchMsg(0, &qmsg);    else      gKeepRunning = FALSE;#else    PLEvent *gEvent;    rv = gEventQ->GetEvent(&gEvent);    rv = gEventQ->HandleEvent(gEvent);#endif#endif#endif  }  PRTime endTime;  endTime = PR_Now();  printf("Elapsed time: %d\n", (PRInt32)(endTime/1000UL-gElapsedTime/1000UL));  sts->Shutdown();  return 0;}