Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
TestSocketInput.cpp File Reference
#include <stdio.h>
#include "nscore.h"
#include "nsCOMPtr.h"
#include "nsISocketTransportService.h"
#include "nsIEventQueueService.h"
#include "nsIServiceManager.h"
#include "nsIComponentRegistrar.h"
#include "nsITransport.h"
#include "nsIRequest.h"
#include "nsIStreamListener.h"
#include "nsIInputStream.h"

Go to the source code of this file.

Classes

class  InputTestConsumer

Functions

static NS_DEFINE_CID (kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID)
static NS_DEFINE_CID (kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID)
int main (int argc, char *argv[])

Variables

static int gKeepRunning = 1

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 138 of file TestSocketInput.cpp.

{
  nsresult rv;

  if (argc < 2) {
      printf("usage: %s <host>\n", argv[0]);
      return -1;
  }

  int port;
  char* hostName = argv[1];
//nsString portString(argv[2]);

//port = portString.ToInteger(&rv);
  port = 13;
  {
    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);

    // Create the Event Queue for this thread...
    nsCOMPtr<nsIEventQueueService> eventQService =
             do_GetService(kEventQueueServiceCID, &rv);
    if (NS_FAILED(rv)) return rv;

    nsCOMPtr<nsIEventQueue> eventQ;
    rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(eventQ));
    if (NS_FAILED(rv)) return rv;

    nsCOMPtr<nsISocketTransportService> sts =
             do_GetService(kSocketTransportServiceCID, &rv);
    if (NS_FAILED(rv)) return rv;

    nsITransport* transport;

    rv = sts->CreateTransport(hostName, port, nsnull, 0, 0, &transport);
    if (NS_SUCCEEDED(rv)) {
      nsCOMPtr<nsIRequest> request;
      transport->AsyncRead(new InputTestConsumer, nsnull, 0, -1, 0, getter_AddRefs(request));

      NS_RELEASE(transport);
    }

    // Enter the message pump to allow the URL load to proceed.
    while ( gKeepRunning ) {
      PLEvent *gEvent;
      eventQ->WaitForEvent(&gEvent);
      eventQ->HandleEvent(gEvent);
    }

  } // 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 0;
}

Here is the call graph for this function:

static NS_DEFINE_CID ( kSocketTransportServiceCID  ,
NS_SOCKETTRANSPORTSERVICE_CID   
) [static]

Variable Documentation

int gKeepRunning = 1 [static]

Definition at line 60 of file TestSocketInput.cpp.