📄 server_cmd.h
字号:
void server_cmd(){ /* attach parent's shared memory */ ap=(struct area *)shmat(shmid, 0, 0); /* note: shmid is still set correctly */while(1){if(ap->flag_server_cmd==-1) break;else{ int i,fo; char cmd[80],cmd2[80]; char buffer[520]={};//check M if(ap->Mstate_gl==0) { printf("M_server error!\n"); exit(EXIT_FAILURE); } while(i=getchar()) { switch(i) { case '1': { int M; char A_res[10]={},B_res[10]={},M_res[10]={}; printf("\ninput the command:"); scanf("%s%s",cmd,cmd2); strcat(cmd," "); strcat(cmd,cmd2); if((ap->Astate_gl==1)&&(ap->Bstate_gl==1)) { socket_com(ap->Ahost_name_gl,ap->Amain_port_gl,cmd); strcpy(A_res,check_error); socket_com(ap->Bhost_name_gl,ap->Bmain_port_gl,cmd); strcpy(B_res,check_error); //compare the result now if(strcmp(A_res,B_res)==0) { if(socket_com(ap->Ahost_name_gl,ap->Amain_port_gl,"Accept the result!\n")==-1) { socket_com(ap->Bhost_name_gl,ap->Bmain_port_gl,"Accept the result!\n"); } printf("A_res:%s is accepted\n",A_res); } else { M=liansuo_function(); sprintf(M_res,"%d",M); if(strcmp(A_res,M_res)==0) { socket_com(ap->Ahost_name_gl,ap->Amain_port_gl,"Accept the result!\n"); printf("A_res:%s is accepted\n",A_res); } else if(strcmp(B_res,M_res)==0) { printf("B_res:%s is accepted\n",B_res); socket_com(ap->Bhost_name_gl,ap->Bmain_port_gl,"Accept the result!\n"); } } } else if((ap->Astate_gl==0)&&(ap->Bstate_gl==1)) { socket_com(ap->Bhost_name_gl,ap->Bmain_port_gl,cmd); strcpy(B_res,check_error); M=liansuo_function(); sprintf(M_res,"%d",M); if(strcmp(B_res,M_res)==0) { printf("B_res:%s is accepted\n",B_res); socket_com(ap->Bhost_name_gl,ap->Bmain_port_gl,"Accept the result!\n"); } else printf("重发命令\n"); } else if((ap->Astate_gl==1)&&(ap->Bstate_gl==0)) { socket_com(ap->Ahost_name_gl,ap->Amain_port_gl,cmd); strcpy(A_res,check_error); M=liansuo_function(); sprintf(M_res,"%d",M); if(strcmp(A_res,M_res)==0) { printf("A_res:%s is accepted\n",A_res); socket_com(ap->Ahost_name_gl,ap->Amain_port_gl,"Accept the result!\n"); } else printf("重发命令\n"); } else printf("两台都未启动\n"); print(); break; }//case1 case '2': { printf("\ninput the process name for call:"); scanf("%s%s",cmd,cmd2); strcat(cmd," "); strcat(cmd,cmd2); if((ap->Astate_gl==1)&&(ap->Bstate_gl==1)) { printf("与A B机通信成功!\n"); socket_com(ap->Ahost_name_gl,ap->Amain_port_gl,cmd); printf("%s\n",check_error); socket_com(ap->Bhost_name_gl,ap->Bmain_port_gl,cmd); printf("%s\n",check_error); } else if((ap->Astate_gl==1)&&(ap->Bstate_gl==0)) { printf("与A机通信成功,B机需人工启动!\n"); socket_com(ap->Ahost_name_gl,ap->Amain_port_gl,cmd); printf("%s\n",check_error); } else if((ap->Astate_gl==0)&&(ap->Bstate_gl==1)) { printf("与B机通信成功,A机需人工启动!\n"); socket_com(ap->Bhost_name_gl,ap->Bmain_port_gl,cmd); printf("%s\n",check_error); } else printf("与A B机通信都不成功,都需人工启动!\n"); print(); break; }//case2 case '0': { // set semaphore buf_sem.sem_op=-1; semop(semid, (struct sembuf *) &buf_sem, 1); ap->flag_server_cmd=-1; // clear semaphore buf_sem.sem_op=1; semop(semid, (struct sembuf *) &buf_sem, 1); break; } }//switch if(i=='0') break; }//while(i)}//else}//while(1)exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -