From 2e66a270817dd0676d14ec26532bddbc3e5a009c Mon Sep 17 00:00:00 2001 From: Chris Love Date: Sat, 4 Sep 2021 19:29:56 -0700 Subject: [PATCH] Remove is_init() check on each log call --- include/spdlog/details/udp_client-windows.h | 10 ++++------ include/spdlog/details/udp_client.h | 7 +------ include/spdlog/sinks/udp_sink.h | 4 ---- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/include/spdlog/details/udp_client-windows.h b/include/spdlog/details/udp_client-windows.h index d56b4135..9b5d5f21 100644 --- a/include/spdlog/details/udp_client-windows.h +++ b/include/spdlog/details/udp_client-windows.h @@ -77,11 +77,6 @@ public: init_winsock_(); } - if (is_init()) - { - close(); - } - addr_.sin_family = PF_INET; addr_.sin_port = htons(port); addr_.sin_addr.s_addr = INADDR_ANY; @@ -108,7 +103,10 @@ public: void close() { - ::closesocket(socket_); + if (socket_ != -1) + { + ::closesocket(socket_); + } socket_ = INVALID_SOCKET; WSACleanup(); } diff --git a/include/spdlog/details/udp_client.h b/include/spdlog/details/udp_client.h index 6eeb68e3..661282cd 100644 --- a/include/spdlog/details/udp_client.h +++ b/include/spdlog/details/udp_client.h @@ -52,14 +52,9 @@ public: return true; } - bool is_init() const - { - return socket_ != -1; - } - void close() { - if (is_init()) + if (socket_ != -1) { ::close(socket_); socket_ = -1; diff --git a/include/spdlog/sinks/udp_sink.h b/include/spdlog/sinks/udp_sink.h index 8071a602..0b35ce41 100644 --- a/include/spdlog/sinks/udp_sink.h +++ b/include/spdlog/sinks/udp_sink.h @@ -53,10 +53,6 @@ protected: { spdlog::memory_buf_t formatted; spdlog::sinks::base_sink::formatter_->format(msg, formatted); - if (!client_.is_init()) - { - client_.init(config_.server_host, config_.server_port); - } client_.send(formatted.data(), formatted.size()); }