void syncthread0(void *a) { Queue *q; Syncpath *s; threadsetname("syncthread"); startclient(); q = a; for(;;){ s = qrecv(q); assert(s->state == SyncStart); syncstat(s); if(s->state == SyncError){ Err: syncfinish(s); continue; } synctriage(s); if(s->state == SyncError) goto Err; if(s->triage != DoNothing) tralog("%P %s%s: [%$] [%$]", s->p, s->conflict ? "conflict " : "", workstr(s, s->triage), s->a.s, s->b.s); qsend(s->sync->triageq, s); } }
void threadmain(int argc, char **argv) { int i; Path *p; fmtinstall('H', encodefmt); fmtinstall('P', pathfmt); fmtinstall('R', rpcfmt); fmtinstall('$', statfmt); fmtinstall('V', vtimefmt); ARGBEGIN{ case 'D': debug |= dbglevel(EARGF(usage())); break; case 'V': traversion(); default: usage(); }ARGEND if(argc < 1) usage(); startclient(); repl = dialreplica(argv[0]); argc--; argv++; fprint(2, "scan..."); if(argc == 0){ fprint(2, "%P...", nil); if(rpcstat(repl, nil) == nil) sysfatal("rpcstat: %s", rpcerror()); }else{ for(i=0; i<argc; i++){ p = strtopath(argv[i]); fprint(2, "%P...", p); if(rpcstat(repl, p) == nil) sysfatal("rpcstat: %s", rpcerror()); } } fprint(2, "hangup..."); rpchangup(repl); fprint(2, "close..."); replclose(repl); fprint(2, "exit\n"); threadexitsall(nil); }
static void kidthread(void *a) { void *p; Kids *k; k = a; threadsetname("kidthread"); startclient(); k->nk = rpckids(k->repl, k->p, &k->k); if(k->nk < 0) k->err = rpcerror(); endclient(); threadstate("kidthread end"); p = k->c; send(k->c, k); threadstate("DONE %p", p); }
int main() { //启动客户端,连接服务器,得到socket描述符 int st = startclient(); //输入请求并发送,order存放请求选项 while (1) { //输入请求,错误则重新输入 int order = getorder(); if (order == -1) { continue; } //将请求信息发送给服务器 send(st, &order, sizeof(order), 0); //选项1代表下载文件 if (order == 1) { download(st); } //选项2代表上传文件 if (order == 2) { upload(st); } //选项3代表关闭连接 if (order == 3) { close(st); break; } } return 0; }
void *mang_alls(void *argv) { //side is passed as absolute frame char *serverip,*parameter; parameter=(char*)argv; serverip=strtok(parameter,"/"); int portno=atoi(strtok(NULL,"/")); int side=atoi(strtok(NULL,"/")),sockfd,k,noworr,socketid; char buffer[256]; char *info[20]; for(k=0;k<20;k++) { info[k]=(char *)malloc(20*(sizeof(char))); } sockfd=startclient(serverip,portno); char help[20]; gethostname(help,20); sprintf(buffer,"%d/0/",side); strcat(buffer,help); noworr=send(sockfd,buffer,strlen(buffer),0); noworr=recv(sockfd,buffer,256,0); pthread_t man_left,man_right,man_bottom,man_top,mang; //tokenize buffer decryptstring(buffer,info); gameinfo.me=side; gameinfo.side[side].mepoints=0; gameinfo.side[side].mequeen=NO; int i,j=0; //updatemygameinfo; gameinfo.playercount=atoi(info[8])+1; //make sure abotut this that not added twice gameinfo.friction=atof(info[9])*0.005; gameinfo.erest=atof(info[10])*0.001; gameinfo.turn=atoi(info[11]); for(i=0;i<4;i++) { gameinfo.side[i].there=atoi(info[i]); strcpy(gameinfo.side[i].ip,info[i+4]); } //figure out positions of others fromgame info, for(i=0;i<4;i++) { if(i==side) { printf("side==%d\n",side); gameinfo.side[side].there=occupied; gethostname(gameinfo.side[side].ip,20); continue; } //add for server too if(atoi(info[i])==occupied) { if(i!=atoi(info[12])) { socketid=startclient(info[4+i],portno);gethostname(help,20); sprintf(buffer,"%d/1/",side); strcat(buffer,help); //why 1 -it implies already hve info?? noworr=send(socketid,buffer,strlen(buffer),0); } else { socketid=sockfd; } gameinfo.side[i].sock=socketid; switch(i) { case left: {pthread_create(&man_left,NULL,manl,"1");break;} case right: {pthread_create(&man_right,NULL,manr,"3");break;} case top: {pthread_create(&man_top,NULL,mant,"2");break;} case bottom: {pthread_create(&man_bottom,NULL,manb,"0");break;} } } } char tem_ps[10];printf("exiting with portno=%d\n",portno); sprintf(tem_ps,"%d",portno); pthread_create(&mang,NULL,mang_all,tem_ps); getc(stdin); }