if (verbosity > silent) PR_fprintf(logFile, "Beginning layered test with new style stack\n"); client = PR_NewTCPSocket(); PR_ASSERT(NULL != client); client_stack = PR_CreateIOLayer(client); PushNewLayers(client_stack); service = PR_NewTCPSocket(); PR_ASSERT(NULL != service); service_stack = PR_CreateIOLayer(service); PushNewLayers(service_stack); rv = PR_InitializeNetAddr(PR_IpAddrAny, default_port, &any_address); PR_ASSERT(PR_SUCCESS == rv); rv = PR_Bind(service, &any_address); PR_ASSERT(PR_SUCCESS == rv); rv = PR_Listen(service, 10); PR_ASSERT(PR_SUCCESS == rv);  minor_iterations = mits; server_thread = PR_CreateThread( PR_USER_THREAD, Server, service_stack, PR_PRIORITY_HIGH, thread_scope, PR_JOINABLE_THREAD, 16 * 1024); PR_ASSERT(NULL != server_thread);  client_thread = PR_CreateThread( PR_USER_THREAD, Client, client_stack, PR_PRIORITY_NORMAL, thread_scope, PR_JOINABLE_THREAD, 16 * 1024); PR_ASSERT(NULL != client_thread);  rv = PR_JoinThread(client_thread); PR_ASSERT(PR_SUCCESS == rv); rv = PR_JoinThread(server_thread); PR_ASSERT(PR_SUCCESS == rv);  rv = PR_Close(client_stack); PR_ASSERT(PR_SUCCESS == rv); rv = PR_Close(service_stack); PR_ASSERT(PR_SUCCESS == rv);
PRIntn main(PRIntn argc, char **argv){    PRStatus rv;    PRIntn mits;    PLOptStatus os;    PRFileDesc *client, *service;    PRNetAddr any_address;    const char *server_name = NULL;    const PRIOMethods *stubMethods;    PRThread *client_thread, *server_thread;    PRThreadScope thread_scope = PR_LOCAL_THREAD;    PLOptState *opt = PL_CreateOptState(argc, argv, "dqGC:c:p:");    while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))    {        if (PL_OPT_BAD == os) continue;        switch (opt->option)        {        case 0:            server_name = opt->value;            break;        case 'd':  /* debug mode */            if (verbosity < noisy)                verbosity = ChangeVerbosity(verbosity, 1);            break;        case 'q':  /* debug mode */            if (verbosity > silent)                verbosity = ChangeVerbosity(verbosity, -1);            break;        case 'G':  /* use global threads */            thread_scope = PR_GLOBAL_THREAD;            break;        case 'C':  /* number of threads waiting */            major_iterations = atoi(opt->value);            break;        case 'c':  /* number of client threads */            minor_iterations = atoi(opt->value);            break;        case 'p':  /* default port */            default_port = atoi(opt->value);            break;        default:            break;        }    }    PL_DestroyOptState(opt);    PR_STDIO_INIT();    logFile = PR_GetSpecialFD(PR_StandardError);    identity = PR_GetUniqueIdentity("Dummy");    stubMethods = PR_GetDefaultIOMethods();    /*    ** The protocol we're going to implement is one where in order to initiate    ** a send, the sender must first solicit permission. Therefore, every    ** send is really a send - receive - send sequence.    */    myMethods = *stubMethods;  /* first get the entire batch */    myMethods.recv = MyRecv;  /* then override the ones we care about */    myMethods.send = MySend;  /* then override the ones we care about */    if (NULL == server_name)        rv = PR_InitializeNetAddr(            PR_IpAddrLoopback, default_port, &server_address);    else    {        rv = PR_StringToNetAddr(server_name, &server_address);        PR_ASSERT(PR_SUCCESS == rv);        rv = PR_InitializeNetAddr(            PR_IpAddrNull, default_port, &server_address);    }    PR_ASSERT(PR_SUCCESS == rv);    /* one type w/o layering */    mits = minor_iterations;    while (major_iterations-- > 0)    {        if (verbosity > silent)            PR_fprintf(logFile, "Beginning non-layered test\n");        client = PR_NewTCPSocket(); PR_ASSERT(NULL != client);        service = PR_NewTCPSocket(); PR_ASSERT(NULL != service);        rv = PR_InitializeNetAddr(PR_IpAddrAny, default_port, &any_address);        PR_ASSERT(PR_SUCCESS == rv);        rv = PR_Bind(service, &any_address); PR_ASSERT(PR_SUCCESS == rv);        rv = PR_Listen(service, 10); PR_ASSERT(PR_SUCCESS == rv);        minor_iterations = mits;        server_thread = PR_CreateThread(            PR_USER_THREAD, Server, service,            PR_PRIORITY_HIGH, thread_scope,            PR_JOINABLE_THREAD, 16 * 1024);        PR_ASSERT(NULL != server_thread);        client_thread = PR_CreateThread(            PR_USER_THREAD, Client, client,            PR_PRIORITY_NORMAL, thread_scope,            PR_JOINABLE_THREAD, 16 * 1024);        PR_ASSERT(NULL != client_thread);        rv = PR_JoinThread(client_thread);        PR_ASSERT(PR_SUCCESS == rv);        rv = PR_JoinThread(server_thread);        PR_ASSERT(PR_SUCCESS == rv);        rv = PR_Close(client); PR_ASSERT(PR_SUCCESS == rv);        rv = PR_Close(service); PR_ASSERT(PR_SUCCESS == rv);        if (verbosity > silent)            PR_fprintf(logFile, "Ending non-layered test\n");        /* with layering */        if (verbosity > silent)            PR_fprintf(logFile, "Beginning layered test\n");        client = PR_NewTCPSocket(); PR_ASSERT(NULL != client);        PushLayer(client);        service = PR_NewTCPSocket(); PR_ASSERT(NULL != service);        PushLayer(service);        rv = PR_InitializeNetAddr(PR_IpAddrAny, default_port, &any_address);        PR_ASSERT(PR_SUCCESS == rv);        rv = PR_Bind(service, &any_address); PR_ASSERT(PR_SUCCESS == rv);        rv = PR_Listen(service, 10); PR_ASSERT(PR_SUCCESS == rv);        minor_iterations = mits;        server_thread = PR_CreateThread(            PR_USER_THREAD, Server, service,            PR_PRIORITY_HIGH, thread_scope,            PR_JOINABLE_THREAD, 16 * 1024);        PR_ASSERT(NULL != server_thread);        client_thread = PR_CreateThread(            PR_USER_THREAD, Client, client,            PR_PRIORITY_NORMAL, thread_scope,            PR_JOINABLE_THREAD, 16 * 1024);        PR_ASSERT(NULL != client_thread);        rv = PR_JoinThread(client_thread);        PR_ASSERT(PR_SUCCESS == rv);        rv = PR_JoinThread(server_thread);        PR_ASSERT(PR_SUCCESS == rv);        rv = PR_Close(client); PR_ASSERT(PR_SUCCESS == rv);        rv = PR_Close(service); PR_ASSERT(PR_SUCCESS == rv);        if (verbosity > silent)            PR_fprintf(logFile, "Ending layered test\n");    }    return 0;}  /* main */