Bugzilla bug #5802: call PR_Bind and PR_Listen before passing the
authorwtc%netscape.com
Wed, 22 Dec 1999 20:12:11 +0000
changeset 1008 4f4060b3393b7814bbb569f425ec6a0fec007b6a
parent 1007 541d72e5206e1160a2b8df17aac2ae63ee846997
child 1009 3cfced8f95cb3408e21a0a048a1d058492823044
push idunknown
push userunknown
push dateunknown
bugs5802
Bugzilla bug #5802: call PR_Bind and PR_Listen before passing the listening socket to the server thread.
pr/tests/nblayer.c
--- a/pr/tests/nblayer.c
+++ b/pr/tests/nblayer.c
@@ -204,23 +204,17 @@ static void PR_CALLBACK Server(void *arg
     PRStatus rv;
     PRInt32 ready;
     PRUint8 buffer[100];
     PRFileDesc *service;
     PRUintn empty_flags = 0;
     struct PRPollDesc polldesc;
     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;
 
     do
     {
         if (verbosity > chatty)
             PR_fprintf(logFile, "Server accepting connection\n");
         service = PR_Accept(stack, &client_address, PR_INTERVAL_NO_TIMEOUT);
         if (verbosity > chatty)
             PR_fprintf(logFile, "Server accept status [0x%p]\n", service);
@@ -475,16 +469,17 @@ static Verbosity ChangeVerbosity(Verbosi
     return (Verbosity)verbage;
 }  /* ChangeVerbosity */
 
 PRIntn main(PRIntn argc, char **argv)
 {
     PRStatus rv;
     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;
     PRSocketOptionData socket_noblock, socket_nodelay;
     PLOptState *opt = PL_CreateOptState(argc, argv, "dqGC:c:p:");
     while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
     {
@@ -567,16 +562,21 @@ PRIntn main(PRIntn argc, char **argv)
         PR_ASSERT(PR_SUCCESS == rv);
         rv = PR_SetSocketOption(service, &socket_noblock);
         PR_ASSERT(PR_SUCCESS == rv);
         rv = PR_SetSocketOption(client, &socket_nodelay);
         PR_ASSERT(PR_SUCCESS == rv);
         rv = PR_SetSocketOption(service, &socket_nodelay);
         PR_ASSERT(PR_SUCCESS == rv);
 
+        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);
+
         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,
@@ -604,24 +604,32 @@ PRIntn main(PRIntn argc, char **argv)
         PR_ASSERT(PR_SUCCESS == rv);
         rv = PR_SetSocketOption(service, &socket_noblock);
         PR_ASSERT(PR_SUCCESS == rv);
         rv = PR_SetSocketOption(client, &socket_nodelay);
         PR_ASSERT(PR_SUCCESS == rv);
         rv = PR_SetSocketOption(service, &socket_nodelay);
         PR_ASSERT(PR_SUCCESS == rv);
 
+        PushLayer(client);
+        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);
+
         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);