X-Git-Url: https://hackdaworld.org/gitweb/?p=physik%2Fnlsop.git;a=blobdiff_plain;f=nlsop_server.c;h=d67fae87f596c80b5564d52a5fa33f23dc315174;hp=353979bc3c2b43be36747183b8bfb315e5d919d2;hb=a13637c42a53e4bebeb12e2a81413c5fdd83764b;hpb=4c5373958d4b8d38e51560ba898cfd0473d7c108 diff --git a/nlsop_server.c b/nlsop_server.c index 353979b..d67fae8 100644 --- a/nlsop_server.c +++ b/nlsop_server.c @@ -122,51 +122,41 @@ int add_node(void) { return 1; } -int save_job(unsigned char dc) { +int save_job(unsigned char dc,unsigned char *ack) { char filename[128]; int fd; int ret; d3_lattice d3l; info info; - unsigned char data; t_job *j; j=(t_job *)priv.job.current->data; - printf("receiving data from client (%d)\n",j->size); - data=DATA_OK; - - /* initial data_ok to start transmit on client */ - network_send_chan(&(priv.net),gi,&data,sizeof(unsigned char)); + printf("receiving data from client (#cells=%d)\n",j->size); network_receive_chan(&(priv.net),gi,(unsigned char *)&d3l, sizeof(d3_lattice)); - network_send_chan(&(priv.net),gi,&data,sizeof(unsigned char)); - printf("debug: got d3_lattice\n"); - network_receive_chan(&(priv.net),gi,(unsigned char *)&info,sizeof(info)); - network_send_chan(&(priv.net),gi,&data,sizeof(unsigned char)); - printf("debug: got info\n"); - network_receive_chan(&(priv.net),gi,j->ac,j->size*sizeof(unsigned char)); - network_send_chan(&(priv.net),gi,&data,sizeof(unsigned char)); - printf("debug: got ac\n"); - network_receive_chan(&(priv.net),gi,(unsigned char *)j->cc, j->size*sizeof(int)); - network_send_chan(&(priv.net),gi,&data,sizeof(unsigned char)); - printf("debug: got cc\n"); - network_receive_chan(&(priv.net),gi,(unsigned char *)&(j->step),sizeof(int)); - network_send_chan(&(priv.net),gi,&data,sizeof(unsigned char)); - printf("debug: got steps\n"); + network_receive_chan(&(priv.net),gi,ack,sizeof(unsigned char)); if(dc!=DC_QUIT) { - snprintf(filename,128,"./data/nlsop_b%f_c%f_s%f_ds%d_dr%f_-_%d_of_%d.save", - j->info.b,j->info.c,j->info.s, - j->info.diff_rate,j->info.dr_ac, - j->step,j->info.steps); + if(*ack==DATA_OK) + snprintf(filename,128, + "./data/nlsop_b%f_c%f_s%f_ds%d_dr%f_-_%d_of_%d.save", + j->info.b,j->info.c,j->info.s, + j->info.diff_rate,j->info.dr_ac, + j->step,j->info.steps); + else + snprintf(filename,128, + "./data/nlsop_b%f_c%f_s%f_ds%d_dr%f_-_%d_of_%d.corrupt", + j->info.b,j->info.c,j->info.s, + j->info.diff_rate,j->info.dr_ac, + j->step,j->info.steps); if((fd=open(filename,O_WRONLY|O_CREAT))<0) { printf("FATAL: unable to open file %s\n",filename); return -1; @@ -247,19 +237,26 @@ int send_status(void) { data=GUI_INFO; - count=list_count(&(priv.job)); - - printf("sending job info\n"); - network_send_chan(&(priv.net),gi,&data,sizeof(unsigned char)); - network_send_chan(&(priv.net),gi,(unsigned char *)&count,sizeof(int)); + printf("sending job + client list ...\n"); + count=list_count(&(priv.job)); + network_send_chan(&(priv.net),gi,(unsigned char *)&count,sizeof(int)); list_reset(&(priv.job)); for(i=0;idata,sizeof(t_job)); list_next(&(priv.job)); } + count=list_count(&(priv.client)); + network_send_chan(&(priv.net),gi,(unsigned char *)&count,sizeof(int)); + list_reset(&(priv.client)); + for(i=0;idata, + sizeof(t_client)); + list_next(&(priv.client)); + } + return 1; } @@ -268,6 +265,7 @@ int handle_node(void) { unsigned char data; t_client *c; t_job *j; + unsigned char ack; for(gi=0;gidata; if(data==DC_END) { - save_job(DC_END); + save_job(DC_END,&ack); /* reset client */ c->status=IDLE; /* free job memory */ @@ -298,22 +296,32 @@ int handle_node(void) { } if(data==DC_OK) { - save_job(DC_OK); + save_job(DC_OK,&ack); /* inc progress state */ j->progress+=1; printf("job at next level, saved.\n"); } if(data==DC_QUIT) { - save_job(DC_QUIT); + ack=0; + save_job(DC_QUIT,&ack); /* network disconnect */ event_math(priv.net.connection[gi].fd,&(priv.event),READ,REMOVE); network_close(&(priv.net),gi); /* del from client list */ list_del_current(&(priv.client)); - /* change job state */ - j->status=IN_QUEUE; - printf("client terminating, job queued, client removed.\n"); + /* change job state (or reset it if corrupted) */ + if(ack==DATA_OK) { + j->status=IN_QUEUE; + printf("client terminating, job queued, client removed.\n"); + } + else { + j->channel=-1; + j->status=IN_QUEUE; + j->progress=0; + j->step=0; + printf("client terminating, corr. job cleared , client removed.\n"); + } } } @@ -458,6 +466,8 @@ int parse_incoming(t_event *event,void *allineed) { void destroy_it(int signum) { + t_job *j; + printf("connection to client (ch %d) fucked up!\n",gi); event_math(priv.net.connection[gi].fd,&(priv.event),READ,REMOVE); network_close(&(priv.net),gi); @@ -465,6 +475,14 @@ void destroy_it(int signum) { list_del_current(&(priv.client)); printf("removed client from list\n"); } + if(list_search_data(&(priv.job),&gi,sizeof(int))==L_SUCCESS) { + printf("associated job found. resetting & queueing job.\n"); + j=(t_job *)priv.job.current->data; + j->channel=-1; + j->status=IN_QUEUE; + j->progress=0; + j->step=0; + } if(list_search_data(&(priv.gui),&gi,sizeof(int))==L_SUCCESS) { list_del_current(&(priv.gui)); printf("removed gui from list\n");