bugfixes + improvements
authorhackbard <hackbard>
Fri, 5 Nov 2004 14:47:26 +0000 (14:47 +0000)
committerhackbard <hackbard>
Fri, 5 Nov 2004 14:47:26 +0000 (14:47 +0000)
makefile
nlsop_gui.c
nlsop_server.c

index d17b37e..338db5d 100644 (file)
--- a/makefile
+++ b/makefile
@@ -16,13 +16,13 @@ clean:
        rm -f $(OBJS) ivac
 
 links:
        rm -f $(OBJS) ivac
 
 links:
-       ln -sf ../../api/event/event.{c,h} .
-       ln -sf ../../api/input/input.{c,h} .
-       ln -sf ../../api/display/display.{c,h} .
-       ln -sf ../../api/audio/audio.{c,h} .
-       ln -sf ../../api/network/network.{c,h} .
-       ln -sf ../../api/list/list.{c,h} .
-       ln -sf ../../api/fourier/fourier.{c,h} .
-       ln -sf ../../api/bmp/bmp.{c,h} .
+       ln -sf ../api/event/event.{c,h} .
+       ln -sf ../api/input/input.{c,h} .
+       ln -sf ../api/display/display.{c,h} .
+       ln -sf ../api/audio/audio.{c,h} .
+       ln -sf ../api/network/network.{c,h} .
+       ln -sf ../api/list/list.{c,h} .
+       ln -sf ../api/fourier/fourier.{c,h} .
+       ln -sf ../api/bmp/bmp.{c,h} .
 
 remake: clean all
 
 remake: clean all
index 8649442..a7b447d 100644 (file)
@@ -314,7 +314,7 @@ int main(int argc,char **argv)
     return -1;
   }
 
     return -1;
   }
 
-  if((fd=open(logfile,O_WRONLY,O_CREAT))<0) {
+  if((fd=open(logfile,O_WRONLY|O_CREAT))<0) {
     printf("unable to open file %s\n",logfile);
     return -1;
   }
     printf("unable to open file %s\n",logfile);
     return -1;
   }
index e68a449..8472491 100644 (file)
@@ -39,6 +39,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <signal.h>
 
 #include "nlsop.h"
 #include "dfbapi.h"
 
 #include "nlsop.h"
 #include "dfbapi.h"
 
 #include "nlsop_general.h"
 
 
 #include "nlsop_general.h"
 
+/* globals */
+int *gi;
+t_net *gnet;
+t_event *gevent;
+t_list *gc_list;
+int alert;
+
+/*
+ * server specific stuff
+ */
+
 int usage(char *prog)
 {
  puts("usage:");
 int usage(char *prog)
 {
  puts("usage:");
@@ -57,10 +69,6 @@ int usage(char *prog)
  return 1;
 }
 
  return 1;
 }
 
-/*
- * server specific stuff
- */
-
 int add_node(t_net *net,t_event *event,t_list *c_list,t_list *g_list) {
 
   int channel;
 int add_node(t_net *net,t_event *event,t_list *c_list,t_list *g_list) {
 
   int channel;
@@ -86,11 +94,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));
   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));
   }
   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");
   }
   else {
     printf("not a client or gui - lets kick that ass out of here!\n");
@@ -227,16 +237,17 @@ int handle_node(t_net *net,t_event *event,
   t_client *c;
   t_job *j;
 
   t_client *c;
   t_job *j;
 
+  gi=&i;
+
   for(i=0;i<MAX_CONNECTIONS;i++) {
     if(FD_ISSET(net->connection[i].fd,&(event->rfds))) {
 
   for(i=0;i<MAX_CONNECTIONS;i++) {
     if(FD_ISSET(net->connection[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 */
 
       if(list_search_data(c_list,&i,sizeof(int))==L_SUCCESS) {
         /* it's a client */
@@ -394,6 +405,18 @@ int parse_incoming(t_event *event,void *allineed) {
   return 1;
 }
 
   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);
+  list_del_current(gc_list);
+
+  alert=1;
+  alarm(0);
+
+}
+
 /*
  * main program
  */
 /*
  * main program
  */
@@ -410,6 +433,10 @@ int main(int argc,char **argv)
   void *allyouneed;
   unsigned int addr[4];
 
   void *allyouneed;
   unsigned int addr[4];
 
+  gnet=&net;
+  gevent=&event;
+  gc_list=&c_list;
+
   /* tzzz ... */
   allyouneed=(void *)addr;
   addr[0]=(unsigned int)&net;
   /* tzzz ... */
   allyouneed=(void *)addr;
   addr[0]=(unsigned int)&net;
@@ -441,6 +468,9 @@ int main(int argc,char **argv)
     return -1;
   }
 
     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");
   /* wait for events :) */
   event_math(net.l_fd,&event,READ,ADD);
   printf("\nNLSOP_SERVER started!\n\n");