Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
TestServ.cpp File Reference
#include "TestCommon.h"
#include <stdlib.h>
#include "nsIServiceManager.h"
#include "nsIEventQueueService.h"
#include "nsIEventQueue.h"
#include "nsIServerSocket.h"
#include "nsISocketTransport.h"
#include "nsNetUtil.h"
#include "nsString.h"
#include "nsCOMPtr.h"
#include "prlog.h"

Go to the source code of this file.

Classes

class  MySocketListener

Defines

#define LOG(args)   PR_LOG(gTestLog, PR_LOG_DEBUG, args)

Functions

static nsresult MakeServer (PRInt32 port)
int main (int argc, char *argv[])

Variables

static PRBool gKeepRunning = PR_TRUE
static nsIEventQueuegEventQ = nsnull

Define Documentation

#define LOG (   args)    PR_LOG(gTestLog, PR_LOG_DEBUG, args)

Definition at line 56 of file TestServ.cpp.


Function Documentation

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

Definition at line 146 of file TestServ.cpp.

{
    if (test_common_init(&argc, &argv) != 0)
        return -1;

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

#if defined(PR_LOGGING)
    gTestLog = PR_NewLogModule("Test");
#endif

    /* 
     * The following code only deals with XPCOM registration stuff. and setting
     * up the event queues. Copied from TestSocketIO.cpp
     */

    rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
    if (NS_FAILED(rv)) return rv;

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

        eqs->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ);

        rv = MakeServer(atoi(argv[1]));
        if (NS_FAILED(rv)) {
            LOG(("MakeServer failed [rv=%x]\n", rv));
            return -1;
        }

        // Enter the message pump to allow the URL load to proceed.
        while (gKeepRunning) {
            PLEvent *event;
            gEventQ->WaitForEvent(&event);
            gEventQ->HandleEvent(event);
        }
    } // this scopes the nsCOMPtrs
    // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
    NS_ShutdownXPCOM(nsnull);
    return rv;
}

Here is the call graph for this function:

static nsresult MakeServer ( PRInt32  port) [static]

Definition at line 125 of file TestServ.cpp.

{
    nsresult rv;
    nsCOMPtr<nsIServerSocket> serv = do_CreateInstance(NS_SERVERSOCKET_CONTRACTID, &rv);
    if (NS_FAILED(rv))
        return rv;

    rv = serv->Init(port, PR_TRUE, 5);
    if (NS_FAILED(rv))
        return rv;

    rv = serv->GetPort(&port);
    if (NS_FAILED(rv))
        return rv;
    LOG(("  listening on port %d\n", port));

    rv = serv->AsyncListen(new MySocketListener());
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 59 of file TestServ.cpp.

Definition at line 58 of file TestServ.cpp.