|
version 1.19, 2005/02/23 05:18:34
|
version 1.20, 2005/02/23 06:07:24
|
|
|
|
| #endif | #endif |
| | |
| // clients threads to create | // clients threads to create |
| #define NUM_CLIENTS 5 |
#define NUM_CLIENTS 1500 |
| | |
| // 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 |
|
|
|
| int clientNum; // 1...NUM_CLIENTS | int clientNum; // 1...NUM_CLIENTS |
| }; | }; |
| | |
| struct Thread { |
struct MyThread { |
| HANDLE Handle; | HANDLE Handle; |
| DWORD ID; | DWORD ID; |
| }; | }; |
|
|
|
| }; | }; |
| | |
| static void test_Startup(void); | static void test_Startup(void); |
| void BlockingClient(int *serverPort); |
void BlockingClient(volatile int *serverPort); |
| void BlockingServer(int *port); |
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_Startup(void); |
| | |
|
|
|
| addr->sin_port = tmpAddr.sin_port; | addr->sin_port = tmpAddr.sin_port; |
| } | } |
| | |
| void BlockingClient(int *serverPort) |
void BlockingClient(volatile int *serverPort) |
| { | { |
| SOCKET sock; | SOCKET sock; |
| SOCKADDR_IN client, server; | SOCKADDR_IN client, server; |
|
|
|
| | |
| StartNetworkApp(SOCK_STREAM, &sock, &client); | StartNetworkApp(SOCK_STREAM, &sock, &client); |
| | |
| |
//trace("client port %d\n",ntohs(client.sin_port)); |
| |
|
| hp = gethostbyname("localhost"); | hp = gethostbyname("localhost"); |
| | |
| // yield until server determines its random port number | // yield until server determines its random port number |
|
|
|
| ok(bClosed,"Error closing socket"); | ok(bClosed,"Error closing socket"); |
| } | } |
| | |
| void BlockingServer(int *port) // listens for incoming connections and accepts up to NUM_CLIENTS connections at once |
void BlockingServer(volatile int *port) // listens for incoming connections and accepts up to NUM_CLIENTS connections at once |
| { | { |
| struct ServerThread *Threads; | struct ServerThread *Threads; |
| int ThreadIndex = 0; | int ThreadIndex = 0; |
|
|
|
| | |
| // 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(); |
| | |
| free(Threads); | free(Threads); |
| } | } |
|
|
|
| static void test_ClientServerBlocking_1(void) | static void test_ClientServerBlocking_1(void) |
| { | { |
| int ThreadIndex = 0; | int ThreadIndex = 0; |
| int serverPort = 0; |
// tell the compiler not to optimize code relating to serverPort |
| struct Thread ServerThread; |
volatile int serverPort = 0; |
| struct Thread *ClientThreads; |
struct MyThread ServerThread; |
| |
struct MyThread *ClientThreads; |
| | |
| ClientThreads = malloc(sizeof(struct Thread) * NUM_CLIENTS); |
ClientThreads = malloc(sizeof(struct MyThread) * NUM_CLIENTS); |
| memset(ClientThreads, 0, sizeof(struct Thread) * NUM_CLIENTS); |
memset(ClientThreads, 0, sizeof(struct MyThread) * NUM_CLIENTS); |
| | |
| trace("starting main server thread\n"); | trace("starting main server thread\n"); |
| ClientThreads[ThreadIndex].Handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) &BlockingServer, &serverPort, 0, &ClientThreads[ThreadIndex].ID); |
ClientThreads[ThreadIndex].Handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) &BlockingServer, (void *) &serverPort, 0, &ClientThreads[ThreadIndex].ID); |
| | |
| trace("starting %d client threads\n", NUM_CLIENTS); |
|
| for(ThreadIndex = 0; ThreadIndex < NUM_CLIENTS; ThreadIndex++) { | for(ThreadIndex = 0; ThreadIndex < NUM_CLIENTS; ThreadIndex++) { |
| ServerThread.Handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) &BlockingClient, &serverPort, 0, &ServerThread.ID); |
ServerThread.Handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) &BlockingClient, (void *) &serverPort, 0, &ServerThread.ID); |
| } | } |
| |
trace("%d clients started\n", NUM_CLIENTS); |
| | |
| |
// wait for all clients to receive data before cleaning up |
| while (clientsDone != NUM_CLIENTS) | while (clientsDone != NUM_CLIENTS) |
| ; |
SwitchToThread(); |
| | |
| free(ClientThreads); | free(ClientThreads); |
| | |
|
|
|
| trace("test 2 of 2:\n"); | trace("test 2 of 2:\n"); |
| test_ClientServerBlocking_1(); | test_ClientServerBlocking_1(); |
| trace("all tests done\n"); | trace("all tests done\n"); |
| |
|
| |
// wait for all clients to receive data before cleaning up |
| while (clientsDone != NUM_CLIENTS) | while (clientsDone != NUM_CLIENTS) |
| ; |
SwitchToThread(); |
| |
|
| free(testData); | free(testData); |
| } | } |