]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Cleanup: remove xusleep() hacks (#613)
authorAmos Jeffries <yadij@users.noreply.github.com>
Fri, 10 Feb 2023 12:25:07 +0000 (12:25 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Fri, 10 Feb 2023 14:25:15 +0000 (14:25 +0000)
usleep() has been obsolete for a long time. C++11 provides better and
portable waiting mechanism we can use easily instead of these hacks
trying to replicate and extend usleep().

include/xusleep.h [deleted file]
lib/Makefile.am
lib/xusleep.c [deleted file]
src/base/File.cc
src/cf.data.pre
src/ipc.cc
src/ipc_win32.cc
src/unlinkd.cc

diff --git a/include/xusleep.h b/include/xusleep.h
deleted file mode 100644 (file)
index 9ae0b77..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
- *
- * Squid software is distributed under GPLv2+ license and includes
- * contributions from numerous individuals and organizations.
- * Please see the COPYING and CONTRIBUTORS files for details.
- */
-
-#ifndef _INC_XUSLEEP_H
-#define _INC_XUSLEEP_H
-
-SQUIDCEXTERN int xusleep(unsigned int);
-
-#endif /* _INC_XUSLEEP_H */
-
index 7dd55d31873bfac1b633297aee718418fede0cc0..c6fcd08ca27ddc5135e8cae6e7ea4f57ec243e23 100644 (file)
@@ -68,8 +68,7 @@ libmiscutil_la_SOURCES = \
        getfullhostname.c \
        heap.c \
        radix.c \
-       util.c \
-       xusleep.c
+       util.c
 
 TESTS += tests/testRFC1738
 
diff --git a/lib/xusleep.c b/lib/xusleep.c
deleted file mode 100644 (file)
index ff17cc8..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
- *
- * Squid software is distributed under GPLv2+ license and includes
- * contributions from numerous individuals and organizations.
- * Please see the COPYING and CONTRIBUTORS files for details.
- */
-
-#include "squid.h"
-#include "xusleep.h"
-
-#if HAVE_UNISTD_H
-#include <unistd.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 0b1582d7d9d81d7efc8c266496c94a96fc2cbe73..bd633338b059a7c09e1e9e992182c6ddfee7568b 100644 (file)
@@ -11,8 +11,9 @@
 #include "debug/Stream.h"
 #include "sbuf/Stream.h"
 #include "tools.h"
-#include "xusleep.h"
 
+#include <chrono>
+#include <thread>
 #include <utility>
 
 #if HAVE_FCNTL_H
@@ -331,7 +332,7 @@ File::lock(const FileOpeningConfig &cfg)
                    " more time(s) after a failure: " << ex.what());
         }
         Must(attemptsLeft); // the catch statement handles the last attempt
-        xusleep(cfg.RetryGapUsec);
+        std::this_thread::sleep_for(std::chrono::microseconds(cfg.RetryGapUsec));
     }
     debugs(54, 9, "disabled");
 }
index d95f31dc021332cb376f3b1f03808a7ddd9461db..c65fe664c997ab9abdc17afdc786c89cb1deeb54 100644 (file)
@@ -10604,8 +10604,6 @@ DOC_START
        processes, these sleep delays will add up and your
        Squid will not service requests for some amount of time
        until all the child processes have been started.
-       On Windows value less then 1000 (1 milliseconds) are
-       rounded to 1000.
 DOC_END
 
 NAME: windows_ipaddrchangemonitor
index cc3bc187886282a3b7d7fbd62ac691b0e97ac4ce..40d34b4755a057f1158bc5af8d7388c678acde76 100644 (file)
@@ -20,6 +20,9 @@
 #include "SquidIpc.h"
 #include "tools.h"
 
+#include <chrono>
+#include <thread>
+
 static const char *hello_string = "hi there\n";
 #ifndef HELLO_BUF_SZ
 #define HELLO_BUF_SZ 32
@@ -305,14 +308,8 @@ ipcCreate(int type, const char *prog, const char *const args[], const char *name
 
         fd_table[pwfd].flags.ipc = 1;
 
-        if (Config.sleep_after_fork) {
-            /* XXX emulation of usleep() */
-
-            struct timeval sl;
-            sl.tv_sec = Config.sleep_after_fork / 1000000;
-            sl.tv_usec = Config.sleep_after_fork % 1000000;
-            select(0, nullptr, nullptr, nullptr, &sl);
-        }
+        if (Config.sleep_after_fork)
+            std::this_thread::sleep_for(std::chrono::microseconds(Config.sleep_after_fork));
 
         return pid;
     }
index 04a0c8d31f1351904cdb5173c16b53d96f4f9413..f7416288b1494e5ad789b3abcc2f6d4deed2857a 100644 (file)
@@ -22,6 +22,9 @@
 #include "tools.h"
 
 #include <cerrno>
+#include <chrono>
+#include <thread>
+
 #if HAVE_MSWSOCK_H
 #include <mswsock.h>
 #endif
@@ -313,16 +316,8 @@ ipcCreate(int type, const char *prog, const char *const args[], const char *name
     fd_table[crfd].flags.ipc = true;
     fd_table[cwfd].flags.ipc = true;
 
-    if (Config.sleep_after_fork) {
-        /* XXX emulation of usleep() */
-        DWORD sl;
-        sl = Config.sleep_after_fork / 1000;
-
-        if (sl == 0)
-            sl = 1;
-
-        Sleep(sl);
-    }
+    if (Config.sleep_after_fork)
+        std::this_thread::sleep_for(std::chrono::microseconds(Config.sleep_after_fork));
 
     if (GetExitCodeThread((HANDLE) thread, &ecode) && ecode == STILL_ACTIVE) {
         if (hIpc)
index f53b5155b1d0ef69549983a5acb2c90dc12bba1a..1d5275a4561d039bd57d82739a95dc06c9f8e22e 100644 (file)
@@ -21,7 +21,9 @@
 #include "store/Disk.h"
 #include "tools.h"
 #include "unlinkd.h"
-#include "xusleep.h"
+
+#include <chrono>
+#include <thread>
 
 /* This code gets linked to Squid */
 
@@ -60,7 +62,7 @@ unlinkdUnlink(const char *path)
          * We can't use fd_set when using epoll() or kqueue().  In
          * these cases we block for 10 ms.
          */
-        xusleep(10000);
+        std::this_thread::sleep_for(std::chrono::milliseconds(10));
 #else
         /*
          * DPW 2007-04-23
@@ -222,7 +224,7 @@ unlinkdInit(void)
     if (pid < 0)
         fatal("Failed to create unlinkd subprocess");
 
-    xusleep(250000);
+    std::this_thread::sleep_for(std::chrono::milliseconds(250));
 
     fd_note(unlinkd_wfd, "squid -> unlinkd");