From: hackbard Date: Fri, 5 Nov 2004 11:00:07 +0000 (+0000) Subject: fixed all{you,i}need issues X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=1be202092955615e3448b1ab1b746347eb20cca3;p=physik%2Fnlsop.git fixed all{you,i}need issues --- diff --git a/nlsop_gui.c b/nlsop_gui.c index 477d264..8649442 100644 --- a/nlsop_gui.c +++ b/nlsop_gui.c @@ -222,10 +222,12 @@ int get_command(t_event *event,void *allineed) { t_net *net; t_display *display; t_input *input; + unsigned int addr[3]; - net=(t_net *)allineed; - display=(t_display *)(allineed+sizeof(t_net)); - input=(t_input *)(allineed+sizeof(t_net)+sizeof(t_display)); + memcpy(addr,allineed,3*sizeof(unsigned int)); + net=(t_net *)addr[0]; + display=(t_display *)addr[1]; + input=(t_input *)addr[2]; switch(input->content[0]) { case GUI_INFO: @@ -271,8 +273,15 @@ int main(int argc,char **argv) int fd; + unsigned int addr[3]; void *allyouneed; + allyouneed=(void *)addr; + + addr[0]=(unsigned int)&net; + addr[1]=(unsigned int)&display; + addr[2]=(unsigned int)&input; + /* default values */ strcpy(logfile,LOGFILE); strcpy(server_ip,""); @@ -310,11 +319,6 @@ int main(int argc,char **argv) return -1; } - allyouneed=malloc(sizeof(t_net)+sizeof(t_display)+sizeof(t_input)); - memcpy(allyouneed,&net,sizeof(t_net)); - memcpy(allyouneed+sizeof(t_net),&display,sizeof(t_display)); - memcpy(allyouneed+sizeof(t_net)+sizeof(t_display),&input,sizeof(t_input)); - /* input init */ input_init(&input,fd); input.mode=CONTENT_BUFFER|LINE_BUFFERED|INPUT_ECHO; diff --git a/nlsop_server.c b/nlsop_server.c index 5d11e48..e68a449 100644 --- a/nlsop_server.c +++ b/nlsop_server.c @@ -309,11 +309,14 @@ int distribute_jobs(t_event *event,void *allineed) { t_client *c; unsigned char data; d3_lattice d3l; + unsigned int addr[4]; - net=(t_net *)allineed; - c_list=(t_list *)(allineed+sizeof(t_net)); - g_list=(t_list *)(allineed+sizeof(t_net)+sizeof(t_list)); - job=(t_list *)(allineed+sizeof(t_net)+2*sizeof(t_list)); + memcpy(addr,allineed,4*sizeof(unsigned int)); + + net=(t_net *)addr[0]; + c_list=(t_list *)addr[1]; + g_list=(t_list *)addr[2]; + job=(t_list *)addr[3]; count_j=list_count(job); count_c=list_count(c_list); @@ -367,11 +370,14 @@ int parse_incoming(t_event *event,void *allineed) { t_net *net; t_list *c_list,*g_list,*job; + unsigned int addr[4]; + + memcpy(addr,allineed,4*sizeof(unsigned int)); - net=(t_net *)allineed; - c_list=(t_list *)(allineed+sizeof(t_net)); - g_list=(t_list *)(allineed+sizeof(t_net)+sizeof(t_list)); - job=(t_list *)(allineed+sizeof(t_net)+2*sizeof(t_list)); + net=(t_net *)addr[0]; + c_list=(t_list *)addr[1]; + g_list=(t_list *)addr[2]; + job=(t_list *)addr[3]; /* decide what to do */ if(FD_ISSET(net->l_fd,&(event->rfds))) { @@ -402,13 +408,14 @@ int main(int argc,char **argv) t_list g_list; t_list job; void *allyouneed; + unsigned int addr[4]; /* tzzz ... */ - allyouneed=malloc(sizeof(t_net)+3*sizeof(t_list)); - memcpy(allyouneed,&net,sizeof(t_net)); - memcpy(allyouneed+sizeof(t_net),&c_list,sizeof(t_list)); - memcpy(allyouneed+sizeof(t_net)+sizeof(t_list),&g_list,sizeof(t_list)); - memcpy(allyouneed+sizeof(t_net)+2*sizeof(t_list),&job,sizeof(t_list)); + allyouneed=(void *)addr; + addr[0]=(unsigned int)&net; + addr[1]=(unsigned int)&c_list; + addr[2]=(unsigned int)&g_list; + addr[3]=(unsigned int)&job; /* default values */ port=1025; @@ -421,6 +428,11 @@ int main(int argc,char **argv) /* 10 sec event timeout - distributing jobs */ event_set_timeout(&event,10,0); + /* list init */ + list_init(&c_list,1); + list_init(&g_list,1); + list_init(&job,1); + /* connect to server */ network_init(&net,1); network_set_listen_port(&net,port); @@ -431,6 +443,7 @@ int main(int argc,char **argv) /* wait for events :) */ event_math(net.l_fd,&event,READ,ADD); + printf("\nNLSOP_SERVER started!\n\n"); event_start(&event,allyouneed,parse_incoming,distribute_jobs); return 1;