version 1.17, 2005/02/23 04:24:09
|
version 1.18, 2005/02/23 04:43:40
|
|
|
#define todo_wine | #define todo_wine |
#endif | #endif |
| |
#define NUM_CLIENTS 1 |
#define NUM_CLIENTS 3 |
// amount of data to transfer from each client to server | // amount of data to transfer from each client to server |
#define TEST_DATA_SIZE 100000 |
#define TEST_DATA_SIZE 14554 |
| |
int clientsDone = 0; | int clientsDone = 0; |
int sizeofSOCKADDR_IN = sizeof(SOCKADDR_IN); | int sizeofSOCKADDR_IN = sizeof(SOCKADDR_IN); |
|
|
int numCharsReceived; | int numCharsReceived; |
int memSame; | int memSame; |
char buf[1001]; | char buf[1001]; |
char* msg="Some message to send to server"; |
|
| |
StartNetworkApp(SOCK_STREAM, &sock, &client); | StartNetworkApp(SOCK_STREAM, &sock, &client); |
| |
|
|
ok( numCharsReceived > 0, "socket was closed unexpectedly" ); | ok( numCharsReceived > 0, "socket was closed unexpectedly" ); |
| |
memSame = ! memcmp(buf,testData+totCharsReceived,numCharsReceived); | memSame = ! memcmp(buf,testData+totCharsReceived,numCharsReceived); |
|
|
|
if(!memSame) { |
|
printf("\n%d chars received\ncompared %d chars\n",totCharsReceived,numCharsReceived); |
|
} |
|
|
ok( memSame, "data integrity lost during transfer" ); | ok( memSame, "data integrity lost during transfer" ); |
| |
|
|
totCharsReceived += numCharsReceived; | totCharsReceived += numCharsReceived; |
printf("received %d chars\n", numCharsReceived); |
//printf("received %d chars\n", numCharsReceived); |
} | } |
printf("client data transfer completed\n"); | printf("client data transfer completed\n"); |
| |
|
|
| |
printf("server starting data transfer\n"); | printf("server starting data transfer\n"); |
while( totCharsSent < TEST_DATA_SIZE ) { | while( totCharsSent < TEST_DATA_SIZE ) { |
numCharsSent = send(t->ConnectedSocket, testData+totCharsSent, charsPerSend, 0); |
numCharsSent = send(t->ConnectedSocket, testData+totCharsSent, (totCharsSent + charsPerSend <= TEST_DATA_SIZE) ? charsPerSend : TEST_DATA_SIZE - totCharsSent, 0); |
//ok( numCharsSent != SOCKET_ERROR, "socket error" ); | //ok( numCharsSent != SOCKET_ERROR, "socket error" ); |
if(numCharsSent == SOCKET_ERROR) { | if(numCharsSent == SOCKET_ERROR) { |
printf("error code: %d",WSAGetLastError()); | printf("error code: %d",WSAGetLastError()); |
} | } |
totCharsSent += numCharsSent; | totCharsSent += numCharsSent; |
printf("sent %d block\n", numCharsSent); |
//printf("sent %d block\n", numCharsSent); |
} | } |
printf("server data transfer completed\n"); | printf("server data transfer completed\n"); |
| |
|
|
*port = server.sin_port; | *port = server.sin_port; |
| |
for (ThreadIndex = 0; ThreadIndex < NUM_CLIENTS; ThreadIndex++) { | for (ThreadIndex = 0; ThreadIndex < NUM_CLIENTS; ThreadIndex++) { |
|
printf("server waiting for connection %d\n", ThreadIndex+1); |
Threads[ThreadIndex].ConnectedSocket = accept(sock, (SOCKADDR *) &Threads[ThreadIndex].Client, &sizeofSOCKADDR_IN); // this can be modified to include the address of the remote socket | Threads[ThreadIndex].ConnectedSocket = accept(sock, (SOCKADDR *) &Threads[ThreadIndex].Client, &sizeofSOCKADDR_IN); // this can be modified to include the address of the remote socket |
ok(Threads[ThreadIndex].ConnectedSocket != INVALID_SOCKET, "error accepting socket"); | ok(Threads[ThreadIndex].ConnectedSocket != INVALID_SOCKET, "error accepting socket"); |
|
printf("server accepted connection %d\n", ThreadIndex + 1); |
Threads[ThreadIndex].ServerThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) &ProcessConnection, &Threads[ThreadIndex], 0, &Threads[ThreadIndex].ServerThreadID); | Threads[ThreadIndex].ServerThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) &ProcessConnection, &Threads[ThreadIndex], 0, &Threads[ThreadIndex].ServerThreadID); |
} | } |
| |
|
|
struct Thread ServerThread; | struct Thread ServerThread; |
struct Thread *ClientThreads; | struct Thread *ClientThreads; |
| |
ServerThread.Handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) &BlockingClient, &serverPort, 0, &ServerThread.ID); |
|
|
|
ClientThreads = malloc(sizeof(struct Thread) * NUM_CLIENTS); | ClientThreads = malloc(sizeof(struct Thread) * NUM_CLIENTS); |
memset(ClientThreads, 0, sizeof(struct Thread) * NUM_CLIENTS); | memset(ClientThreads, 0, sizeof(struct Thread) * NUM_CLIENTS); |
| |
for(ThreadIndex = 0; ThreadIndex < NUM_CLIENTS; ThreadIndex++) { |
|
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, &serverPort, 0, &ClientThreads[ThreadIndex].ID); |
|
|
|
for(ThreadIndex = 0; ThreadIndex < NUM_CLIENTS; ThreadIndex++) { |
|
printf("created client thread %d\n",ThreadIndex + 1); |
|
ServerThread.Handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) &BlockingClient, &serverPort, 0, &ServerThread.ID); |
} | } |
| |
trace("test_ClientServerBlocking_1 done\n"); | trace("test_ClientServerBlocking_1 done\n"); |