X-Git-Url: https://hackdaworld.org/gitweb/?p=physik%2Fnlsop.git;a=blobdiff_plain;f=nlsop_server.c;h=ea4579164d0de297e6b3f790aca0746399fb819c;hp=e68a4493a90c7b5fdce4f689c51056e3e3df3b3b;hb=9ba8efd9cd20fa8047c4583dbadb18308401894a;hpb=1be202092955615e3448b1ab1b746347eb20cca3 diff --git a/nlsop_server.c b/nlsop_server.c index e68a449..ea45791 100644 --- a/nlsop_server.c +++ b/nlsop_server.c @@ -39,6 +39,7 @@ #include #include #include +#include #include "nlsop.h" #include "dfbapi.h" @@ -50,6 +51,18 @@ #include "nlsop_general.h" +/* globals */ +int *gi; +t_net *gnet; +t_event *gevent; +t_list *gc_list; +t_list *gg_list; +int alert; + +/* + * server specific stuff + */ + int usage(char *prog) { puts("usage:"); @@ -57,10 +70,6 @@ int usage(char *prog) return 1; } -/* - * server specific stuff - */ - int add_node(t_net *net,t_event *event,t_list *c_list,t_list *g_list) { int channel; @@ -86,11 +95,13 @@ int add_node(t_net *net,t_event *event,t_list *c_list,t_list *g_list) { if(data==NLSOP_GUI) { gui_chan=channel; list_add_element(g_list,&gui_chan,sizeof(int)); + printf("node is a gui\n"); } else if(data==NLSOP_CLIENT) { client.status=IDLE; client.channel=channel; list_add_element(c_list,&client,sizeof(t_client)); + printf("node is a client\n"); } else { printf("not a client or gui - lets kick that ass out of here!\n"); @@ -101,6 +112,8 @@ int add_node(t_net *net,t_event *event,t_list *c_list,t_list *g_list) { /* if we have a new node - care for it! */ event_math(net->connection[channel].fd,event,READ,ADD); + printf("\n"); + return 1; } @@ -194,6 +207,9 @@ int add_job(t_net *net,int chan,t_list *jl) { job.step=0; list_add_element(jl,&job,sizeof(t_job)); + + printf("job added: b=%f | c=%f | s=%f ...\n", + job.info.b,job.info.c,job.info.s); return 1; } @@ -227,16 +243,17 @@ int handle_node(t_net *net,t_event *event, t_client *c; t_job *j; + gi=&i; + for(i=0;iconnection[i].fd,&(event->rfds))) { - if(network_receive_chan(net,i,&data,1)==N_ERROR) { - printf("connection to client (ch %d) fucked up!\n",i); - event_math(net->connection[i].fd,event,READ,REMOVE); - network_close(net,i); - list_del_current(c_list); - return -1; - } + alert=0; + alarm(1); + network_receive_chan(net,i,&data,1); + alarm(0); + + if(alert==1) return -1; if(list_search_data(c_list,&i,sizeof(int))==L_SUCCESS) { /* it's a client */ @@ -250,12 +267,14 @@ int handle_node(t_net *net,t_event *event, c->status=IDLE; /* delete job entry */ list_del_current(job); + printf("job ended, saved and removed from list.\n"); } if(data==DC_OK) { save_job(net,i,j,DC_OK); /* inc progress state */ j->progress+=1; + printf("job at next level, saved.\n"); } if(data==DC_QUIT) { @@ -267,6 +286,7 @@ int handle_node(t_net *net,t_event *event, list_del_current(c_list); /* change job state */ j->status=IN_QUEUE; + printf("client terminating, job queued, client removed.\n"); } } @@ -296,6 +316,8 @@ int handle_node(t_net *net,t_event *event, } } } + + printf("\n"); return 1; } @@ -318,6 +340,8 @@ int distribute_jobs(t_event *event,void *allineed) { g_list=(t_list *)addr[2]; job=(t_list *)addr[3]; + printf("d: distributing jobs ...\n"); + count_j=list_count(job); count_c=list_count(c_list); @@ -394,6 +418,25 @@ int parse_incoming(t_event *event,void *allineed) { return 1; } +void destroy_it(int signum) { + + printf("connection to client (ch %d) fucked up!\n",*gi); + event_math(gnet->connection[*gi].fd,gevent,READ,REMOVE); + network_close(gnet,*gi); + if(list_search_data(gc_list,gi,sizeof(int))==L_SUCCESS) { + list_del_current(gc_list); + printf("removed client from list\n"); + } + if(list_search_data(gg_list,gi,sizeof(int))==L_SUCCESS) { + list_del_current(gg_list); + printf("removed gui from list\n"); + } + + alert=1; + alarm(0); + +} + /* * main program */ @@ -410,6 +453,11 @@ int main(int argc,char **argv) void *allyouneed; unsigned int addr[4]; + gnet=&net; + gevent=&event; + gc_list=&c_list; + gg_list=&g_list; + /* tzzz ... */ allyouneed=(void *)addr; addr[0]=(unsigned int)&net; @@ -441,6 +489,9 @@ int main(int argc,char **argv) return -1; } + /* install sighandler */ + signal(SIGALRM,destroy_it); + /* wait for events :) */ event_math(net.l_fd,&event,READ,ADD); printf("\nNLSOP_SERVER started!\n\n");