/* * Receive n bytes from a socket */ int recvdata(SOCKET sock, char *ptr, int nbytes) { int nleft, nread; nleft = nbytes; while (nleft > 0) { D_PRINTF( "In recvdata(%d, %d)\n", sock, nleft ); nread = NETREAD(sock, ptr, nleft); D_PRINTF( "NETREAD() returned %d\n", nread ); if (BADSOCKET(nread) || nread == 0) { /* return error value NETWRITE */ D_PRINTF( "Error in recvdata(): %s\n",neterrstr() ); return(nread); } D_PRINTF( "NETREAD() data: \"%.*s\"\n", nread, ptr); nleft -= nread; ptr += nread; } /* end while */ /* return >= 0 */ return(nbytes - nleft); } /* end recvdata */
stats_t * text_to_stats(char *stats_as_text) { int i; rqst_stats_t *the_rqst_stats; THREAD static stats_t stats; stats_t *the_stats = &stats; D_PRINTF( "Parsing stats: %s\n", stats_as_text ); /* grab stats.rs */ the_rqst_stats = text_to_rqst_stats(stats_as_text); the_stats->rs = *the_rqst_stats; /* grab main structure */ the_stats->starttime = text_to_timeval(strtok((char *)0, "\t")); the_stats->endtime = text_to_timeval(strtok((char *)0, "\t")); the_stats->datatime = text_to_timeval(strtok((char *)0, "\t")); the_stats->totalpages = (unsigned long) text_to_double(strtok((char *)0, "\t")); the_stats->total_num_of_files = (unsigned int) text_to_double(strtok((char *)0, "\t")); for (i = 0; i < number_of_pages; i++) { the_stats->page_numbers[i] = (unsigned int) text_to_double(strtok((char *)0, "\t")); } /* return bytes read */ D_PRINTF( "Returning stats\n"); return(the_stats); } /* end text_to_stats */
/* Recursively remove all file/directories under dir/subdir. If save_dir is set, move any core files there. */ int nuke_dir_subdir(const char *dirpath, const char *subdir, const char *savedir) { int dlen, nlen; char *path; DIR *dir; struct dirent *de; int ret; if (!dirpath || !*dirpath) { return -1; } if (!subdir) { subdir = ""; } dlen = strlen(dirpath); nlen = strlen(subdir); path = alloca(dlen + nlen + 2); strcpy (path, dirpath); if (*subdir) { char *cp = path + dlen; *cp++ = '/'; strcpy (cp, subdir); } dir = opendir(path); if (!dir) { D_PRINTF(stderr, "Error removing contents of '%s': %s\n", path, strerror(errno)); rmdir(path); /* attempt to rmdir anyway */ return -1; } while ((de = readdir(dir))) { // Note that errors are intentionally ignored. if (de->d_type == DT_DIR) { if (0 == strcmp(".", de->d_name)) continue; if (0 == strcmp("..", de->d_name)) continue; nuke_dir_subdir (path, de->d_name, savedir); } else { if (savedir && is_core_file(de->d_name)) { if (move_dir_file (path, savedir, de->d_name) >= 0) continue; } unlink_dir_file (path, de->d_name); } } closedir(dir); ret = rmdir(path); /* fails if directory not empty */ if (ret < 0) { D_PRINTF(stderr, "Error removing dir '%s'\n", path); } return ret; }
/* * count_file_list() * given a filename, return a guess at the number of pages */ int count_file_list(const char *url_list_file) { FILE *fp; long int num_of_pages; char a_line[BUFSIZ]; char *textvalue; int returnval; fp = fopen(url_list_file, "r"); if (fp == 0) { D_PRINTF("Error %d opening filelist %s: %s\n", errno, url_list_file, strerror(errno) );; return(returnerr("Error %d opening filelist %s: %s\n", errno, url_list_file, strerror(errno))); } else { num_of_pages = 0; D_PRINTF( "Opened file, about to count\n" ); /* * parse through the file line-by-line * strip out comments, but don't check for URL consistency */ while (fgets(a_line, BUFSIZ, fp) != 0) { textvalue = a_line; /* check for comments */ if (strchr(textvalue, '#') != 0) { /* throw out anything after any '#' */ D_PRINTF( "Stripping comment from line: %s\n", textvalue ); returnval = strcspn(textvalue, "#"); D_PRINTF( "Found first # at %d\n", returnval ); if (returnval == 0) { textvalue = 0; } } /* is there more? */ if (textvalue != 0) { num_of_pages++; D_PRINTF( "Found %ld pages\n", num_of_pages ); } } return(num_of_pages); } fclose(fp); } /* end count_file_list() */
int resolve_addrs(char *host, char *protocol, struct hostent *host_phe, struct protoent *proto_ppe, unsigned long *addr, short *type) { struct hostent *phe; struct protoent *ppe; /* if IP address given, convert to internal form */ if (host[0] >= '0' && host[0] <= '9') { *addr = inet_addr(host); if (*addr == INADDR_NONE) return(returnerr("Invalid IP address %s\n", host)); } else { /* look up by name */ phe = gethostbyname(host); if (phe == 0) { D_PRINTF( "Gethostbyname failed: %s", neterrstr() ); return(returnerr("Can't get %s host entry\n", host)); } memcpy(host_phe, phe, sizeof(struct hostent)); memcpy((char *)addr, phe->h_addr, sizeof(*addr)); } /* Map protocol name to protocol number */ ppe = getprotobyname(protocol); if (ppe == 0) { D_PRINTF( "protobyname returned %d\n", ppe ); return(returnerr("Can't get %s protocol entry\n",protocol)); } memcpy(proto_ppe, ppe, sizeof(struct protoent)); D_PRINTF( "Protocol number %d\n", ppe->p_proto ); /* Use protocol to choose a socket type */ if (strcmp(protocol,"udp") == 0) { *type = SOCK_DGRAM; } else { *type = SOCK_STREAM; D_PRINTF( "Choosing SOCK_STREAM %d type %d %s\n", SOCK_STREAM, *type, neterrstr() ); } return 0; }
/* unlink file given directory and name */ int unlink_dir_file(const char *dirpath, const char *file) { int dlen, nlen; char *path; int ret; if (!dirpath || !*dirpath) { return -1; } if (!file) { file = ""; } dlen = strlen(dirpath); nlen = strlen(file); path = alloca(dlen + nlen + 2); strcpy (path, dirpath); if (*file) { char *cp = path + dlen; *cp++ = '/'; strcpy (cp, file); } ret = unlink(path); if (ret < 0) { /* attempt to make writable */ chmod (path, 0666); ret = unlink(path); } if (ret < 0) { D_PRINTF(stderr, "Error Unlinking '%s'\n", path); } return ret; }
static void accumstats(rqst_timer_t *rqsttimer, page_stats_t *pagestats, stats_t *timestat) { rqst_stats_t rqststats; #define TFMT "%10u:%10u" /* * DUMP THE TIMING INFORMATION HERE, OR COMPUTE WHAT YOU WANT TO * PRINT OUT LATER. */ D_PRINTF( "Total bytes read: %d \t Body size read: %d\n", rqsttimer->totalbytes, rqsttimer->bodybytes ); D_PRINTF( "Enter time: " TFMT " \t Exit Time: " TFMT "\n", rqsttimer->entertime.tv_sec, rqsttimer->entertime.tv_usec, rqsttimer->exittime.tv_sec, rqsttimer->exittime.tv_usec ); D_PRINTF( "Before connect: " TFMT " \t After connect: " TFMT "\n", rqsttimer->beforeconnect.tv_sec, rqsttimer->beforeconnect.tv_usec, rqsttimer->afterconnect.tv_sec, rqsttimer->afterconnect.tv_usec ); D_PRINTF( "Before header: " TFMT " \t After header: " TFMT "\n", rqsttimer->beforeheader.tv_sec, rqsttimer->beforeheader.tv_usec, rqsttimer->afterheader.tv_sec, rqsttimer->afterheader.tv_usec ); D_PRINTF( "After body: " TFMT "\n", rqsttimer->afterbody.tv_sec, rqsttimer->afterbody.tv_usec ); rqstat_times(&(rqststats), rqsttimer); rqstat_sum(&(timestat->rs), &(rqststats)); rqstat_sum(&(pagestats->rs), &(rqststats)); if (rqsttimer->page_number != 999) { timestat->page_numbers[rqsttimer->page_number] += 1; } #undef TFMT } /* END accumstats */
double text_to_double(char *double_as_text) { double the_double = 0; int returnval = 0; D_PRINTF("D/%d %s\n", (int)double_as_text, double_as_text); returnval = sscanf(double_as_text, "%lf", &the_double); return(the_double); }
/* * Helper to populate an RAM file table entry. */ static void ramfile_set(ramfile_t *file, const char *name, u8 *addr, u32 size) { file->hash = name ? strhash(name) : 0; file->addr = addr; file->size = size; D_PRINTF("%s: name=%s hash=%08x addr=%08x size=%i\n", __FUNCTION__, name, file->hash, (u32)file->addr, file->size); }
/* * Copy statically linked IRX files to kernel RAM. * They will be loaded by the debugger later... */ void install_modules(const config_t *config) { ramfile_t file_tab[IRX_NUM + 1]; ramfile_t *file_ptr = file_tab; ramfile_t *ktab = NULL; u32 addr = IRX_ADDR; D_PRINTF("%s: addr=%08x\n", __FUNCTION__, addr); /* * build RAM file table */ #ifdef _SMS_MODULES if (config_get_bool(config, SET_DEBUGGER_SMS_MODULES)) { ramfile_set(file_ptr++, "ps2ip", _ps2ip_sms_irx_start, _ps2ip_sms_irx_size); ramfile_set(file_ptr++, "ps2smap", _ps2smap_sms_irx_start, _ps2smap_sms_irx_size); } else { #endif ramfile_set(file_ptr++, "ps2ip", _ps2ip_irx_start, _ps2ip_irx_size); ramfile_set(file_ptr++, "ps2smap", _ps2smap_irx_start, _ps2smap_irx_size); #ifdef _SMS_MODULES } #endif ramfile_set(file_ptr++, "ps2dev9", _ps2dev9_irx_start, _ps2dev9_irx_size); ramfile_set(file_ptr++, "debugger", _debugger_irx_start, _debugger_irx_size); ramfile_set(file_ptr++, "memdisk", _memdisk_irx_start, _memdisk_irx_size); ramfile_set(file_ptr++, "eesync", _eesync_irx_start, _eesync_irx_size); ramfile_set(file_ptr, NULL, NULL, 0); /* terminator */ /* * copy modules to kernel RAM * * memory structure at @addr: * |RAM file table|IRX module #1|IRX module #2|etc. */ DI(); ee_kmode_enter(); ktab = (ramfile_t*)addr; addr += sizeof(file_tab); file_ptr = file_tab; while (file_ptr->hash) { memcpy((u8*)addr, file_ptr->addr, file_ptr->size); file_ptr->addr = (u8*)addr; addr += file_ptr->size; file_ptr++; } memcpy(ktab, file_tab, sizeof(file_tab)); ee_kmode_exit(); EI(); FlushCache(0); }
/* Recursively remove all file/directories under dir/subdir. If save_dir is set, move any core files there. */ int nuke_dir(const char *dir, const char *save_dir) { int ret; ret = nuke_dir_subdir(dir, NULL, save_dir); if (ret == 0) { D_PRINTF(stderr, "Removed dir '%s'\n", dir); } return ret; }
static int echo_client(char *hostname, const int fd) { /* * WRITE TEXT FROM FILE DESCRIPTOR INTO STDOUT */ char buf[BUFSIZ]; int cc; D_PRINTF( "echo_client running\n" ); while (getppid() != 1) { cc = NETREAD(fd, buf, sizeof(buf)); if (cc > 0) { write(STDOUT_FILENO, buf, cc); } } D_PRINTF( "Exiting echo_client\n" ); NETCLOSE(fd); }
struct timeval text_to_timeval(char *timeval_as_text) { int returnval = 0; long int seconds, microseconds; struct timeval the_timeval; D_PRINTF("T/%d %s\n", (int)timeval_as_text, timeval_as_text); returnval = sscanf(timeval_as_text, "%ld.%ld", &seconds, µseconds); the_timeval.tv_sec = seconds; the_timeval.tv_usec = microseconds; return the_timeval; }
static void childhandler(void) { int status; /* RECEIVED A SIGNAL THAT A CHILD PROCESS HAS DIED */ D_PRINTF( "A child process has died\n" ); while (wait3(&status, WNOHANG, (struct rusage *)0) >= 0) { /* do nothing */ ; } } /* END childhandler() */
/* * Send n bytes to a socket */ int senddata(SOCKET sock, char *ptr, int nbytes) { int nleft, nwritten; D_PRINTF( "In senddata(%d, \"%.*s\", %d)\n", sock, nbytes, ptr, nbytes ); nleft = nbytes; while (nleft > 0) { nwritten = NETWRITE(sock, ptr, nleft); D_PRINTF( "senddata() returned %d\n", nwritten ); if (BADSOCKET(nwritten)) { /* return error value from NETWRITE */ D_PRINTF( "Error in senddata(): %s\n", neterrstr() ); return(nwritten); } nleft -= nwritten; ptr += nwritten; } return(nbytes - nleft); } /* end senddata */
long int load_percent(page_list_t *page_list, long int number_of_pages) { int i; long int index_number = 0; for (i = 0; i < number_of_pages; i++) { index_number += page_list[i].load_num; } D_PRINTF( "load_percent returning %d\n", (index_number) ); return(index_number); }
/* * parse_line - Parse the current line and process the found token. */ static int parse_line(const char *line, int nl, parser_ctx_t *ctx, gamelist_t *list) { int tok = get_token(line, ctx->top); D_PRINTF("%4i %i %s\n", nl, tok, line); /* * Check if current token is expected - makes sure that the list * operations succeed. */ if (!(ctx->next & tok)) { parse_err(nl, "parse error: %s invalid here", tok2str(tok)); return -1; } /* Process actual token and add it to the list it belongs to. */ switch (tok) { case TOK_GAME_TITLE: ctx->game = __make_game(line); if (ctx->game == NULL) { parse_err(nl, "make_game() failed"); return -1; } GAMES_INSERT_TAIL(list, ctx->game); break; case TOK_CHEAT_DESC: ctx->cheat = __make_cheat(line); if (ctx->cheat == NULL) { parse_err(nl, "make_cheat() failed"); return -1; } CHEATS_INSERT_TAIL(&ctx->game->cheats, ctx->cheat); break; case TOK_CHEAT_CODE: ctx->code = __make_code(line); if (ctx->code == NULL) { parse_err(nl, "make_code() failed"); return -1; } CODES_INSERT_TAIL(&ctx->cheat->codes, ctx->code); break; } ctx->next = next_token(tok); return 0; }
/* * parse_err - Store information about a parse error. */ static void parse_err(int nl, const char *msg, ...) { va_list ap; parse_error_line = nl; if (msg != NULL) { va_start(ap, msg); vsprintf(parse_error_text, msg, ap); va_end(ap); } else { strcpy(parse_error_text, "-"); } D_PRINTF("line %i: %s\n", nl, parse_error_text); }
/* Do any extra initialization related to ssl */ void mstoneSslInit(void) { #ifdef USE_PTHREADS int n; num_locks = CRYPTO_num_locks(); locks = xcalloc(num_locks * sizeof(*locks)); for (n = 0; n < num_locks; n++) { if (pthread_mutex_init(&locks[n], NULL)) { returnerr(stderr, "Failed to initialize mutex %d\n", n); } } CRYPTO_set_id_callback(thread_id); CRYPTO_set_locking_callback(thread_lock); D_PRINTF(stderr, "Initialized SSL for threading\n"); #endif /* USE_PTHREADS */ }
/* unlink file given directory and name */ int move_dir_file(const char *from_dir, const char *to_dir, const char *file) { int dlen, nlen, tolen; char *path, *newpath; int ret; if (!from_dir || !*from_dir) { return -1; } if (!to_dir || !*to_dir) { return -1; } if (!file) { file = ""; } dlen = strlen(from_dir); tolen = strlen(to_dir); nlen = strlen(file); path = alloca(dlen + nlen + 2); strcpy (path, from_dir); if (*file) { char *cp = path + dlen; *cp++ = '/'; strcpy (cp, file); } newpath = alloca(tolen + nlen + 2); strcpy (newpath, to_dir); if (*file) { char *cp = newpath + tolen; *cp++ = '/'; strcpy (cp, file); } ret = rename(path, newpath); if (ret < 0) { D_PRINTF(stderr, "Error moving '%s' to '%s'\n", path, newpath); } return ret; }
void ParseCmdLine(int argc, char **argv ) { char getoptch; int currarg; extern char *optarg; extern int optind; /* * PARSE THE COMMAND LINE OPTIONS */ while((getoptch = getopt(argc,argv,"P:f:t:l:p:u:R:w:n:M:adrsvWX")) != (const char)EOF) { switch(getoptch) { case 'M': strcpy(network_mask_str, optarg); break; case 'P': haveproxyserver = 1; strcpy(proxyserver, optarg); break; case 'R': record_all_transactions = 1; break; case 'X': norexec = 1; break; case 'W': servaddrin_config = 1; break; case 'a': dumpall = 1; break; case 'd': debug = 1; break; case 'f': strcpy(configfile, optarg); break; case 'l': numloops = atoi(optarg); break; case 'p': portnum = atoi(optarg); break; case 'r': redirect = 1; break; case 's': savefile = 1; break; case 't': testtime = atoi(optarg); break; case 'u': uil_filelist_f = 1; strcpy(uil_filelist, optarg); break; case 'v': verbose = 1; break; case 'w': havewebserver = 1; strcpy(webserver, optarg); break; default: usage(argv[0]); } /* end switch */ } /* end while */ if (numloops && testtime) errexit("Can't have both -l and -t\n"); if(!havewebserver && !servaddrin_config) { /* * THE SERVERS NAME MUST BE SPECIFIED */ fprintf(stderr,"No WWW Server specified\n"); usage(argv[0]); } if (havewebserver && servaddrin_config) { /* * CAN'T HAVE BOTH -w and -W */ fprintf(stderr, "Can't have both -w and -W options\n"); usage(argv[0]); } network_mask = inet_addr(network_mask_str); if (network_mask == INADDR_NONE) { fprintf(stderr, "Invalid network mask (-M %s)\n", network_mask_str); usage(argv[0]); } if(strlen(configfile) == 0) { /* * THE MASTER MUST HAVE A CONFIGURATION FILE TO READ. */ fprintf(stderr,"No Configuration file specified\n"); usage(argv[0]); } /* IF WE DO NOT HAVE A FILE LIST THEN THERE ARE UIL'S AT THE END OF THE * COMMAND LINE SO GRAB THEM. */ if (uil_filelist_f == 0) { currarg = optind; number_of_pages = 0; while(currarg != argc) { /* * GET THE UILS TO RETRIEVE. */ sscanf(argv[currarg],"%s",filelist[number_of_pages]); number_of_pages++; currarg++; } } else { /* have filelist; take a stab at the number of valid URLs */ D_PRINTF( "About to parse filelist %s\n", uil_filelist ); number_of_pages = count_file_list(uil_filelist); } if (number_of_pages == 0) { /* * AT LEAST ONE FILE MUST BE SPECIFIED */ fprintf(stderr,"No URL resources specified\n"); usage(argv[0]); } }
/* connect to a socket given the hostname and protocol */ SOCKET connectsock(char *host, NETPORT portnum, char *protocol) { struct sockaddr_in sin; /* an Internet endpoint address */ SOCKET s; /* socket descriptor */ int type; /* socket type */ short proto; int returnval; /* temporary return value */ D_PRINTF( "Beginning connectsock; host=%s port=%d proto=%s\n", host, portnum, protocol ); sin.sin_family = AF_INET; memset((char *)&sin, 0, sizeof(sin)); D_PRINTF( "Zeroed address structure\n" ); sin.sin_port = htons(portnum); D_PRINTF( "Set port number %d\n", portnum ); /* get the contact information */ if (strcmp(host, webserver) == 0) { sin.sin_addr.S_ADDR = webserv_addr; sin.sin_family = PF_INET; proto = webserv_ppe.p_proto; type = webserv_type; } else if (strcmp(host, webmaster) == 0) { sin.sin_addr.S_ADDR = webmast_addr; sin.sin_family = PF_INET; proto = webmast_ppe.p_proto; type = webmast_type; } else { struct hostent host_phe; struct protoent host_ppe; unsigned long host_addr; short host_type; /* socket type */ if (resolve_addrs(host, "tcp", &host_phe, &host_ppe, &host_addr, &host_type)) return returnerr("Can't resolve hostname %s in get()\n", host); sin.sin_addr.S_ADDR = host_addr; sin.sin_family = PF_INET; proto = host_ppe.p_proto; type = host_type; } /* Allocate a socket */ s = socket(PF_INET, type, proto); D_PRINTF( "Socket %d returned %d, %s\n", type, s, neterrstr() ); if (BADSOCKET(s)) { D_PRINTF( "Can't create socket: %s\n",neterrstr() ); return BADSOCKET_VALUE; } /* Connect the socket */ D_PRINTF( "Trying to connect %d with size %d, %s\n", s, sizeof(sin), neterrstr() ); D_PRINTF( "Address is family %d, port %d, addr %s\n", sin.sin_family, ntohs(sin.sin_port), inet_ntoa(sin.sin_addr) ); returnval = connect(s, (struct sockaddr *)&sin, sizeof(sin)); D_PRINTF( "Connect returned %d, %s\n", returnval, neterrstr() ); if (returnval < 0) { D_PRINTF( "Can't connect: %s\n", neterrstr() ); NETCLOSE(s); return BADSOCKET_VALUE; } /* all done, returning socket descriptor */ D_PRINTF( "Returning %d from connectsock call\n", s ); return(s); } /* END connectsock() */
/* * parse_file_list() * given a filename, a pointer to a page list, and pointers to integers * for the number of pages and the number of files, parse its contents. */ void parse_file_list (const char *url_list_file, page_list_t *page_list, long int *num_of_pages, long int *num_of_files) { FILE *fp; int filenum; int returnval; int loadnum; char a_line[BUFSIZ]; char tempbuf[BUFSIZ]; char *textvalue; int numfiles = 1, numpages = 0; int maxpages = *num_of_pages; page_list_t *pp; extern int haveproxyserver; fp = fopen(url_list_file, "r"); if (fp == 0) { errexit("Error %d opening filelist: %s\n", errno, strerror(errno)); } else { /* * GRAB A LINE. FORMAT IS: URL WEIGHTINGFACTOR * EXAMPLE: http://www/file.html 1 */ D_PRINTF( "File is open.\n" ); while(fgets(a_line, BUFSIZ, fp) != 0) { textvalue = a_line; /* check for comments */ if (strchr(textvalue, '#') != 0) { /* throw out anything after a '#' */ D_PRINTF( "Stripping comment from line: %s\n", textvalue ); returnval = strcspn(textvalue, "#"); D_PRINTF( "Found first # at %d\n", returnval ); if (returnval == 0) continue; } if (numpages >= *num_of_pages) errexit("Out of space in parse_file_list()\n"); pp = &page_list[numpages]; D_PRINTF( "Processing page %ld\n", numpages ); loadnum = 0; if (textvalue != 0) { /* is there more? */ /* check for weighting factor */ D_PRINTF( "Setting page values from: %s\n", textvalue ); returnval = sscanf(textvalue, "%s%d", tempbuf, &loadnum); D_PRINTF("Scan for weighting returns %d, %d\n", returnval, loadnum); if (returnval == EOF || loadnum <= 0) { pp->load_num = 1; } else { pp->load_num = loadnum; } D_PRINTF("Setting load=%d for line: %s\n", pp->load_num, textvalue); /* placeholder for grouping multiple files onto one page */ pp->num_of_files = 1; filenum = 0; textvalue = tempbuf; D_PRINTF( "Line is now: %s\n", textvalue ); /* * if we've got a proxy server, we'll assume that the * remaining text is a valid URL, and stuff it into * page_list[numpages].filename[filenum] * Otherwise, we'll have to parse it out. */ if (haveproxyserver) { pp->servername[filenum] = 0; pp->port_number[filenum] = 0; strcpy(pp->filename[filenum], textvalue); } else /* no proxy server, so we have to parse it out... */ { /* try http://server(:port)/file */ D_PRINTF( "Trying http://server(:port)/filename\n" ); returnval = sscanf(textvalue, "http://%[^/]%s", tempbuf, a_line); /* check server string for :port */ if (returnval != 0 && returnval != EOF) { D_PRINTF( "Setting filename %s\n", a_line ); strcpy(pp->filename[filenum], a_line); D_PRINTF( "Checking %s for :portnumber\n", tempbuf ); returnval = sscanf(tempbuf, "%[^:]:%d", a_line, &pp->port_number[filenum]); if (returnval < 2) { pp->port_number[filenum] = 80; } if (returnval == EOF) { pp->servername[filenum] = 0; } else { D_PRINTF("Port number %d, setting server %s\n", pp->port_number[filenum], a_line); strcpy(pp->servername[filenum], a_line); } D_PRINTF("Server %s, port number %d\n", pp->servername[filenum], pp->port_number[filenum]); } else /* no good - try straight filename */ { pp->port_number[filenum] = 80; D_PRINTF( "Trying filename, returnval=%d\n", returnval ); pp->servername[filenum] = 0; D_PRINTF("Server %s, port number %d\n", pp->servername[filenum], pp->port_number[filenum]); returnval = sscanf(textvalue, "%s", a_line); D_PRINTF( "Scan returned filename %s\n", a_line ); strcpy(pp->filename[filenum], a_line); } /* end of parsing */ } /* end if haveproxyserver */ D_PRINTF("Done parsing line\n"); D_PRINTF("Got server %s, port %d, file %s, returnval %d\n", pp->servername[filenum], pp->port_number[filenum], pp->filename[filenum], returnval); } /* end if textvalue not NULL */ numpages++; } /* end while not EOF */ if (numpages < 1) { returnerr("No files are specified by filelist\n"); } } /* end if file ok */ fclose(fp); D_PRINTF("Returning %ld pages and %ld files\n", numpages, numfiles ); *num_of_pages = numpages; *num_of_files = numfiles; }
SOCKET connecttomaster(char *str) { char *tempch; SOCKET sock; char msg[100]; char ConnectStr[100]; /* Fix to handle multiple threads */ int tries; strcpy(ConnectStr, str); /* * BREAK UP THE connectstr INTO A HOSTNAME/HOST-IP AND A PORT NUMBER. */ if((tempch = strpbrk(ConnectStr,":")) == 0) { /* * INCORRECT FORMAT OF ConnectStr. CORRECT FORMAT IS * HOSTNAME:PORT OR HOST-IP:PORT */ D_PRINTF( "Incorrect format %s: use hostname:port or ip_addr:port\n", ConnectStr ); return(returnerr("Incorrect format %s: use host:port or ip_addr:port\n", ConnectStr)); } /* * ZERO OUT THE COLON SO WE HAVE TWO STRINGS, THE HOSTNAME AND THE PORT */ *tempch = '\0'; tempch++; /* loop here to connect to webmaster - TCP/IP allows no more than 5 * connection requests outstanding at once and thus the webmaster may * reject a connection if there are a lot of client processes */ #define MAXTRIES 30 #define TRYDELAY_SEC 1 for (tries = 0; tries < MAXTRIES; tries++) { sock = connectsock(ConnectStr,(NETPORT)atoi(tempch),"tcp"); if (!BADSOCKET(sock)) break; sleep(TRYDELAY_SEC); } if (BADSOCKET(sock)) { /* ERROR CONNECTING TO MASTER PROCESS */ return(returnerr("Could not connect to master process\n")); } /* * SIGNAL THE MASTER THAT WE ARE READY TO PROCEED. WHEN ALL * CHILD PROCESSES HAVE CONNECTED AND SENT THIS SIGNAL, * THE MASTER WILL ISSUE US A GO SIGNAL. */ if(NETWRITE(sock,READYSTR,READYSTRLEN) != READYSTRLEN) { return(returnerr("Error sending READY message to master")); } memset(msg,0,GOSTRLEN+1); if(NETREAD(sock,msg,GOSTRLEN) != GOSTRLEN) { D_PRINTF( "Error receiving GO message from master: %s\n", neterrstr() ); return(returnerr("Error receiving GO message from master\n")); } if(strncmp(GOSTR,msg,GOSTRLEN)) { /* * WE RECEIVED A MESSAGE OTHER THAN GO. PRINT IT OUT AND RETURN ERROR */ return(returnerr("Received non-GO message %s\n",msg)); } return(sock); } /* END connecttomaster() */
/* * fetch the set of files that constitute a page * * maxcount = the number of files in the WWW page * pageval = the number of the WWW page (offset in load_file_list[]) * (if -1, use page # 0 - does this still work?) * * returns the number of files retrieved */ static int makeload(int maxcount, int pageval, THREAD rqst_timer_t *timerarray, THREAD stats_t *timestat, THREAD SOCKET mastersock, THREAD page_stats_t *page_stats) { int cnt; int returnval; page_stats_t page_stats_tmp; char server[MAXHOSTNAMELEN]; NETPORT loc_portnum; D_PRINTF( "Starting makeload(maxcount %d, pageval %d)\n", maxcount, pageval ); strcpy( server, webserver); /* Put in default value */ page_stats_init(&page_stats_tmp); D_PRINTF( "Page stats initialized\n" ); for (cnt = 0; cnt < maxcount; cnt++) { D_PRINTF( "Loop count %d in makeload()\n", cnt ); if (pageval == -1) { pageval = cnt; } if (timeexpired) { break; } /* check for a filename */ if (strlen(load_file_list[pageval].filename[cnt]) < 1) { D_PRINTF( "Bad filename at pageval %d, count %d\n", pageval, cnt ); return(returnerr("Bad filename at pageval %d, count %d\n", pageval, cnt)); } /* if (load_file_list[pageval].port_number[cnt] != 0) { loc_portnum = load_file_list[pageval].port_number[cnt]; } else { loc_portnum = portnum; } */ loc_portnum = portnum; if ((load_file_list[pageval].servername[cnt] != 0) && *load_file_list[pageval].servername[cnt]) { D_PRINTF( "Copying URL server %s to server\n", load_file_list[pageval].servername[cnt] ); strcpy(server, load_file_list[pageval].servername[cnt]); } if (haveproxyserver) { D_PRINTF( "Copying proxy %s to webserver\n", proxyserver ); strcpy(server, proxyserver); } D_PRINTF( "Calling get(%s, %d, %s, &(timearray[%d]))\n", server, loc_portnum, load_file_list[pageval].filename[cnt], cnt ); returnval = get(server, loc_portnum, load_file_list[pageval].filename[cnt], &(timerarray[cnt])); if (returnval < 0) { D_PRINTF( "***GET() RETURNED AN ERROR\n" ); } /* * DID GET() RETURN A VALID TIME? */ if ((returnval == 0) && (timerarray[cnt].valid == 2)) { timerarray[cnt].page_number = pageval; accumstats(&timerarray[cnt], &page_stats_tmp, timestat); } else if (!timeexpired) /* INVALID, INCREMENT THE ERROR COUNTER */ { D_PRINTF( "GET error counter incremented\n" ); timestat->rs.totalerrs++; } if (amclient) { fd_set readfds; struct timeval timeout; int rv; timeout.tv_sec = 0; timeout.tv_usec = 0; FD_ZERO(&readfds); FD_SET(mastersock, &readfds); /* if the webmaster has aborted, quit */ D_PRINTF("Before select() on webmaster socket\n"); if (rv = select(FD_SETSIZE, &readfds, 0, 0, &timeout)) { D_PRINTF("select() returned %d\n", rv); D_PRINTF("Client terminating at request of webmaster\n"); exit(2); } } } /* END for cnt */ /* * DO WE HAVE A VALID RETURN FROM GET()? * WHY NOT USE returnval HERE? */ if ((returnval == 0) && (cnt == load_file_list[pageval].num_of_files) && (timerarray[cnt-1].valid == 2)) { rqst_stats_t *ps_rs; rqst_stats_t *pst_rs; ps_rs = &(page_stats[pageval].rs); pst_rs = &(page_stats_tmp.rs); rqstat_sum(ps_rs, pst_rs); page_stats[pageval].totalpages++; if (page_stats[pageval].page_size == 0) { page_stats[pageval].page_size = (unsigned) page_stats_tmp.rs.totalbody; } } D_PRINTF( "\nMakeload output page %d: %d errors, %d pages\n", pageval, timestat->rs.totalerrs, page_stats[pageval].totalpages ); D_PRINTF( "Makeload returning %d\n", cnt ); return(cnt); } /* END makeload() */
void ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { int file_count=0; int getoptch; int currarg; extern char *optarg; extern int optind; int i, j; char *tempch; int err; #define SLEEP_USEC 100 #ifdef WIN32 WSADATA WSAData; #else struct timeval sleeptime; /* set the amount of time that we'll pause before sending a "." to the webmaster */ sleeptime.tv_sec = SLEEP_USEC/1000000; sleeptime.tv_usec = SLEEP_USEC % 1000000; #endif /* WIN32 */ debugfile = stderr; #ifdef WIN32 MessageBeep(~0U); /* announce our existence */ MessageBeep(~0U); MessageBeep(~0U); err = WSAStartup(MAKEWORD(1,1), &WSAData); if (err != 0) { errexit("Error in WSAStartup()\n"); } atexit(sock_cleanup); SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST); /* create semaphore in locked state */ hSemaphore = CreateSemaphore(0, 0, 1, 0); if(hSemaphore == 0) { errexit("Create semaphore failed: %d", GetLastError()); } #endif /* WIN32 */ memset(webserver, 0, sizeof(webserver)); memset(webmaster, 0, sizeof(webmaster)); memset(proxyserver, 0, sizeof(proxyserver)); memset(connectstr, 0, sizeof(connectstr)); /* * PARSE THE COMMAND LINE OPTIONS */ while((getoptch = getopt(argc,argv,"P:f:t:l:p:u:R:w:c:n:sdv")) != EOF) { switch(getoptch) { case 'c': sprintf(connectstr, "%s", optarg); amclient = 1; printf("%s", OKSTR); /* sent back to webmaster */ fflush(stdout); break; case 'd': debug = 0; /* sumedh */ break; case 'f': sprintf(configfile, "%s", optarg); break; case 'l': numloops = atoi(optarg); break; case 'n': numclients = atoi(optarg); break; case 'u': sprintf(uil_filelist, "%s", optarg); uil_filelist_f = 1; break; case 'p': portnum = atoi(optarg); break; case 's': savefile = 1; break; case 't': testtime = 60 * atoi(optarg); break; case 'v': verbose = 1; break; case 'w': havewebserver = 1; sprintf(webserver,"%s",optarg); break; case 'P': haveproxyserver = 1; sprintf(proxyserver, "%s", optarg); break; case 'R': record_all_transactions = 1; break; default: usage(argv[0]); } } returnerr("Client begins...\n"); D_PRINTF( "Running in debug mode\n\n" ); /* print the command line */ for (i = 0; i < argc; i++) D_PRINTF( "%s ", argv[i] ); D_PRINTF( "\n\n" ); if(testtime && numloops) { /* * EITHER numloops OR testtime, BUT NOT BOTH. */ usage(argv[0]); } if(havewebserver != 1) { #ifdef WIN32 /* * THE SERVER'S NAME MUST BE SPECIFIED */ returnerr("No WWW Server specified\n"); usage(argv[0]); #else /* IF IT ISN'T, WE ASSUME LOCALHOST */ sprintf(webserver, "%s", "localhost"); havewebserver = 1; #endif /* WIN32 */ } currarg = optind; numfiles = 0; while(currarg != argc) { /* * GET THE URLS TO RETRIEVE. */ if (numfiles == MAXNUMOFFILES) { returnerr("Maximum of %d files on the command line.\n"); usage(argv[0]); } sscanf(argv[currarg],"%s",filelist[numfiles]); numfiles++; currarg++; } if ((numfiles != 0) && uil_filelist_f) { returnerr("Both a filelist and UIL specified.\n"); usage(argv[0]); } if((numfiles == 0) && !(uil_filelist_f)) { /* * AT LEAST ONE FILE MUST BE SPECIFIED */ returnerr("No UIL resources or filelist specified \n"); usage(argv[0]); } if((numloops == 0) && (testtime == 0)) { /* * NO SPECIFIED NUMBER OF LOOPS, AND NO TEST TIME */ usage(argv[0]); } if(numclients > MAXPROCSPERNODE || numclients < 1) { returnerr("Number of Clients must be between 1 and %d\n", MAXPROCSPERNODE); exit(1); } /* allow use of IP address */ if(amclient) { if((tempch = strpbrk(connectstr,":")) == 0) { /* * INCORRECT FORMAT OF ConnectStr. CORRECT FORMAT IS * HOSTNAME:PORT OR HOST-IP:PORT */ D_PRINTF( "Incorrect format %s: use hostname:port or ip_addr:port\n", connectstr ); returnerr("Incorrect format %s: use host:port or ip_addr:port\n", connectstr); exit(1); } else { strncpy(webmaster, connectstr, tempch-connectstr); } if(resolve_addrs(webmaster, "tcp", &webmast_phe, &webmast_ppe, &webmast_addr, &webmast_type)) exit(1); } if (haveproxyserver) { D_PRINTF( "Copying proxy %s to webserver\n", proxyserver ); strcpy(webserver, proxyserver); } if (resolve_addrs(webserver, "tcp", &webserv_phe, &webserv_ppe, &webserv_addr, &webserv_type)) exit(1); /* * INITIALIZE DATA */ /* allocate space for dynamic arrays */ load_file_list = (page_list_t *)mymalloc((MAXNUMOFPAGES)*sizeof(page_list_t)); if (uil_filelist_f) { /* take a guess at the number of URLs in the file */ D_PRINTF( "About to parse filelist %s\n", uil_filelist ); number_of_pages = count_file_list(uil_filelist); numfiles = 1; /* IF WE HAVE A FILELIST, PARSE IT */ /* allocate memory */ D_PRINTF( "Allocating page list: %ld by %d\n", number_of_pages, numfiles ); for (i=0; i<number_of_pages; i++) { for (j=0; j<MAXNUMOFFILES; j++) { load_file_list[i].servername[j] = (char *)mymalloc(URL_SIZE); load_file_list[i].filename[j] = (char *)mymalloc(URL_SIZE); } } D_PRINTF( "Parsing file list: %s\n", uil_filelist ); parse_file_list(uil_filelist, load_file_list, &number_of_pages, &numfiles); /* free memory for pages that won't be used? */ D_PRINTF( "Actual page list: %ld by %d\n", number_of_pages, MAXNUMOFFILES ); D_PRINTF( "Setting up weighting for %ld pages\n", number_of_pages ); total_weight = load_percent(load_file_list, number_of_pages); /* total_weight = load_percent(load_file_list, number_of_pages, pages); */ } else { /* no uil file */ number_of_pages = numfiles; } if (number_of_pages < 1) { /* no pages - exit */ D_PRINTF( "No valid URLs found\n" ); errexit("No valid URLs found\n"); } #ifndef WIN32 /* * IF WE ARE TO FORK ADDITIONAL CLIENTS ON THIS MACHINE, * WE MUST DO IT BEFORE WE CONNECT TO THE MASTER. * * FIRST, SET UP SIGNAL HANDLING */ signal(SIGCHLD, childhandler); for(i = 0; i < numclients; i++) { thr_create (0, 0, ClientThread, 0, THR_BOUND, 0); /* switch(fork()) { case 0: numclients = 1; ClientThread(0); exit(0); break; case -1: errexit("Error forking child processes\n"); exit(1); default: break; } */ select(0,(fd_set *)0,(fd_set *)0, (fd_set *)0, &sleeptime); } /* * Wait for all children to exit. */ while (thr_join(0, 0, 0) == 0); /* for(;;) { int pid = wait((int*)0); if ((pid == -1) && errno == ECHILD) break; } */ #else /* start threads on NT */ for (i = 0; i < numclients; i++) { if (_beginthread(ClientThread, 0, 0) == -1) { errexit("_beginthread failed: %d", GetLastError()); } } #endif /* WIN32 */ #ifdef WIN32 /* wait for children to get to sync point */ while (CounterSemaphore < numclients) sleep(1); CounterSemaphore = 0; /* start all children simultaneously */ ReleaseSemaphore(hSemaphore, 1, 0); if (testtime) { sleep(testtime); alarmhandler(); /* signal end of test to threads */ } /* * Wait for all threads to exit. */ while (CounterSemaphore < numclients) sleep(1); CloseHandle(hSemaphore); #endif /* WIN32 */ return; } /* end main() */
char * rqst_stats_to_text(rqst_stats_t *the_rqst_stats) { THREAD static char rqst_stats_as_text[SIZEOF_RQSTSTATSTEXT]; char *tmpbuf; *rqst_stats_as_text = 0; tmpbuf = timeval_to_text(&(the_rqst_stats->totalresponsetime)); strcat(rqst_stats_as_text, tmpbuf); tmpbuf = double_to_text((the_rqst_stats->totalresponsetimesq)); strcat(rqst_stats_as_text, tmpbuf); tmpbuf = timeval_to_text(&(the_rqst_stats->minresponsetime)); strcat(rqst_stats_as_text, tmpbuf); tmpbuf = timeval_to_text(&(the_rqst_stats->maxresponsetime)); strcat(rqst_stats_as_text, tmpbuf); tmpbuf = timeval_to_text(&(the_rqst_stats->totalconnecttime)); strcat(rqst_stats_as_text, tmpbuf); tmpbuf = double_to_text((the_rqst_stats->totalconnecttimesq)); strcat(rqst_stats_as_text, tmpbuf); tmpbuf = timeval_to_text(&(the_rqst_stats->minconnecttime)); strcat(rqst_stats_as_text, tmpbuf); tmpbuf = timeval_to_text(&(the_rqst_stats->maxconnecttime)); strcat(rqst_stats_as_text, tmpbuf); tmpbuf = double_to_text((the_rqst_stats->totalconnects)); strcat(rqst_stats_as_text, tmpbuf); tmpbuf = double_to_text((the_rqst_stats->totalerrs)); strcat(rqst_stats_as_text, tmpbuf); tmpbuf = timeval_to_text(&(the_rqst_stats->totalerrortime)); strcat(rqst_stats_as_text, tmpbuf); tmpbuf = double_to_text((the_rqst_stats->totalbytes)); strcat(rqst_stats_as_text, tmpbuf); tmpbuf = double_to_text((the_rqst_stats->totalbytessq)); strcat(rqst_stats_as_text, tmpbuf); tmpbuf = double_to_text((the_rqst_stats->minbytes)); strcat(rqst_stats_as_text, tmpbuf); tmpbuf = double_to_text((the_rqst_stats->maxbytes)); strcat(rqst_stats_as_text, tmpbuf); tmpbuf = double_to_text((the_rqst_stats->totalbody)); strcat(rqst_stats_as_text, tmpbuf); tmpbuf = double_to_text((the_rqst_stats->totalbodysq)); strcat(rqst_stats_as_text, tmpbuf); tmpbuf = double_to_text((the_rqst_stats->minbody)); strcat(rqst_stats_as_text, tmpbuf); tmpbuf = double_to_text((the_rqst_stats->maxbody)); strcat(rqst_stats_as_text, tmpbuf); D_PRINTF("rqst_stats_to_text returning %d: %s\n", strlen(rqst_stats_as_text), rqst_stats_as_text ); return(rqst_stats_as_text); }
void ClientThread(void *dummy) { THREAD FILE *logfile; THREAD stats_t timestat; THREAD rqst_timer_t timerarray[MAXNUMOFFILES]; THREAD SOCKET mastersock = BADSOCKET_VALUE; /* connection to webmaster */ THREAD page_stats_t *page_stats; /* actually a dynamic array */ int loopcnt = 0; int filecnt; int loop; int ran_number; int page_index; int page_number; int file_count = 0; char file_name[50]; struct timeval runningtime; time_t junk; int i; int returnval; /* * INITIALIZE DATA */ page_stats = (page_stats_t *)mymalloc((number_of_pages)*sizeof(page_stats_t)); for (i=0; i < number_of_pages; i++) { page_stats_init(&(page_stats[i])); } if (debug) { /* * OPEN A DEBUG FILE */ fflush(stderr); sprintf(file_name, "%s.%d", DEBUG_FILE, (int)getpid()); debugfile = fopen(file_name, "w+"); if (debugfile == 0) errexit("Can't open debug file\n"); D_PRINTF( "Running in debug mode, %d\n",amclient ); } if (record_all_transactions) { /* * OPEN A LOG FILE. */ sprintf(file_name, "%s%d", LOG_FILE, (int)getpid()); returnerr("Log file is %s\n", file_name); logfile = fopen(file_name, "w+"); } /* Initialize random number generator */ junk = getpid (); rand_r(&junk); D_PRINTF( "Random seed: %d\n", junk ); for (i=0; i < MAXNUMOFFILES; i++) { rqtimer_init(&(timerarray[i])); } stats_init(×tat); D_PRINTF( "Number of files %d\n", numfiles ); timestat.total_num_of_files = numfiles; if (amclient) { /* * WE ARE A CLIENT PROCESS. (i.e. WE ARE NOT RUN BY A USER, BUT BY * THE MASTER WWWSTONE PROCESS. WE NEED TO CONNECT TO THE * MASTER WHO WILL SYNCHRONIZE ALL THE CLIENTS. */ D_PRINTF( "Trying to connect with %s\n",connectstr ); mastersock = connecttomaster(connectstr); D_PRINTF( "connecttomaster returns %d, %s\n", mastersock, neterrstr() ); if(BADSOCKET(mastersock)) { /* * ERROR CONNECTING TO THE MASTER. ABORT. */ errexit("Error connecting to the master: %s\n", neterrstr()); } } /* END IF CLIENT */ #ifdef WIN32 /* Tell parent we're ready */ InterlockedIncrement(&CounterSemaphore); /* Wait for main() thread to release us */ WaitForSingleObject(hSemaphore, INFINITE); ReleaseSemaphore(hSemaphore, 1, 0); #endif /* WIN32 */ if (testtime != 0) { /* * IF RUNNING A TIMED TEST, WE WILL LOOP * UNTIL THE ALARM GOES OFF. * WE'LL ALSO NEED TO SET THE SIGNAL HANDLER */ #ifndef WIN32 /*signal(SIGALRM, alarmhandler);*/ /* * SEND SIGALRM IN testtime SECONDS */ /*alarm(testtime);*/ #endif /* WIN32 */ } /* * AND THEY'RE OFF... */ if (testtime) numloops = INFINITY; GETTIMEOFDAY(&(timestat.starttime), &(timestat.starttimezone)); /* LOOP UNTIL WE HIT numloops, OR WE RUN OUT OF TIME */ for(loopcnt = 0; (loopcnt < numloops) && !timeexpired; loopcnt++) { /* * THIS IS WHERE LOAD TESTING IS DONE. * GET A RANDOM NUMBER, THEN INDEX INTO THE * PAGE, AND THEN REQUEST THAT SET OF FILES. */ if (uil_filelist_f) /* HAVE FILELIST */ { D_PRINTF( "Have filelist\n" ); /* if (testtime != 0) /* RUNNING IN TIMED MODE */ if (1) { D_PRINTF( "Running in timed mode\n" ); /* random number between 0 and totalweight-1 */ junk = getpid (); ran_number = (rand_r(&junk) % total_weight); D_PRINTF( "random %ld\n", ran_number ); /* loop through pages, find correct one * while ran_number is positive, decrement it * by the load_num of the current page * example: ran_number is 5, pages have weights of 10 and 10 * first iteration page_index = 0, ran_number = -5 * iteration halted, page_index = 0 */ page_index = -1; while (ran_number >= 0) { page_index++; D_PRINTF( "Current page index %d: %ld - %d\n", page_index, ran_number, load_file_list[page_index].load_num ); ran_number -= load_file_list[page_index].load_num; } if (page_index >= number_of_pages) { page_index--; } D_PRINTF( "Final page index %d\n", page_index ); filecnt = makeload(load_file_list[page_index].num_of_files, page_index, timerarray, ×tat, mastersock, page_stats); testtime = 1; } else /* NOT RUNNING IN TIMED MODE */ { for (page_number = 0; page_number < number_of_pages; page_number++) { filecnt = makeload(load_file_list[page_number].num_of_files, page_number, timerarray, ×tat, mastersock, page_stats); } /* END for page_number */ } /* END if/else TIMED MODE */ } else /* NO FILELIST */ { D_PRINTF( "No filelist\n" ); /* * LOOP THROUGH UNTIL numfiles TIMES OR UNTIL TIMER EXPIRES * AND ALARM SETS filecnt TO INFINITY. */ /* does this still work?? */ /* filecnt = makeload(numfiles, -1, timerarray); */ } /* END if HAVE FILELIST */ if (filecnt > 0) file_count += filecnt; } /* END while loopcnt */ GETTIMEOFDAY(&(timestat.endtime), &(timestat.endtimezone)); D_PRINTF( "Test run complete\n" ); signal(SIGALRM, 0); if (testtime == 0) { numfiles = loopcnt; if (uil_filelist_f) { numfiles = file_count; } } /* This option ( "-R" ) looks broken (e.g. l > 50) -- JEF 2/15/96 */ if (record_all_transactions) { /* * DUMP THE LOG FILE INFORMATION. */ for (loop=0; loop < (loopcnt * file_count); loop++) { fprintf(logfile, " entertime \t%d.%d\n" " beforeconnect \t%d.%d\n" " afterconnect \t%d.%d\n" " beforeheader \t%d.%d\n" " afterheader \t%d.%d\n" " afterbody \t%d.%d\n" " exittime \t%d.%d\n" " total bytes \t%d\n" " body bytes\t%d\n", timerarray[loop].entertime.tv_sec, timerarray[loop].entertime.tv_usec, timerarray[loop].beforeconnect.tv_sec, timerarray[loop].beforeconnect.tv_usec, timerarray[loop].afterconnect.tv_sec, timerarray[loop].afterconnect.tv_usec, timerarray[loop].beforeheader.tv_sec, timerarray[loop].beforeheader.tv_usec, timerarray[loop].afterheader.tv_sec, timerarray[loop].afterheader.tv_usec, timerarray[loop].afterbody.tv_sec, timerarray[loop].afterbody.tv_usec, timerarray[loop].exittime.tv_sec, timerarray[loop].exittime.tv_usec, timerarray[loop].totalbytes, timerarray[loop].bodybytes); } /* end for loop */ } /* end if recording all transactions */ D_PRINTF( "total errors: %d\n",timestat.rs.totalerrs ); /* gethostname(timestat.hostname,MAXHOSTNAMELEN); */ /* D_PRINTF( "Test for host: %s\n",timestat.hostname ); */ D_PRINTF( "Server is: %s running at port number: %d\n", webserver,portnum ); /* sprintf(timestat.hostname,"%s:%d",timestat.hostname,getpid()); */ if (amclient) /* CLIENT TO A WEBMASTER */ { char *stats_as_text; /* * SEND THE TIMING DATA TO THE MASTER */ stats_as_text = stats_to_text(×tat); D_PRINTF( "stats_to_text returned %s\n", stats_as_text ); returnval = senddata(mastersock, stats_as_text, SIZEOF_STATSTEXTBASE + number_of_pages*SIZEOF_DOUBLETEXT); D_PRINTF( "Wrote time stats to master %d\n", returnval ); if (returnval < 1) { D_PRINTF( "Error while writing time stats: %s\n", neterrstr() ); errexit("Error while writing time stats: %s\n", neterrstr()); } if (uil_filelist_f) /* write pagestats */ { char *page_stats_as_text; for (i = 0; i < number_of_pages; i++) { D_PRINTF( "On page_stats[%d]\n", i ); page_stats_as_text = page_stats_to_text(&page_stats[i]); returnval = strlen(page_stats_as_text); D_PRINTF( "page_stats_to_text[%d] returned %d\n", i, returnval ); returnval = senddata(mastersock, page_stats_as_text, SIZEOF_PAGESTATSTEXT); if (returnval < 1) { D_PRINTF( "Error while writing page_stats[%d]: %s\n", i, neterrstr() ); errexit("Error while writing page_stats[%d]: %s\n", i, neterrstr()); } /* end if */ D_PRINTF( "Wrote %d bytes of page_stats[%d] to master\n", returnval, i ); } /* end for */ } /* end if filelist */ D_PRINTF( "About to close socket\n" ); if (NETCLOSE(mastersock)) D_PRINTF( "Close socket error: %s\n", neterrstr() ); } else /* NOT A CLIENT TO A WEBMASTER */ { if (testtime) { printf("Test ran for: %d minutes\n",(testtime/60)); } else { printf("Test ran for: %d iterations.\n",numloops); } compdifftime(&(timestat.endtime), &(timestat.starttime), &(runningtime)); printf("Total time of test (sec) %d.%d\n", runningtime.tv_sec, runningtime.tv_usec); printf("Files retrieved per iteration: %d\n",numfiles); /* 'per iteration' */ printf("----------------------------------\n"); printf("Totals:\n\n"); rqstat_print(&(timestat.rs)); if (timestat.rs.totalconnects == 0) goto end; printf("Thruput = %5.2lf Kbytes/sec\n", thruputpersec(timestat.rs.totalbytes, &runningtime) / 1000); if (uil_filelist_f && numloops && verbose) { for (loop = 0; loop < number_of_pages; loop++) { if (timestat.page_numbers[loop] != 0) { printf ("===============================================================================\n"); printf ("Page # %d\n\n", loop); printf ("Total number of times page was hit %d\n", page_stats[loop].totalpages); rqstat_print(&(page_stats[loop].rs)); printf ("Page size %d \n", page_stats[loop].page_size); printf ("===============================================================================\n\n"); } /* END if timestat */ } /* END for loop */ } /* END if filelist */ } /* END if client */ end: if(record_all_transactions) fclose(logfile); if(debug) { D_PRINTF( "Client exiting.\n" ); fclose(debugfile); } #ifdef WIN32 /* tell parent we're done */ InterlockedIncrement(&CounterSemaphore); #endif /* WIN32 */ } /* END ClientThread() */
s32 padInit(void * ee_addr) { iop_event_t event; if(freepad_init == 1) { M_PRINTF("Refresh request from EE\n."); padEnd(); } vblankData.padEnd = 0; vblankData.init = 0; vblankData.stopTransfer = 0; pad_ee_addr = ee_addr; pad_port = 0; pad_slot = 0; mainThreadCount2 = 0; pad_portdata[0] = 0; pad_portdata[1] = 0; sif_buffer[0] = 0; sio2cmdReset(); sio2cmdInitFindPads(); sio2cmdInitMouse(); sio2cmdInitNegicon(); sio2cmdInitKonamiGun(); sio2cmdInitDigital(); sio2cmdInitJoystick(); sio2cmdInitNamcoGun(); sio2cmdInitAnalog(); sio2cmdInitJogcon(); sio2cmdInitConfig(); pdReset(); openSlots[0] = 0; openSlots[1] = 0; event.attr = 2; event.bits = 0; vblankData.eventflag = CreateEventFlag(&event); if( vblankData.eventflag == 0) M_PRINTF("padInit: CreateEventFlag failed (%i).\n", (int)vblankData.eventflag); if(vblankData.eventflag != 0) { iop_thread_t thread; int intr_state; thread.attr = TH_C; thread.thread = TransferThread; thread.stacksize = 0x800; thread.priority = 20; vblankData.tid_2 = CreateThread(&thread); if(vblankData.tid_2 == 0) { M_PRINTF("padInit: CreateThread TransferThread failed (%i)\n.", (int)vblankData.tid_2); return 0; } StartThread(vblankData.tid_2, 0); thread.attr = TH_C; thread.thread = MainThread; thread.stacksize = 0x1000; thread.priority = 46; vblankData.tid_1 = CreateThread(&thread); if(vblankData.tid_1 == 0) { M_PRINTF("padInit: CreateThread MainThread failed (%i)\n.", (int)vblankData.tid_1); return 0; } StartThread(vblankData.tid_1, 0); CpuSuspendIntr(&intr_state); RegisterVblankHandler(0, 16, (void*)VblankStart, (void*)&vblankData); RegisterVblankHandler(1, 16, (void*)VblankEnd, (void*)&vblankData); CpuResumeIntr(intr_state); vblankData.init = 1; freepad_init = 1; D_PRINTF("padInit: Success\n"); return 1; } D_PRINTF("padInit: Failed\n"); return 0; }
/* echo stdout/stderr from clients */ void echo_client(void *stream) { SOCKET *sockarr; FILE *outfile; int which_stream = (int) stream; char buf[BUFSIZ]; int i, len, rv; fd_set readfds; /* This code which handles the timeout may need to be ifdef'ed for WIN32 */ struct timeval timeout; timeout.tv_sec = (long)5; timeout.tv_usec = (long)0; if (which_stream) { sockarr = sockIO; outfile = stdout; } else { sockarr = sockErr; outfile = stderr; } D_PRINTF( "echo_client running\n" ); signal( SIGINT, SIG_DFL); /* restore default behavior for SIGINT */ while (1) { FD_ZERO(&readfds); for (i = 0; i < num_rexecs; i++) if (sockarr[i] != BADSOCKET_VALUE) FD_SET(sockarr[i], &readfds); rv = select(num_rexecs, &readfds, 0, 0, &timeout); if ( rv == 0) continue; if (rv < 0 && WSAGetLastError() == WSANOTINITIALISED) return; if (rv < 0) errexit("Error in echo_client(): select() returns %d: %s\n", rv, neterrstr()); /* loop over the sockets that are ready with data */ for (i = 0; i < num_rexecs; i++) { if (sockarr[i] != BADSOCKET_VALUE && FD_ISSET(sockarr[i], &readfds)) { len = NETREAD(sockarr[i], buf, sizeof(buf)); if (len <= 0) { /* mark connection closed */ sockarr[i] = BADSOCKET_VALUE; if (len < 0 && WSAGetLastError() == WSANOTINITIALISED) return; if (len < 0) fprintf(stderr, "Error in echo_client() after NETREAD(): %s\n", neterrstr()); continue; } /* copy to stdout or stderr */ fwrite(buf, sizeof(char), len, outfile); } } } D_PRINTF( "Exiting echo_client\n" ); }