//===================================================== file = timeget2.c ===== //= A client program to do threaded GETs from a Web server = //= - Times the GET response = //============================================================================= //= Notes: = //= 1) This program is for Winsock only. = //= 2) This program hardwires the IP address into IP_ADDR and hardwires = //= the GET request string into GET_STRING. = //= 3) NUM_GET is the number of serial GETs to do = //=---------------------------------------------------------------------------= //= Output from an execution: = //= = //= --------------------------------------------- timeget2.c ----- = //= Number of parallel GETs = 100 = //= Target IP address = 131.247.2.16 = //= GET string = GET /1m.dat HTTP/1.0 = //= = //= = //= Elapsed time = 4406.000 millisec = //= --------------------------------------------------------------- = //=---------------------------------------------------------------------------= //= Build: bcc32 timeget2.c = //=---------------------------------------------------------------------------= //= Execute: timeget2 = //=---------------------------------------------------------------------------= //= History: KJC (10/02/02) - Genesis (from httpget3.c) = //============================================================================= //----- Include files --------------------------------------------------------- #include // Needed for printf() #include // Needed for exit() #include // Needed for strcpy() and strlen() #include // Needed for all Winsock stuff #include // Needed for ftime() and timeb structure #include // Needed for _beginthread() and _endthread() //----- Defines --------------------------------------------------------------- #define BUF_SIZE 4096 // Buffer size #define PORT_NUM 80 // Web servers are at port 80 #define IP_ADDR "131.247.2.16" // IP address of web server #define GET_STRING "GET /1m.dat HTTP/1.0\n\n" // GET string #define NUM_GET 100 // Number of GETs to do //----- Globals --------------------------------------------------------------- int Count; // Global thread counter int Num; // Number of threads completed //----- Function prototypes ------------------------------------------------- void do_get(void *in_arg); // Thread function to do a GET //===== Main program ========================================================== void main(void) { WORD wVersionRequested = MAKEWORD(1,1); // Stuff for WSA functions WSADATA wsaData; // Stuff for WSA functions struct timeb start, stop; // Start and stop times structures double elapsed; // Elapsed time in seconds int retcode; // Return code int i; // Loop counter // This stuff initializes winsock WSAStartup(wVersionRequested, &wsaData); // Output a banner printf("--------------------------------------------- timeget2.c -----\n"); printf(" Number of parallel GETs = %d \n", NUM_GET); printf(" Target IP address = %s \n", IP_ADDR); printf(" GET string = %s \n", GET_STRING); // Start timing ftime(&start); // Do NUM_GET GETs Count = Num = 0; for (i=0; i 0) || (retcode == -1)) { if (retcode == -1) { Count--; printf("*** ERROR - recv() failed (%d) \n", WSAGetLastError()); _endthread(); exit(1); } retcode = recv(server_s, in_buf, BUF_SIZE, 0); } // Decrement for a completed thread Count--; // Output GET finished (comment this out for better performance) // printf(" GET finished -- %d \n", Num++); // Close all open sockets and end the thread closesocket(server_s); _endthread(); }