Bugzilla bug #21651: call PR_Listen on the listening socket before passing
authorwtc%netscape.com
Wed, 22 Dec 1999 20:10:49 +0000
changeset 1007 541d72e5206e1160a2b8df17aac2ae63ee846997
parent 1006 d7f7231ad07b57b5060538619c12e0a767a533f9
child 1008 4f4060b3393b7814bbb569f425ec6a0fec007b6a
push idunknown
push userunknown
push dateunknown
bugs21651
Bugzilla bug #21651: call PR_Listen on the listening socket before passing it to the server thread.
pr/tests/layer.c
--- a/pr/tests/layer.c
+++ b/pr/tests/layer.c
@@ -112,23 +112,17 @@ static void PR_CALLBACK Client(void *arg
 static void PR_CALLBACK Server(void *arg)
 {
     PRStatus rv;
     PRUint8 buffer[100];
     PRFileDesc *service;
     PRUintn empty_flags = 0;
     PRIntn bytes_read, bytes_sent;
     PRFileDesc *stack = (PRFileDesc*)arg;
-    PRNetAddr any_address, client_address;
-
-    rv = PR_InitializeNetAddr(PR_IpAddrAny, default_port, &any_address);
-    PR_ASSERT(PR_SUCCESS == rv);
-
-    rv = PR_Bind(stack, &any_address); PR_ASSERT(PR_SUCCESS == rv);
-    rv = PR_Listen(stack, 10); PR_ASSERT(PR_SUCCESS == rv);
+    PRNetAddr client_address;
 
     service = PR_Accept(stack, &client_address, PR_INTERVAL_NO_TIMEOUT);
     if (verbosity > quiet)
         PR_fprintf(logFile, "Server accepting connection\n");
 
     do
     {
         bytes_read = PR_Recv(
@@ -232,16 +226,17 @@ static Verbosity ChangeVerbosity(Verbosi
 }  /* ChangeVerbosity */
 
 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;
@@ -307,16 +302,20 @@ PRIntn main(PRIntn argc, char **argv)
 
     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);
 
@@ -335,27 +334,33 @@ PRIntn main(PRIntn argc, char **argv)
         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, PushLayer(service),
+            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, PushLayer(client),
+            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);