]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix for compiling src/unlinkd.cc with kqueue and epoll.
authorwessels <>
Tue, 24 Apr 2007 12:30:36 +0000 (12:30 +0000)
committerwessels <>
Tue, 24 Apr 2007 12:30:36 +0000 (12:30 +0000)
When Squid is compiled with --enable-kqueue or --enable-epoll, we're
not supposed to use any fd_set structures.  unlinkd.cc uses select()
to pause and wait for for feedback from the external unlinkd helper.
But when using kqueue or epoll, unlinkd.cc will have to use "usleep"
emulation rather than select.

The contents of lib/xusleep.c and include/xusleep.h have been copied
from Squid-2 sources.

include/xusleep.h [new file with mode: 0644]
lib/Makefile.am
lib/xusleep.c [new file with mode: 0644]
src/unlinkd.cc

diff --git a/include/xusleep.h b/include/xusleep.h
new file mode 100644 (file)
index 0000000..49b0bb0
--- /dev/null
@@ -0,0 +1 @@
+SQUIDCEXTERN int xusleep(unsigned int);
index 7523ddf1322429a1b2cef1a0eec1e9767ab31bc0..ebba939287d246b5bda31ab50a45dcf677c6a7f9 100644 (file)
@@ -1,6 +1,6 @@
 ## Process this file with automake to produce Makefile.in
 #
-#  $Id: Makefile.am,v 1.24 2007/04/16 14:12:06 hno Exp $
+#  $Id: Makefile.am,v 1.25 2007/04/24 06:30:37 wessels Exp $
 #
 
 DIST_SUBDIRS = libTrie
@@ -80,6 +80,7 @@ libmiscutil_a_SOURCES = \
        util.c \
        uudecode.c \
        assert.c \
+       xusleep.c \
        $(XPROF_STATS_SOURCE) \
        $(WIN32SRC)
 libmiscutil_a_LIBADD = \
diff --git a/lib/xusleep.c b/lib/xusleep.c
new file mode 100644 (file)
index 0000000..e51afd3
--- /dev/null
@@ -0,0 +1,27 @@
+#include "config.h"
+#include "profiling.h"
+#include "xusleep.h"
+
+#if HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#if HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
+
+
+/*
+ * xusleep, as usleep but accepts longer pauses
+ */
+int
+xusleep(unsigned int usec)
+{
+    /* XXX emulation of usleep() */
+    struct timeval sl;
+    sl.tv_sec = usec / 1000000;
+    sl.tv_usec = usec % 1000000;
+    return select(0, NULL, NULL, NULL, &sl);
+}
index b6ac21ab28a7674c73a93f76690643d0f00a4be2..952592801baee9858369e067522373a097a9150d 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: unlinkd.cc,v 1.59 2007/04/12 23:51:56 wessels Exp $
+ * $Id: unlinkd.cc,v 1.60 2007/04/24 06:30:37 wessels Exp $
  *
  * DEBUG: section 2     Unlink Daemon
  * AUTHOR: Duane Wessels
@@ -69,6 +69,7 @@ main(int argc, char *argv[])
 
 #include "SquidTime.h"
 #include "fde.h"
+#include "xusleep.h"
 
 /* This code gets linked to Squid */
 
@@ -95,13 +96,24 @@ unlinkdUnlink(const char *path)
     }
 
     /*
-    * If the queue length is greater than our limit, then
-    * we pause for up to 100ms, hoping that unlinkd
-    * has some feedback for us.  Maybe it just needs a slice
-    * of the CPU's time.
-    */
+     * If the queue length is greater than our limit, then we pause
+     * for a small amount of time, hoping that unlinkd has some
+     * feedback for us.  Maybe it just needs a slice of the CPU's
+     * time.
+     */
     if (queuelen >= UNLINKD_QUEUE_LIMIT) {
-
+#if defined(USE_EPOLL) || defined(USE_KQUEUE)
+       /*
+        * DPW 2007-04-23
+        * We can't use fd_set when using epoll() or kqueue().  In
+        * these cases we block for 10 ms.
+        */
+       xusleep(10000);
+#else
+       /*
+        * DPW 2007-04-23
+        * When we can use select, block for up to 100 ms.
+        */
         struct timeval to;
         fd_set R;
         FD_ZERO(&R);
@@ -109,6 +121,7 @@ unlinkdUnlink(const char *path)
         to.tv_sec = 0;
         to.tv_usec = 100000;
         select(unlinkd_rfd + 1, &R, NULL, NULL, &to);
+#endif
     }
 
     /*
@@ -217,7 +230,6 @@ unlinkdInit(void)
 {
     const char *args[2];
 
-    struct timeval slp;
     args[0] = "(unlinkd)";
     args[1] = NULL;
     pid = ipcCreate(
@@ -241,11 +253,7 @@ IPC_FIFO,
     if (pid < 0)
         fatal("Failed to create unlinkd subprocess");
 
-    slp.tv_sec = 0;
-
-    slp.tv_usec = 250000;
-
-    select(0, NULL, NULL, NULL, &slp);
+    xusleep(250000);
 
     fd_note(unlinkd_wfd, "squid -> unlinkd");