From: wessels <> Date: Tue, 24 Apr 2007 12:30:36 +0000 (+0000) Subject: Fix for compiling src/unlinkd.cc with kqueue and epoll. X-Git-Tag: SQUID_3_0_PRE6~48 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9ece7c7c51252249cbbe01b5a87004b395cbd193;p=thirdparty%2Fsquid.git Fix for compiling src/unlinkd.cc with kqueue and epoll. 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. --- diff --git a/include/xusleep.h b/include/xusleep.h new file mode 100644 index 0000000000..49b0bb02bd --- /dev/null +++ b/include/xusleep.h @@ -0,0 +1 @@ +SQUIDCEXTERN int xusleep(unsigned int); diff --git a/lib/Makefile.am b/lib/Makefile.am index 7523ddf132..ebba939287 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -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 index 0000000000..e51afd37d1 --- /dev/null +++ b/lib/xusleep.c @@ -0,0 +1,27 @@ +#include "config.h" +#include "profiling.h" +#include "xusleep.h" + +#if HAVE_STDLIB_H +#include +#endif +#if HAVE_UNISTD_H +#include +#endif +#if HAVE_SYS_SELECT_H +#include +#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); +} diff --git a/src/unlinkd.cc b/src/unlinkd.cc index b6ac21ab28..952592801b 100644 --- a/src/unlinkd.cc +++ b/src/unlinkd.cc @@ -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");