From: Amos Jeffries Date: Fri, 10 Feb 2023 12:25:07 +0000 (+0000) Subject: Cleanup: remove xusleep() hacks (#613) X-Git-Tag: SQUID_6_0_1~17 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5eee0e42ab5ad5d2f296e698bdfc5e711bb490d4;p=thirdparty%2Fsquid.git Cleanup: remove xusleep() hacks (#613) 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(). --- diff --git a/include/xusleep.h b/include/xusleep.h deleted file mode 100644 index 9ae0b773c0..0000000000 --- a/include/xusleep.h +++ /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 */ - diff --git a/lib/Makefile.am b/lib/Makefile.am index 7dd55d3187..c6fcd08ca2 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -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 index ff17cc85eb..0000000000 --- a/lib/xusleep.c +++ /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 -#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/base/File.cc b/src/base/File.cc index 0b1582d7d9..bd633338b0 100644 --- a/src/base/File.cc +++ b/src/base/File.cc @@ -11,8 +11,9 @@ #include "debug/Stream.h" #include "sbuf/Stream.h" #include "tools.h" -#include "xusleep.h" +#include +#include #include #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"); } diff --git a/src/cf.data.pre b/src/cf.data.pre index d95f31dc02..c65fe664c9 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -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 diff --git a/src/ipc.cc b/src/ipc.cc index cc3bc18788..40d34b4755 100644 --- a/src/ipc.cc +++ b/src/ipc.cc @@ -20,6 +20,9 @@ #include "SquidIpc.h" #include "tools.h" +#include +#include + 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; } diff --git a/src/ipc_win32.cc b/src/ipc_win32.cc index 04a0c8d31f..f7416288b1 100644 --- a/src/ipc_win32.cc +++ b/src/ipc_win32.cc @@ -22,6 +22,9 @@ #include "tools.h" #include +#include +#include + #if HAVE_MSWSOCK_H #include #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) diff --git a/src/unlinkd.cc b/src/unlinkd.cc index f53b5155b1..1d5275a456 100644 --- a/src/unlinkd.cc +++ b/src/unlinkd.cc @@ -21,7 +21,9 @@ #include "store/Disk.h" #include "tools.h" #include "unlinkd.h" -#include "xusleep.h" + +#include +#include /* 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");