Example #1
0
int main() {
    Ptr_MemoryAccessRequest ptr_memAccReq;
    ptr_memAccReq = (Ptr_MemoryAccessRequest) malloc(sizeof(MemoryAccessRequest));
    srandom(time(NULL));   
    
    //向FIFO文件中写入内容
    while(1){
   	 	if(readrequest(ptr_memAccReq)==-1)//从标准输入读入访存请求
   	 		break;
        //sleep(1);
    }
    
    printf("程序正常结束\n");
    return 0;
}
Example #2
0
int 
handleclient(int conn) 
{
	char *basedir;
	char *clientdir;
	mp3entry *mp3buf;
	FILE *stream;

	if ((stream = fdopen(conn, "r+")) == NULL || !readrequest(stream)) {
		debug(1, "error while reading client request");
		fclose(stream);
		return(EXIT_FAILURE);
	}
	
	debug(1, "requested path %s", conf.path);

	GETCWD(basedir);
	if(chdir(conf.path))
		die("incorrect dir");
	GETCWD(clientdir);
	
	debug(1, "doing security checks");
	if(strncmp(basedir, clientdir, strlen(basedir) - 1)) {
		fclose(stream);
		debug(1, "basedir %s, clientdir %s", basedir, clientdir);
		die("client tried to break out of base directory");
	}
	
	debug(1, "looking for mp3 files in subdirectory %s", conf.path);
	if(!MODE_ISSET(MODE_SINGLE)) {
		getfiles(".");
	} else if(validfile(conf.filename, clientdir, &mp3buf)) { 
		addentry(&root, mp3buf);
	}
	
	if(!root)
		die("no files");
	else
		debug(1, "%d MP3 file(s) found", countentries(root));

	if(!MODE_ISSET(MODE_INDEX) && !conf.order) {
		debug(1, "shuffling mp3 files");
		shuffleentries();
	}

	if(conf.debuglevel > 2) {
		debug(1, "listing mp3 files");
		dumpentries();
	}
	
	if(MODE_ISSET(MODE_INDEX)) {
		debug(1, "entering HTTP mode");
		fprintf(stream, HTTPSERVMSG, AMPLE_VERSION);
		fflush(stream);
		createhtml(stream,(clientdir + strlen(basedir)),(strlen(clientdir) + 1));
	} else if(MODE_ISSET(MODE_SINGLE)) {
		debug(1, "entering MP3-Single mode");
		fprintf(stream, SINGLESERVMSG, AMPLE_VERSION, root->filesize);
		fflush(stream);
		playfile(stream, root);
	} else if (MODE_ISSET(MODE_METADATA)) {
		debug(1, "entering MP3-Metadata mode");
		fprintf(stream, SHOUTSERVMSG, AMPLE_VERSION, conf.servername, BYTESBETWEENMETA);
		fflush(stream);
		playlist(stream);
	} else {
		debug(1, "entering MP3-Basic mode");
		fprintf(stream, BASICSERVMSG, AMPLE_VERSION);
		fflush(stream);
		playlist(stream);
	}

	fclose(stream);
	clearlist(root);
	return(EXIT_SUCCESS);
}
Example #3
0
int
main(int argc, char **argv)
{
	char *host;
	int port, fail;
	Request *rs;
	Run run;
	int n, i, qps;
	FILE **fs, *f;

	if(argc < 4)
		panic("usage: %s host port qps [file ...]", argv[0]);
	host = argv[1];
	port = atoi(argv[2]);
	if(port == 0)
		panic("invalid port \"%s\"", argv[2]);
	qps = atoi(argv[3]);
	if(qps==0)
		panic("invalid QPS \"%s\"", argv[3]);

	fail = 0;

	i = 0;
	n = 1000;
	rs = mal(n*sizeof(*rs));
	
	if(argc > 4){
		fs = alloca((argc-3)*sizeof(FILE*));
		for(i=0;i<argc-4;i++){
			fs[i] = fopen(argv[i+4], "r");
			if(fs[i] == nil)
				panic("failed to open \"%s\"", argv[i+3]);
		}
		fs[i] = nil;
	}else{
		fs = alloca(2*sizeof(FILE*));
		fs[0] = stdin;
		fs[1] = nil;
	}

	while((f=*(fs++)) != nil){
		setfile(f);
		while(!eof()){
			if(i == n){
				n *= 2;
				rs = remal(rs, n*sizeof(*rs));
			}
			if(readrequest(&rs[i]))
				i++;
			else
				fail++;
		}
	}

	say("parsed %d requests, failed %d", i, fail);

	event_init();
	
	run.rs = rs;
	run.rsiz = i;
	run.tv.tv_sec = 0;
	run.tv.tv_usec = 1000000/qps;
	run.host = host;
	run.port = port;
	run.cachedconn = nil;

	evtimer_set(&run.ev, runcb, &run);
	evtimer_add(&run.ev, &run.tv);

	event_dispatch();

	return 0;
}
Example #4
0
int php3_init_request_info(void *conf)
{
	static int exit_requested = 0;
	int i, len;
	TLS_VARS;
	req = NULL;

	setalarm(idle_timeout);
	while (checkinput(server->infd) && (req = readrequest(server))) {
		alarm(0);
		if (req->reqtype == FHTTPD_REQUEST) {
			if (headermade)
				php3_fhttpd_free_header();
			response = createresponse(1024, req->id, req->fd, req->ver_major > 0);
			if (response) {
				if (req->script_name && req->script_name_resolved) {
					len = strlen(req->script_name);
					strncpy(script_name_resolved_buffer, req->script_name_resolved, 2047);
					script_name_resolved_buffer[2047] = 0;

					GLOBAL(request_info).path_info = NULL;	/* Not supported */
					GLOBAL(request_info).path_translated = script_name_resolved_buffer;
					GLOBAL(request_info).query_string = req->query_string;
					GLOBAL(request_info).current_user = NULL;
					GLOBAL(request_info).current_user_length = 0;
					GLOBAL(request_info).request_method = method_names[req->method];
					GLOBAL(request_info).script_name = req->script_name;
					GLOBAL(request_info).content_length = req->databuffsize;
					GLOBAL(request_info).content_type = req->content_type;
					GLOBAL(request_info).cookies = NULL;
					for (i = 0; i < req->nlines; i++) {
						if (req->lines[i].paramc > 1) {
							if (req->lines[i].params[0]) {
								if (!strcasecmp(req->lines[i].params[0], "HTTP_COOKIE")) {
									if (req->lines[i].params[1]) {
										GLOBAL(request_info).cookies = req->lines[i].params[1];
									}
								}
							}
						}
					}
					/* doc_root configuration variable is currently ignored,
					   as it is with every other access method currently also. */

					/* We always need to emalloc() filename, since it gets placed into
					   the include file hash table, and gets freed with that table.
					   Notice that this means that we don't need to efree() it in
					   php3_destroy_request_info()! */
					if (GLOBAL(request_info).path_translated)
						GLOBAL(request_info).filename = estrdup(GLOBAL(request_info).path_translated);
					else
						GLOBAL(request_info).filename = NULL;

					return SUCCESS;
				} else {
					deleterequest(req);
					req = NULL;
					setalarm(idle_timeout);
				}
			} else {
				deleterequest(req);
				req = NULL;
				setalarm(idle_timeout);
			}
		} else {
			if (req->reqtype == FHTTPD_EXITOK) {
				exit_status = 1;
				deleterequest(req);
				req = NULL;
				setalarm(idle_timeout);
				return FAILURE;
			}
			deleterequest(req);
			req = NULL;
			setalarm(idle_timeout);
		}
	}
	if (global_alarmflag) {
		if (!exit_requested) {
			requestexit(server, 1);
			exit_requested = 1;
		}
	} else {
	exit_status = 1; 
	}
	return FAILURE;
}