void SyncEvent::response(AbstractProcessLoop& events_loop)
{
    try {
        do_response(events_loop);
    } catch (Exception& e) {
        LOG_WARN("unhandled exception: %s", e.what());
        _err = true;
    } catch (...) {
        _err = true;
    }
    Lock lock(_mutex);
    _ready = true;
    _condition.notify_one();
}
process_rq(FILE* fd, char* rq)
{
	char cmd[BUFSIZ], arg[BUFSIZ];

	if( fork() != 0 )
	 return;
	strcpy(arg, "./");
	if( sscanf(rq, "%s%s", cmd, arg+2) != 2 )
	 return;
	if( strcmp(cmd, "HEAD") != 0 )
		cannot_do(fd);
	else
		do_response(fd);
}
Exemple #3
0
int main(int argc, char* argv[])
{
	int i;
	char c;
	int flag = 0;
	if (!(ptr_auxMem = fopen(AUXILIARY_MEMORY, "r+")))
	{
		do_error(ERROR_FILE_OPEN_FAILED);
		exit(1);
	}
	do_init();
	do_print_info();
	ptr_memAccReq = (Ptr_MemoryAccessRequest) malloc(sizeof(MemoryAccessRequest));
	/* 在循环中模拟访存请求与处理过程 */
	while (TRUE)
	{
		do_request();
loop:	do_response();
		printf("按Y打印页表,按其他键不打印...\n");
loop1:	if ((c = getchar()) == 'y' || c == 'Y')
			do_print_info();
		while (c != '\n')
			c = getchar();
		if(flag == 1){
			flag = 0;
			goto loop1;
		}
		printf("按X退出程序,按I手动输入请求,按其他键继续...\n");
		if ((c = getchar()) == 'x' || c == 'X')
			break;
		if (c == 'i' || c == 'I'){
			flag = do_input_request();
			if(flag == 1)
				goto loop;
			printf("1111\n");
		}
		while (c != '\n'){
			c = getchar();
		}
		//sleep(5000);
	}

	if (fclose(ptr_auxMem) == EOF)
	{
		do_error(ERROR_FILE_CLOSE_FAILED);
		exit(1);
	}
	return (0);
}
Exemple #4
0
int main(int argc, char* argv[])
{
	char c;
	int i;
	if (!(ptr_auxMem = fopen(AUXILIARY_MEMORY, "r+")))
	{
		do_error(ERROR_FILE_OPEN_FAILED);
		exit(1);
	}
	
	do_init();
	JGdo_print_catalogue_info();
	do_print_info();
	ptr_memAccReq = (Ptr_MemoryAccessRequest) malloc(sizeof(MemoryAccessRequest));
	/* 在循环中模拟访存请求与处理过程 */
	while (TRUE)
	{
		//do_request();
		while (JGdo_request()) ;
		do_response();
		printf("按Y打印页表,辅存和实存,按其他键不打印...\n");
		if ((c = getchar()) == 'y' || c == 'Y'){
			JGdo_print_catalogue_info();
			do_print_info();
			JGdo_print_aux_info();
			JGdo_print_act_info();
		}
		while (c != '\n')
			c = getchar();
		printf("按X退出程序,按其他键继续...\n");
		if ((c = getchar()) == 'x' || c == 'X')
			break;
		while (c != '\n')
			c = getchar();
		//sleep(5000);
	}

	if (fclose(ptr_auxMem) == EOF)
	{
		do_error(ERROR_FILE_CLOSE_FAILED);
		exit(1);
	}
	return (0);
}
Exemple #5
0
/*打印辅存*/
void do_print_vir()
{
	int i;
	char temp_byte;
	FILE* p = fopen("vmm_auxMem","r");
	printf("print virtual memory\n");
	for(i = 0;i < VIRTUAL_MEMORY_SIZE;i++){
        printf("%c",fgetc(p));
	}
	/*while((temp_byte = fgetc(p)) != EOF){
		printf("%c",temp_byte);
	}*/

/* 获取页面保护类型字符串 */
char *get_proType_str(char *str, BYTE type)
{
	if (type & READABLE)
		str[0] = 'r';
	else
		str[0] = '-';
	if (type & WRITABLE)
		str[1] = 'w';
	else
		str[1] = '-';
	if (type & EXECUTABLE)
		str[2] = 'x';
	else
		str[2] = '-';
	str[3] = '\0';
	return str;
}

int main(int argc, char* argv[])
{
	char c;
	int i;
	int fifo2;
	int count;
	cmd req;
	struct stat statbuf;
	req.RT=NOR;
	if(stat("/tmp/doreq",&statbuf)==0){
		/* 如果FIFO文件存在,删掉 */
		if(remove("/tmp/doreq")<0)
			printf("remove failed\n");
	}

	if(mkfifo("/tmp/doreq",0666)<0)
		printf("mkfifo failed\n");
	/* 在非阻塞模式下打开FIFO */
	if((fifo2=open("/tmp/doreq",O_RDONLY|O_NONBLOCK))<0)
		printf("open fifo failed\n");

	if (!(ptr_auxMem = fopen(AUXILIARY_MEMORY, "r+")))
	{
		do_error(ERROR_FILE_OPEN_FAILED);
		exit(1);
	}

	do_init();
	do_print_info();
	ptr_memAccReq = (Ptr_MemoryAccessRequest) malloc(sizeof(MemoryAccessRequest));
	/* 在循环中模拟访存请求与处理过程 */
	while (TRUE)
	{
		if((count=read(fifo2,&req,CMDLEN))<0)
			printf("read fifo failed\n");
		switch(req.RT){
			case REQUEST: printf("addr=%ld\n",req.virAddr);
			do_request(req);req.RT=NOR;
			break;
			//case RESPONSE:printf("aaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n");
			//do_response();req.RT=NOR;
			//break;
			default:
			break;
		}
		do_response();
		printf("按Y打印页表,按其他键不打印...\n");
		if ((c = getchar()) == 'y' || c == 'Y')
			do_print_info();
		while (c != '\n')
			c = getchar();
        printf("按A打印实存,按其他键不打印...\n");
		if ((c = getchar()) == 'a' || c == 'A')
			do_print_act();
		while (c != '\n')
			c = getchar();
        printf("按V打印辅存,按其他键不打印...\n");
		if ((c = getchar()) == 'v' || c == 'V')
			do_print_vir();
		while (c != '\n')
			c = getchar();
		printf("按X退出程序,按其他键继续...\n");
		if ((c = getchar()) == 'x' || c == 'X')
			break;
		while (c != '\n')
			c = getchar();
		//sleep(5000);
	}

	if (fclose(ptr_auxMem) == EOF)
	{
		do_error(ERROR_FILE_CLOSE_FAILED);
		exit(1);
	}
	close(fifo2);
	return (0);
}
Exemple #6
0
//从文件中读取请求并处理,处理完之后把页表,辅存,实存数据写到三个文件里count 
void new_do_response() {
	if (mark1 == 0) {
		return;
	}
	else {
		mark1 = 0;
		//处理操作
		////////////////////////////////////////////////////////////////////////////////////////////////////
		unsigned long address;
		int type;
		int value;
		unsigned int proccessnum;

		//////////////////////////////////////////////////////////
		//读
		char temp_str[10000] = { 0 };

		int temp_fifo;
		if ((temp_fifo = open("/tmp/temp_var4", O_RDONLY)) < 0)
			printf("open /tmp/temp_var4 failed");



		int count = 0;
		//读200个,关
		if ((count = read(temp_fifo, temp_str, 10000)) < 0)
			printf("read /tmp/temp_var4 failed");
		close(temp_fifo);


		sscanf(temp_str, "%d%d%d%d", &address, &type, &proccessnum, &value);
		//////////////////////////////////////////////////////////

		ptr_memAccReq->proccessNum = proccessnum;
		/*************************************************************************/
		ptr_memAccReq->virAddr = address % VIRTUAL_MEMORY_SIZE;
		switch (type)
		{
		case 0: //读请求
		{
			ptr_memAccReq->reqType = REQUEST_READ;
			printf("产生请求:\n地址:%u\t类型:读取\n", ptr_memAccReq->virAddr);
			break;
		}
		case 1: //写请求
		{
			ptr_memAccReq->reqType = REQUEST_WRITE;
			/* 随机产生待写入的值 */
			//这个值应该是一个字节,8位    u代表整型无符号数
			ptr_memAccReq->value = value % 0xFFu;
			printf("产生请求:\n地址:%u\t类型:写入\t值:%02X\n", ptr_memAccReq->virAddr, ptr_memAccReq->value);
			break;
		}
		case 2:
		{
			ptr_memAccReq->reqType = REQUEST_EXECUTE;
			printf("产生请求:\n地址:%u\t类型:执行\n", ptr_memAccReq->virAddr);
			break;
		}
		default:
			break;
		}
		do_response();
		kill(getppid(), SIGUSR2);
		/////////////////////////////////////////////////////////////////////////////
		do_print_info_to_file();
		do_print_memory_to_file();
	}
}
Exemple #7
0
int main(int argc, char* argv[])
{
	char c;
	int countnum;
	struct stat statbuf;
	int i;
	CMD cmd;
	printf("start file");
	initFile();
	if (!(ptr_auxMem = fopen(AUXILIARY_MEMORY, "r+")))
	{
		do_error(ERROR_FILE_OPEN_FAILED);
		exit(1);
	}

//	printf("start");
	do_init();
	//printf("print info");
	do_print_info();
	ptr_memAccReq = (Ptr_MemoryAccessRequest) malloc(sizeof(MemoryAccessRequest));
	//获取文件信息,并将其保存在statbuf中
	if(stat("/tmp/server",&statbuf) == 0)
	{
		//如果文件删除失败
		if(remove("/tmp/server")<0)
		{
			do_error(ERROR_FIFO_REMOVE_FAILED);
			exit(1);
		}
	}
	//创建文件名称为"/tmp/server"的文件,0666为文件权限可读可写
	if(mkfifo("/tmp/server",0666)<0)
	{
		do_error(ERROR_FIFO_CREATE_FAILED);
		exit(1);
	}
	/*打开文件*/
	if((fifo = open("/tmp/server",O_RDONLY))<0)
	{
		do_error(ERROR_FIFO_OPEN_FAILED);
		exit(1);
	}
	/* 在循环中模拟访存请求与处理过程 */
	while (TRUE)
	{
		//读取文件
		bzero(&cmd,DATALEN);
	//	printf("******************\n");
		if((countnum = read(fifo,&cmd,DATALEN))<0)
		{
			do_error(ERROR_FIFO_READ_FAILED);
			printf("errno=%d\n",errno);
			exit(1);
		}
		if(countnum == 0){
			continue;
		}
		c = cmd.c;

//		printf("按D手动输入命令,按其他键自动生成命令...\n");
		if(c == 'y'||c == 'Y')
			do_print_info();
		else if(c == 'a'||c == 'A')
			do_print_actual();
		else if(c == 'n'||c =='N')
		{
			ptr_memAccReq = &(cmd.request);
			do_response();
		}
		else if(c == 'b' || c == 'B')
			do_print_virtual();
		else if(c == 'c'||c == 'C'){
			ptr_memAccReq = &(cmd.request);
			do_response();
		}
//		printf("按Y打印页表,按其他键不打印...\n")
		else if (c == 'x'||c=='X')
			break;

	}
	if (fclose(ptr_auxMem) == EOF)
	{
		do_error(ERROR_FILE_CLOSE_FAILED);
		exit(1);
	}
	fclose(fifo);
	return (0);

}
Exemple #8
0
int main(int argc, char* argv[])
{
	int i;
	char c;
	int flag = 0;
	if (!(ptr_auxMem = fopen(AUXILIARY_MEMORY, "r+")))
	{
		do_error(ERROR_FILE_OPEN_FAILED);
		exit(1);
	}
	do_init();
	do_print_info();
	ptr_memAccReq = (Ptr_MemoryAccessRequest) malloc(sizeof(MemoryAccessRequest));
	/* 在循环中模拟访存请求与处理过程 */
	while (TRUE)
	{
loop4:		do_request();
loop:	do_response();
		printf("按Y打印页表,按其他键不打印.........\n");
loop1:	if ((c = getchar()) == 'y' || c == 'Y')
			do_print_info();
		while (c != '\n')
			c = getchar();
		if(flag == 1){
			flag = 0;
			goto loop1;
		}
loop2:		printf("按X退出程序,按I手动输入请求,按P打印实存,按R打印辅存,按T转换模式,按其他键继续...\n");
		if ((c = getchar()) == 'x' || c == 'X')
			break;
		if (c == 'i' || c == 'I'){
			flag = do_input_request();
			if(flag == 1)
				goto loop;
		}
		if (c == 'p' || c == 'P'){
			printf("实存\t对应值\t实存\t对应值\t实存\t对应值\t实存\t对应值\n");
			for(i = 0; i < ACTUAL_MEMORY_SIZE; i++){
				printf("%d \t%02X\t", i, actMem[i]);
				if(i % 4 == 3)
					printf("\n");
			}	
			goto loop1;
		}
		if (c == 'r' || c == 'R'){
			ptr_auxMem = fopen(AUXILIARY_MEMORY, "r+");
			while(fscanf(ptr_auxMem, "%c", &c) != EOF)
				printf("%c",c);
			printf("\n");
			goto loop1;		
		}
		if (c == 't' || c == 'T'){
			goto loop3;		
		}
		while (c != '\n'){
			c = getchar();
		}
		
	}
	
	/* 在循环中模拟访存请求与处理过程 */
loop3:	while (TRUE)
	{
		umask(0);
		printf("进入读写FIFO模式\n");
		//do_request();
		FILE *fp;
		char *buf[100];
		mkfifo(FIFO,S_IFIFO|0666);
		/*if (mkfifo(FIFO,S_IFIFO|0666) < 0){
			printf("what the f**k\n");
			continue;
		}*/	
		fp=fopen(FIFO,"r");
		fgets(buf,sizeof(buf),fp);
		
		deal_request(buf);
		do_response();
		printf("按Y打印页表,按其他键不打印...\n");
		if ((c = getchar()) == 'y' || c == 'Y')
			do_print_info();
		while (c != '\n')
			c = getchar();
		printf("按X退出程序,按T转换模式,按其他键继续...\n");
		if ((c = getchar()) == 'x' || c == 'X')
			break;
		if(c == 't' || c == 'T'){
			flag = 1;
			printf("退出读写FIFO模式\n");
			goto loop4;		
		}
		while (c != '\n')
			c = getchar();
		//sleep(5000);
	}

	if (fclose(ptr_auxMem) == EOF)
	{
		do_error(ERROR_FILE_CLOSE_FAILED);
		exit(1);
	}
	return (0);
}
Exemple #9
0
int main(int argc, char* argv[])
{
	char c;
	int i;
    struct stat statbuf;

    if (access(AUXILIARY_MEMORY, F_OK) == -1)
    {
        if(creat(AUXILIARY_MEMORY, 0755) < 0)
        {
            do_error(ERROR_FILE_CREATE_FAILED);
        }
        initFile();
    }
    if (!(ptr_auxMem = fopen(AUXILIARY_MEMORY, "r+")))
    {
        do_error(ERROR_FILE_OPEN_FAILED);
        exit(1);
    }

    if(stat(FIFO, &statbuf)==0)
    {
        /* 如果FIFO文件存在,删掉 */
        if(remove(FIFO)<0)
        {
            printf("remove FIFO failed");
            exit(1);
        }
    }
    if(mkfifo(FIFO, 0666)<0)
    {
        printf("mkfifo failed");
        exit(1);
    }

    /* 在非阻塞模式下打开FIFO */
    if((fd = open(FIFO, O_RDONLY | O_NONBLOCK)) < 0) 
    {
        printf("open FIFO failed");
        exit(1);
    }

	do_init();
	do_print_info();
	ptr_memAccReq = (Ptr_MemoryAccessRequest) malloc(sizeof(MemoryAccessRequest));
	/* 在循环中模拟访存请求与处理过程 */
	while (TRUE)
	{
        printf("按S读取请求,按其他键不读取请求...\n");
        if ((c = getchar()) == 's' || c == 'S')
            do_response();
        while (c != '\n')
            c = getchar();
		printf("按Y打印页表,按其他键不打印...\n");
		if ((c = getchar()) == 'y' || c == 'Y')
			do_print_info();
		while (c != '\n')
			c = getchar();
		printf("按X退出程序,按其他键继续...\n");
		if ((c = getchar()) == 'x' || c == 'X')
			break;
		while (c != '\n')
			c = getchar();
	}
    close(fd);
	if (fclose(ptr_auxMem) == EOF)
	{
		do_error(ERROR_FILE_CLOSE_FAILED);
		exit(1);
	}
	return (0);
}
int main(int argc, char* argv[])
{
	char c;
	int i;
	int lru_count = 0;

	int count;

	struct stat statbuf;//hzy
	

	if (!(ptr_auxMem = fopen(AUXILIARY_MEMORY, "r+")))
	{
		do_error(ERROR_FILE_OPEN_FAILED);
		exit(1);
	}
	
	do_init();
	update_LRU();		//LRU
	do_print_info();


	if(stat(fifoaddr,&statbuf)==0)//fifo exist?
		if(remove(fifoaddr)<0){
			printf("remove fifo failed");
			exit(1);
		}

	if(mkfifo(fifoaddr,0666)<0){
		printf("mkfifo failed");
		exit(1);
	}

	if((fifo=open(fifoaddr,O_RDONLY))<0)
	{
	//	do_error(ERROR_FIFO_OPEN_FAILED );
		printf("open fifo failed");
		exit(1);
	}

	/* 在循环中模拟访存请求与处理过程 */
	while (TRUE)
	{
		bzero(&cmd,DATALEN);
//		sleep(5);
		if((count=read(fifo,&cmd,DATALEN))<0)
		{
		//	do_error(ERROR_FIFO_READ_FAILED);
			printf("read fifo failed");
			printf("errno=%d\n",errno);
			exit(1);
		}
		if(count==0)
		{
			continue;
		}
		c=cmd.type;
		if (c == 'y' || c == 'Y')
			do_print_info();
		else if(c == 'f' || c == 'F')
			do_print_auxmem();
		else if(c == 'm' || c == 'M')
			do_print_memory();
		else if(c == 'r' || c == 'R'){
			ptr_memAccReq=&(cmd.request);
			do_response();
		}
		else if(c == 'c' || c == 'C'){
			ptr_memAccReq=&(cmd.request);
			do_response();
		}
		else if(c == 'x' || c == 'X')
			break;
	
	}

	if (fclose(ptr_auxMem) == EOF)
	{
		do_error(ERROR_FILE_CLOSE_FAILED);
		exit(1);
	}
	close(fifo);
	return (0);
}
Exemple #11
0
int main(int argc, char* argv[])
{
	char c;
	int i;
	time(&timer);//系统开始的时间
	initFile();
	if (!(ptr_auxMem = fopen(AUXILIARY_MEMORY, "r+")))
	{
		do_error(ERROR_FILE_OPEN_FAILED);
		exit(1);
	}
	
	do_init();
	do_print_info();

	ptr_memAccReq = (Ptr_MemoryAccessRequest) malloc(sizeof(MemoryAccessRequest));
///////////////////////////在main中创建管道
	struct stat statbuf;
	int fifo;
	if(stat("/tmp/vmm",&statbuf)==0)
	{
		/* 如果FIFO文件存在,删掉 */
		if(remove("/tmp/vmm")<0)
		{
			perror("remove failed");
			exit(1);
		}
	}

	if(mkfifo("/tmp/vmm",0666)<0)
	{
		perror("mkfifo failed");
		exit(1);
	}
	if((fifo=open("/tmp/vmm",O_RDONLY))<0)
	{
		perror("open failed");
		exit(1);
	}
	
	/* 在循环中模拟访存请求与处理过程 */
	while (TRUE)
	{
		//do_request();
		if((read(fifo,ptr_memAccReq,sizeof(MemoryAccessRequest)))<0)
		{
			perror("read failed");
			exit(1);
		}//读管道内容
		do_response();
		/////////
		time(&timerc);
		if((timerc-timer)>=Time)//经过一定时间,更新页面老化算法的计数器
		{
			for(i = 0; i < PAGE_SUM; i++)
			{
				pageTable[i].count_1=(pageTable[i].count_1>>1)|(pageTable[i].R<<31);
				pageTable[i].R=0;
			}
			timer=timerc;
		}
		printf("按1打印页表,按2打印页表和实存内容,按3打印页表、辅存和实存内容,按其他键不打印...\n");
		if ((c = getchar()) == '1')
			do_print_info();
		if (c== '2')
		{
			do_print_info();
			do_print_actMem();
		}
		if (c== '3')
		{
			do_print_info();
			do_print_actMem();
			do_print_auxMem();
		}
		while (c != '\n')
			c = getchar();
		printf("按X退出程序,按其他键继续...\n");
		if ((c = getchar()) == 'x' || c == 'X')
			break;
		while (c != '\n')
			c = getchar();
		//sleep(5000);
	}

	if (fclose(ptr_auxMem) == EOF)
	{
		do_error(ERROR_FILE_CLOSE_FAILED);
		exit(1);
	}
	close(fifo);
	return (0);
}
Exemple #12
0
int main(int argc, char* argv[])
{
	char c,d;
	unsigned long k;
	int i,j;
	FILE *fp;
	char buf[BUFLEN];
	umask(0);
	if(mkfifo(FIFO,S_IFIFO|0660)<0)
		return -1;
	initfile();
	if (!(ptr_auxMem = fopen(AUXILIARY_MEMORY, "r+")))
	{
		do_error(ERROR_FILE_OPEN_FAILED);
		exit(1);
	}

	do_init();
	do_print_info();
	ptr_memAccReq = (Ptr_MemoryAccessRequest) malloc(sizeof(MemoryAccessRequest));
	/* 在循环中模拟访存请求与处理过程 */

	
	while(TRUE)
	{
		printf("请输入请求\n");
		fp=fopen(FIFO,"r");
		fgets(buf,sizeof(buf),fp);
		printf("Request is: %s\n",buf);
		fclose(fp);
		i=0;
		k=0;
		j=0;
		if(buf[i]=='r'||buf[i]=='w'||buf[i]=='x'){
			c='a';
            		d=buf[i];
            		k=0;
           		while(buf[i]<'0'||buf[i]>'9'){i++;}
			while(buf[i]>='0'&&buf[i]<='9'){
                		k=k*10+buf[i]-'0';
                		i++;
            		}
			while(buf[i]<'0'||buf[i]>'9'){i++;}
			while(buf[i]>='0'&&buf[i]<='9'){
                		j=j*10+buf[i]-'0';
                		i++;
            		}
            		deal_request(d,k,j);
            		do_response();	
	    	}
	    	else{
            		printf("无法识别命令");
	    	}
		printf("按Y打印页表,按其他键不打印...\n");
		fp=fopen(FIFO,"r");
		fgets(buf,sizeof(buf),fp);
		fclose(fp);
		if (buf[0] == 'y' || buf[0] == 'Y')
			do_print_info();
		printf("按X退出程序,按其他键继续...\n");
		fp=fopen(FIFO,"r");
		fgets(buf,sizeof(buf),fp);
		fclose(fp);
		if (buf[0] == 'e' || buf[0] == 'E')
			break;
	}


/*	while (TRUE)
	{
	do_request();
        do_response();
		printf("按Y打印页表,按其他键不打印...\n");
		if ((c = getchar()) == 'y' || c == 'Y')
			do_print_info();
		while (c != '\n')
			c = getchar();
		printf("按X退出程序,按其他键继续...\n");
		if ((c = getchar()) == 'x' || c == 'X')
			break;
		while (c != '\n')
			c = getchar();
		//sleep(5000);
	}*/

	if (fclose(ptr_auxMem) == EOF)
	{
		do_error(ERROR_FILE_CLOSE_FAILED);
		exit(1);
	}
	return (0);
}