From 618a1597da6c8400ea1e6884c1389dad4f3a962c Mon Sep 17 00:00:00 2001 From: dominic Date: Mon, 10 Feb 2020 20:54:34 +0100 Subject: [PATCH] fixed build error with libstdc++ sorry compiled only with libc++ --- include/spdlog/sinks/tcp_sink.h | 52 +++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/include/spdlog/sinks/tcp_sink.h b/include/spdlog/sinks/tcp_sink.h index 70cf6f86..0a76eee5 100644 --- a/include/spdlog/sinks/tcp_sink.h +++ b/include/spdlog/sinks/tcp_sink.h @@ -3,20 +3,18 @@ #pragma once -#include -#include -#include - -#include #include -#include -#include #include -#include - +#include #include +#include +#include +#include +#include +#include #include -#include +#include +#include #pragma once @@ -104,13 +102,30 @@ private: } struct SocketCloser { - using pointer = int; - void operator()(int socket_fd) + SocketCloser(int fd) + : fd_{fd} + {} + int fd_; + ~SocketCloser() + { + if (fd_ != -1) + { + ::close(fd_); + } + } + + int get() + { + return fd_; + } + int release() { - ::close(socket_fd); + int fd = fd_; + fd_ = -1; + return fd; } }; - std::unique_ptr socket_up(socket_rv); + SocketCloser socket_up(socket_rv); socket_rv = -1; int const oldFlag = ::fcntl(socket_up.get(), F_GETFL); @@ -153,11 +168,10 @@ private: timeout = std::chrono::nanoseconds{} > timeout ? std::chrono::nanoseconds{} : timeout; - auto const stoptime = - timeout > std::chrono::hours(24 * 365 * 100) - ? std::chrono::steady_clock::time_point::max() - : std::chrono::steady_clock::now() + - timeout; // TODO could overflow but the program run for ~191 years in that case so that should be OK + auto const stoptime = timeout > std::chrono::hours(24 * 365 * 100) + ? std::chrono::steady_clock::time_point::max() + : std::chrono::steady_clock::now() + timeout; // TODO could overflow but the program run for + // ~191 years in that case so that should be OK auto ts = calcTs(timeout);