The timeout should be always handled. Now we use pselect in the loops.
authorviric@mandarina
Sun, 07 Oct 2007 21:59:12 +0200
changeset 67 d7405e4f12e1
parent 66 b2469563a1dc
child 68 560d86d7dfc1
The timeout should be always handled. Now we use pselect in the loops.
client.c
eth_proto.c
server.c
--- a/client.c	Sun Oct 07 00:10:17 2007 +0200
+++ b/client.c	Sun Oct 07 21:59:12 2007 +0200
@@ -9,6 +9,7 @@
 #include <sys/types.h>
 #include <sys/select.h>
 #include <unistd.h>
+#include <signal.h>
 #include <errno.h>
 #include <string.h>
 
@@ -23,9 +24,14 @@
         Net_c_send net_send)
 {
     fd_set read_set;
+    sigset_t sigold,signoalarm;
     int maxfd;
     int res;
 
+    /* Prepare the sigset for blocking alarm */
+    sigemptyset(&signoalarm);
+    sigaddset(&signoalarm, SIGALRM);
+
     do
     {
         FD_ZERO(&read_set);
@@ -35,7 +41,17 @@
 
         net_prepare(&read_set, &maxfd);
 
-        res = select(maxfd + 1, &read_set, 0, 0, 0);
+        /* Prepare checking for timeout */
+        sigprocmask(SIG_BLOCK, &signoalarm, &sigold);
+
+#ifdef linux
+        if (command_line.s_param.serve_eth)
+            /* This will check if the timeout occurred,
+             * and will not do anything otherwise. */
+            eth_proto_process_timeouts();
+#endif
+
+        res = pselect(maxfd + 1, &read_set, 0, 0, 0, &sigold);
 #ifdef linux
         if (command_line.c_param.transport == ETHERNET)
             /* If there isn't a good result, we quit */
--- a/eth_proto.c	Sun Oct 07 00:10:17 2007 +0200
+++ b/eth_proto.c	Sun Oct 07 21:59:12 2007 +0200
@@ -209,7 +209,7 @@
     {
         edata.send_retries_left -= 1;
         edata.send_acked = 0;
-        program_timeout(2);
+        program_timeout(1);
     }
     else /* strange case, data not sent */
     {
--- a/server.c	Sun Oct 07 00:10:17 2007 +0200
+++ b/server.c	Sun Oct 07 21:59:12 2007 +0200
@@ -10,6 +10,7 @@
 #include <sys/select.h>
 #include <unistd.h>
 #include <errno.h>
+#include <signal.h>
 #include <string.h>
 
 #include "main.h"
@@ -18,6 +19,7 @@
 static void loop()
 {
     fd_set read_set;
+    sigset_t sigold,signoalarm;
     int maxfd;
     int stdin_opened;
     int res;
@@ -27,6 +29,10 @@
     else
         stdin_opened = 1;
 
+    /* Prepare the sigset for blocking alarm */
+    sigemptyset(&signoalarm);
+    sigaddset(&signoalarm, SIGALRM);
+
     do
     {
         FD_ZERO(&read_set);
@@ -45,8 +51,18 @@
             s_eth_prepare_read_fdset(&read_set, &maxfd);
 #endif /* linux */
 
+        /* Prepare checking for timeout */
+        sigprocmask(SIG_BLOCK, &signoalarm, &sigold);
+
+#ifdef linux
+        if (command_line.s_param.serve_eth)
+            /* This will check if the timeout occurred,
+             * and will not do anything otherwise. */
+            eth_proto_process_timeouts();
+#endif
+
         /* Will block */
-        res = select(maxfd + 1, &read_set, 0, 0, 0);
+        res = pselect(maxfd + 1, &read_set, 0, 0, 0, &sigold);
 #ifdef linux
         if (command_line.s_param.serve_eth)
             eth_proto_process_timeouts();