diff --git a/tdutils/CMakeLists.txt b/tdutils/CMakeLists.txt index 6cd3b629a..22718beb8 100644 --- a/tdutils/CMakeLists.txt +++ b/tdutils/CMakeLists.txt @@ -160,6 +160,7 @@ set(TDUTILS_SOURCE td/utils/port/detail/Poll.h td/utils/port/detail/PollableFd.h td/utils/port/detail/Select.h + td/utils/port/detail/skip_eintr.h td/utils/port/detail/ThreadIdGuard.h td/utils/port/detail/ThreadPthread.h td/utils/port/detail/ThreadStl.h diff --git a/tdutils/td/utils/port/FileFd.cpp b/tdutils/td/utils/port/FileFd.cpp index 0b8300f33..b7bd04168 100644 --- a/tdutils/td/utils/port/FileFd.cpp +++ b/tdutils/td/utils/port/FileFd.cpp @@ -15,6 +15,7 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/port/detail/PollableFd.h" +#include "td/utils/port/detail/skip_eintr.h" #include "td/utils/port/PollFlags.h" #include "td/utils/port/sleep.h" #include "td/utils/ScopeGuard.h" diff --git a/tdutils/td/utils/port/ServerSocketFd.cpp b/tdutils/td/utils/port/ServerSocketFd.cpp index fdeecb39c..cb12330c6 100644 --- a/tdutils/td/utils/port/ServerSocketFd.cpp +++ b/tdutils/td/utils/port/ServerSocketFd.cpp @@ -10,6 +10,7 @@ #include "td/utils/common.h" #include "td/utils/logging.h" +#include "td/utils/port/detail/skip_eintr.h" #include "td/utils/port/IPAddress.h" #include "td/utils/port/PollFlags.h" diff --git a/tdutils/td/utils/port/SocketFd.cpp b/tdutils/td/utils/port/SocketFd.cpp index 515f5fa1a..3fa3a1f85 100644 --- a/tdutils/td/utils/port/SocketFd.cpp +++ b/tdutils/td/utils/port/SocketFd.cpp @@ -10,6 +10,7 @@ #include "td/utils/format.h" #include "td/utils/logging.h" #include "td/utils/misc.h" +#include "td/utils/port/detail/skip_eintr.h" #include "td/utils/port/PollFlags.h" #if TD_PORT_WINDOWS diff --git a/tdutils/td/utils/port/Stat.cpp b/tdutils/td/utils/port/Stat.cpp index b3ae8d4a9..7722b3e28 100644 --- a/tdutils/td/utils/port/Stat.cpp +++ b/tdutils/td/utils/port/Stat.cpp @@ -6,7 +6,6 @@ // #include "td/utils/port/Stat.h" -#include "td/utils/port/detail/PollableFd.h" #include "td/utils/port/FileFd.h" #if TD_PORT_POSIX @@ -15,6 +14,7 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/port/Clocks.h" +#include "td/utils/port/detail/skip_eintr.h" #include "td/utils/ScopeGuard.h" #include diff --git a/tdutils/td/utils/port/UdpSocketFd.cpp b/tdutils/td/utils/port/UdpSocketFd.cpp index bdba69ae7..5b25b6132 100644 --- a/tdutils/td/utils/port/UdpSocketFd.cpp +++ b/tdutils/td/utils/port/UdpSocketFd.cpp @@ -10,6 +10,7 @@ #include "td/utils/format.h" #include "td/utils/logging.h" #include "td/utils/misc.h" +#include "td/utils/port/detail/skip_eintr.h" #include "td/utils/port/PollFlags.h" #include "td/utils/port/SocketFd.h" #include "td/utils/VectorQueue.h" diff --git a/tdutils/td/utils/port/detail/EventFdLinux.cpp b/tdutils/td/utils/port/detail/EventFdLinux.cpp index ad26f95e1..f399ca5b2 100644 --- a/tdutils/td/utils/port/detail/EventFdLinux.cpp +++ b/tdutils/td/utils/port/detail/EventFdLinux.cpp @@ -13,6 +13,7 @@ char disable_linker_warning_about_empty_file_event_fd_linux_cpp TD_UNUSED; #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/port/detail/NativeFd.h" +#include "td/utils/port/detail/skip_eintr.h" #include "td/utils/port/PollFlags.h" #include "td/utils/ScopeGuard.h" #include "td/utils/Slice.h" diff --git a/tdutils/td/utils/port/detail/PollableFd.h b/tdutils/td/utils/port/detail/PollableFd.h index 609a64ed8..c482b8834 100644 --- a/tdutils/td/utils/port/detail/PollableFd.h +++ b/tdutils/td/utils/port/detail/PollableFd.h @@ -16,9 +16,7 @@ #include "td/utils/SpinLock.h" #include -#include #include -#include namespace td { @@ -209,30 +207,6 @@ inline const NativeFd &PollableFd::native_fd() const { return fd_info_->native_fd(); } -#if TD_PORT_POSIX -namespace detail { -template -auto skip_eintr(F &&f) { - decltype(f()) res; - static_assert(std::is_integral::value, "integral type expected"); - do { - errno = 0; // just in case - res = f(); - } while (res < 0 && errno == EINTR); - return res; -} -template -auto skip_eintr_cstr(F &&f) { - char *res; - do { - errno = 0; // just in case - res = f(); - } while (res == nullptr && errno == EINTR); - return res; -} -} // namespace detail -#endif - template bool can_read(const FdT &fd) { return fd.get_poll_info().get_flags().can_read() || fd.get_poll_info().get_flags().has_pending_error(); diff --git a/tdutils/td/utils/port/detail/skip_eintr.h b/tdutils/td/utils/port/detail/skip_eintr.h new file mode 100644 index 000000000..3fe805ba5 --- /dev/null +++ b/tdutils/td/utils/port/detail/skip_eintr.h @@ -0,0 +1,39 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2020 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#pragma once + +#include +#include + +namespace td { + +#if TD_PORT_POSIX +namespace detail { +template +auto skip_eintr(F &&f) { + decltype(f()) res; + static_assert(std::is_integral::value, "integral type expected"); + do { + errno = 0; // just in case + res = f(); + } while (res < 0 && errno == EINTR); + return res; +} + +template +auto skip_eintr_cstr(F &&f) { + char *res; + do { + errno = 0; // just in case + res = f(); + } while (res == nullptr && errno == EINTR); + return res; +} +} // namespace detail +#endif + +} // namespace td diff --git a/tdutils/td/utils/port/path.cpp b/tdutils/td/utils/port/path.cpp index 991f20afc..5935d5ed1 100644 --- a/tdutils/td/utils/port/path.cpp +++ b/tdutils/td/utils/port/path.cpp @@ -10,7 +10,7 @@ #include "td/utils/format.h" #include "td/utils/logging.h" -#include "td/utils/port/detail/PollableFd.h" +#include "td/utils/port/detail/skip_eintr.h" #include "td/utils/ScopeGuard.h" #if TD_PORT_WINDOWS