]> hackdaworld.org Git - my-code/api.git/commitdiff
bugfixes
authorhackbard <hackbard>
Fri, 29 Oct 2004 12:26:08 +0000 (12:26 +0000)
committerhackbard <hackbard>
Fri, 29 Oct 2004 12:26:08 +0000 (12:26 +0000)
event/event.c
event/event.h
network/network.c
network/network.h

index e3d60abd979b3481967b7f28ce615d2963e629cd..398a1ddc5ba930c96c7b39247585a54bea741d79 100644 (file)
@@ -22,6 +22,14 @@ int event_init(t_event *event,int outfd) {
   return E_SUCCESS;
 }
 
+int event_set_timeout(t_event *event,int sec,int usec) {
+
+  event->timeout.tv_sec=sec;
+  event->timeout.tv_usec=usec;
+
+  return E_SUCCESS;
+}
+
 int event_math(int fd,t_event *event,char rw,char ar) {
 
   if(ar==ADD) {
index b17983bb23445a48846d1ad09a510f11c32e2580..aadd65f48e443a85ae43487a6641f985bb41e26b 100644 (file)
@@ -4,6 +4,7 @@
 #define EVENT_H
 
 /* includes */
+#define _GNU_SOURCE
 #include <stdio.h>
 #include <sys/select.h>
 #include <unistd.h>
@@ -38,6 +39,7 @@ typedef struct s_event {
 
 /* function prototypes */
 int event_init(t_event *event,int outfd);
+int event_set_timeout(t_event *event,int sec,int usec);
 int event_math(int fd,t_event *event,char rw,char ar);
 int event_start(t_event *event,void *ptr,
                 int (*callback0)(t_event *event,void *ptr),
index aefb7c2e9b8e4d00f67ad9bbd0ee08d7eb6ef9d4..7df2597fd2f313bf5fc52e61850594eccbac281e 100644 (file)
@@ -41,7 +41,7 @@ int network_listen(t_net *net) {
       perror("[network] setsockopt call");
       return N_ERROR;
     }
-    dprintf(event->outfd,"[network] reused address\n");
+    dprintf(net->outfd,"[network] reused address\n");
   }
 
   if(listen(net->l_fd,MAX_LISTEN_QUEUE)==-1) {
@@ -49,7 +49,7 @@ int network_listen(t_net *net) {
     return N_ERROR;
   }
 
-  dprintf(event->outfd,"[network] listen on %s port %d\n",
+  dprintf(net->outfd,"[network] listen on %s port %d\n",
           inet_ntoa(addr.sin_addr),net->l_port);
 
   return N_SUCCESS;
@@ -68,7 +68,7 @@ int network_shutdown(t_net *net) {
     return N_ERROR;
   }
 
-  dprintf(event->outfd,"[network] shutdown\n");
+  dprintf(net->outfd,"[network] shutdown\n");
 
   return N_SUCCESS;
 }
@@ -94,7 +94,7 @@ int network_manage_connection(t_net *net) {
           perror("[network] close call");
           return N_E_CLOSE;
         }
-        dprintf(event->outfd,"[network] connection %d closed\n",i);
+        dprintf(net->outfd,"[network] connection %d closed\n",i);
         net->connection[i].status=0;
       }
 
@@ -125,8 +125,8 @@ int network_manage_connection(t_net *net) {
             return N_E_CONNECT;
           }
 
-          dprintf(event->outfd,"[network] established connection to ");
-          dprintf(event->outfd,"%s port %d on channel %d\n",
+          dprintf(net->outfd,"[network] established connection to ");
+          dprintf(net->outfd,"%s port %d on channel %d\n",
                   net->connection[i].ip,net->connection[i].port,i);
           net->connection[i].status|=C_ESTABL;
 
@@ -144,12 +144,12 @@ int network_manage_connection(t_net *net) {
 int network_connect(t_net *net,int channel) {
 
   if(net->connection[channel].status&C_IN_USE) {
-    dprintf(event->outfd,"[network] connect failed, channel %02d in use\n",
+    dprintf(net->outfd,"[network] connect failed, channel %02d in use\n",
             channel);
     return N_E_IN_USE;
   }
   if(!(net->connection[channel].status&C_INFO_A)) {
-    dprintf(event->outfd,
+    dprintf(net->outfd,
             "[network] connect failed, missing config for chan %02d\n",channel);
     return N_E_NO_INFO;
   }
@@ -162,7 +162,7 @@ int network_connect(t_net *net,int channel) {
 int network_close(t_net *net,int channel) {
 
   if(!(net->connection[channel].status&C_ESTABL)) {
-    dprintf(event->outfd,"[network] close failed, channel %02d not active\n",
+    dprintf(net->outfd,"[network] close failed, channel %02d not active\n",
             channel);
     return N_E_NC;
   }
@@ -184,7 +184,7 @@ int network_close_all(t_net *net) {
 int network_set_connection_info(t_net *net,int channel,char *ip,int port) {
 
   if(net->connection[channel].status&C_IN_USE) {
-    dprintf(event->outfd,
+    dprintf(net->outfd,
             "[network] set connection failed, channel %02d in use\n",channel);
     return N_E_IN_USE;
   }
@@ -235,7 +235,7 @@ int network_manage_incoming(t_net *net) {
       strncpy(net->connection[channel].ip,inet_ntoa(addr.sin_addr),IP_DIGITS);
       net->connection[channel].port=ntohs(addr.sin_port);
       net->connection[channel].status=C_IN_USE|C_INFO_A|C_SOCKET|C_ESTABL;
-      dprintf(event->outfd,
+      dprintf(net->outfd,
               "[network] established connection from %s:%d, channel %d\n",
               net->connection[channel].ip,net->connection[channel].port,
               channel);
@@ -243,7 +243,7 @@ int network_manage_incoming(t_net *net) {
     }
   }
 
-  dprintf(event->outfd,"[network] maximum connections reached\n");
+  dprintf(net->outfd,"[network] maximum connections reached\n");
   return N_E_MAXC;
 }
  
@@ -267,14 +267,20 @@ int network_send(int fd,unsigned char *data,int datasize) {
 
 int network_receive(int fd,unsigned char *data,int datasize) {
 
-  int count;
+  int count,left;
 
-  if((count=read(fd,data,datasize))==-1) {
-    perror("[network] read call");
-    return N_ERROR;
+  count=0;
+  left=datasize;
+
+  while(left) {
+    if((count=read(fd,data,datasize))==-1) {
+      perror("[network] read call");
+      return N_ERROR;
+    }
+    left-=count;
   }
 
-  return count;
+  return datasize;
 }
 
 int network_udp_listen_init(t_net *net) {
@@ -299,10 +305,10 @@ int network_udp_listen_init(t_net *net) {
       perror("[network] setsockopt call (udp)");
       return N_ERROR;
     }
-    dprintf(event->outfd,"[network] reused address (udp)\n");
+    dprintf(net->outfd,"[network] reused address (udp)\n");
   }
 
-  dprintf(event->outfd,"[network] listening on port %d (udp)\n",
+  dprintf(net->outfd,"[network] listening on port %d (udp)\n",
           net->l_udp_port);
 
   if((net->s_udp_fd=socket(AF_INET,SOCK_DGRAM,0))==-1) {
@@ -325,7 +331,7 @@ int network_udp_receive(t_net *net,int channel, unsigned char *data,int count) {
   }
 
   if(strncmp(net->connection[channel].ip,inet_ntoa(addr.sin_addr),IP_DIGITS)) {
-    dprintf(event->outfd,"[network] packet from unknown: %s\n",
+    dprintf(net->outfd,"[network] packet from unknown: %s\n",
             inet_ntoa(addr.sin_addr));
     return N_UDP_WRONG_SENDER;
   }
index 281a43feddf10460d72c4637d1b3b331d37cb1e7..bfb4ab4baad76436565c27044370fdbd79804a47 100644 (file)
@@ -4,6 +4,7 @@
 #define NETWORK_H
 
 /* includes */
+#define _GNU_SOURCE
 #include <stdio.h>
 #include <errno.h>
 #include <string.h>