OSDN Git Service

test: get out of the endless while loop, when bind failed
[uclinux-h8/uClibc.git] / test / nptl / tst-cancel4.c
index 874de67..4ba4045 100644 (file)
@@ -83,7 +83,30 @@ static pthread_barrier_t b2;
 # define IPC_ADDVAL 0
 #endif
 
-#define WRITE_BUFFER_SIZE 4096
+/* The WRITE_BUFFER_SIZE value needs to be chosen such that if we set
+   the socket send buffer size to '1', a write of this size on that
+   socket will block.
+
+   The Linux kernel imposes a minimum send socket buffer size which
+   has changed over the years.  As of Linux 3.10 the value is:
+
+     2 * (2048 + SKB_DATA_ALIGN(sizeof(struct sk_buff)))
+
+   which is attempting to make sure that with standard MTUs,
+   TCP can always queue up at least 2 full sized packets.
+
+   Furthermore, there is logic in the socket send paths that
+   will allow one more packet (of any size) to be queued up as
+   long as some socket buffer space remains.   Blocking only
+   occurs when we try to queue up a new packet and the send
+   buffer space has already been fully consumed.
+
+   Therefore we must set this value to the largest possible value of
+   the formula above (and since it depends upon the size of "struct
+   sk_buff", it is dependent upon machine word size etc.) plus some
+   slack space.  */
+
+#define WRITE_BUFFER_SIZE 16384
 
 /* Cleanup handling test.  */
 static int cl_called;
@@ -758,11 +781,7 @@ tf_sigpause (void *arg)
 
   pthread_cleanup_push (cl, NULL);
 
-  /* Just for fun block the cancellation signal.  We need to use
-     __xpg_sigpause since otherwise we will get the BSD version.  */
-  //__xpg_sigpause (SIGCANCEL);
-
-  __sigpause (SIGCANCEL, 1);
+  sigpause (SIGCANCEL);
 
   pthread_cleanup_pop (0);
 
@@ -996,6 +1015,8 @@ tf_accept (void *arg)
       if (++tries > 10)
        {
          printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
+         /* prevent endless loop, when bind fails forever */
+         exit (1);
        }
 
       strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-1-XXXXXX");