(file) Return to wsock32_main.c CVS log (file) (dir) Up to [RizwankCVS] / wine4 / wine / dlls / wsock32 / tests

Diff for /wine4/wine/dlls/wsock32/tests/wsock32_main.c between version 1.21 and 1.23

version 1.21, 2005/02/23 06:13:50 version 1.23, 2005/02/24 02:13:45
Line 44 
Line 44 
 #endif #endif
  
 // clients threads to create // clients threads to create
 #define NUM_CLIENTS 1500  #define NUM_CLIENTS 64
  
 // amount of data to transfer from each client to server // amount of data to transfer from each client to server
 #define TEST_DATA_SIZE 145243 #define TEST_DATA_SIZE 145243
Line 83 
Line 83 
 }; };
  
 static void test_Startup(void); static void test_Startup(void);
 void BlockingClient(volatile int *serverPort);  
 void BlockingServer(volatile int *port);  
 static void test_ClientServerBlocking_1(void); static void test_ClientServerBlocking_1(void);
 static void test_Startup(void);  static void test_Cleanup(void);
   
   static void StartBlockingClients(volatile int *serverPort);
   static void BlockingClient(volatile int *serverPort);
   static void BlockingServer(volatile int *port);
   
  
 // StartNetworkApp creates socket sock of type type and returns assigned port number in addr. // StartNetworkApp creates socket sock of type type and returns assigned port number in addr.
 void StartNetworkApp(int type, SOCKET *sock, SOCKADDR_IN *addr) void StartNetworkApp(int type, SOCKET *sock, SOCKADDR_IN *addr)
Line 141 
Line 144 
  
         // yield until server determines its random port number         // yield until server determines its random port number
         while(*serverPort == 0)         while(*serverPort == 0)
                 SwitchToThread();                  Sleep(100);
  
         server.sin_family = AF_INET;         server.sin_family = AF_INET;
         server.sin_addr = *(struct in_addr *) hp->h_addr;         server.sin_addr = *(struct in_addr *) hp->h_addr;
Line 167 
Line 170 
  
                 // yield to our other threads                 // yield to our other threads
                 if(yieldCounter % 20 == 0) {                 if(yieldCounter % 20 == 0) {
                         //SwitchToThread();                          //Sleep(100);
                 }                 }
                 yieldCounter++;                 yieldCounter++;
         }         }
  
         trace("client done\n");          //trace("client done\n");
         clientsDone++;         clientsDone++;
 } }
  
Line 196 
Line 199 
  
                 // yield to our other threads                 // yield to our other threads
                 if(yieldCounter % 20 == 0) {                 if(yieldCounter % 20 == 0) {
                         //SwitchToThread();                          //Sleep(100);
                 }                 }
                 yieldCounter++;                 yieldCounter++;
         }         }
Line 227 
Line 230 
         // set the port parameter; clients now know we're ready to accept connections         // set the port parameter; clients now know we're ready to accept connections
         *port = server.sin_port;         *port = server.sin_port;
  
           // bound to port; now we can start clients
           CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) &StartBlockingClients, port, 0, NULL);
   
         // we require one connection from each client thread         // we require one connection from each client thread
         for (ThreadIndex = 0; ThreadIndex < NUM_CLIENTS; ThreadIndex++) {         for (ThreadIndex = 0; ThreadIndex < NUM_CLIENTS; ThreadIndex++) {
                         // accept connection                         // accept connection
Line 239 
Line 245 
  
         // wait for all clients to receive data before cleaning up         // wait for all clients to receive data before cleaning up
         while (clientsDone != NUM_CLIENTS)         while (clientsDone != NUM_CLIENTS)
                 SwitchToThread();                  Sleep(100);
  
         free(Threads);         free(Threads);
 } }
  
 static void test_ClientServerBlocking_1(void)  static void StartBlockingClients(volatile int *serverPort)
 { {
         int ThreadIndex = 0;         int ThreadIndex = 0;
         // tell the compiler not to optimize code relating to serverPort  
         volatile int serverPort = 0;  
         struct MyThread ServerThread;  
         struct MyThread *ClientThreads;         struct MyThread *ClientThreads;
  
         ClientThreads = malloc(sizeof(struct MyThread) * NUM_CLIENTS);         ClientThreads = malloc(sizeof(struct MyThread) * NUM_CLIENTS);
         memset(ClientThreads, 0, sizeof(struct MyThread) * NUM_CLIENTS);         memset(ClientThreads, 0, sizeof(struct MyThread) * NUM_CLIENTS);
  
         trace("starting main server thread\n");  
         ClientThreads[ThreadIndex].Handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) &BlockingServer, (void *) &serverPort, 0, &ClientThreads[ThreadIndex].ID);  
   
         for(ThreadIndex = 0; ThreadIndex < NUM_CLIENTS; ThreadIndex++) {         for(ThreadIndex = 0; ThreadIndex < NUM_CLIENTS; ThreadIndex++) {
                 ServerThread.Handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) &BlockingClient, (void *) &serverPort, 0, &ServerThread.ID);                  ClientThreads[ThreadIndex].Handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) &BlockingClient, (void *) serverPort, 0, &ClientThreads[ThreadIndex].ID);
         }         }
         trace("%d clients started\n", NUM_CLIENTS);         trace("%d clients started\n", NUM_CLIENTS);
  
         // wait for all clients to receive data before cleaning up         // wait for all clients to receive data before cleaning up
         while (clientsDone != NUM_CLIENTS)         while (clientsDone != NUM_CLIENTS)
                 SwitchToThread();                  Sleep(100);
  
         free(ClientThreads);         free(ClientThreads);
   }
   
   static void test_ClientServerBlocking_1(void)
   {
           // tell the compiler not to optimize code relating to serverPort
           volatile int *serverPort;
           struct MyThread ServerThread;
   
           serverPort = malloc(sizeof(int));
           *serverPort = 0;
   
           // start server thread
           // server starts client threads after it binds to a port.
           trace("starting main server thread\n");
           ServerThread.Handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) &BlockingServer, (void *) serverPort, 0, &ServerThread.ID);
   
           // wait for all clients to receive data before cleaning up
           while (clientsDone != NUM_CLIENTS)
                   Sleep(100);
  
         trace("test_ClientServerBlocking_1 done\n");         trace("test_ClientServerBlocking_1 done\n");
 } }
Line 293 
Line 312 
          trace("startup ok\n");          trace("startup ok\n");
 } }
  
   
   static void test_Cleanup(void)
   {
           int cleanupOK;
   
           cleanupOK = ! WSACleanup();
   
           ok( cleanupOK , "error in WSACleanup()");
           trace("cleanup ok\n");
   }
   
 START_TEST(wsock32_main) START_TEST(wsock32_main)
 { {
           const int numTests = 3;
         testData = malloc(TEST_DATA_SIZE);         testData = malloc(TEST_DATA_SIZE);
   trace("test 1 of 2:\n");  
           trace("test 1 of %d:\n", numTests);
   test_Startup();   test_Startup();
   trace("test 2 of 2:\n");  
           trace("test 2 of %d:\n", numTests);
   test_ClientServerBlocking_1();   test_ClientServerBlocking_1();
   trace("all tests done\n");  
  
         // wait for all clients to receive data before cleaning up          trace("test 3 of %d:\n", numTests);
         while (clientsDone != NUM_CLIENTS)          test_Cleanup();
                 SwitchToThread();  
     trace("all tests done\n");
  
         free(testData);         free(testData);
 } }


Legend:
Removed from v.1.21  
changed lines
  Added in v.1.23

Rizwan Kassim
Powered by
ViewCVS 0.9.2