From 22c761b7872b5bae600201fc9d94d9e8a9b97591 Mon Sep 17 00:00:00 2001 From: IronsDu Date: Sun, 25 Aug 2024 19:30:19 +0800 Subject: [PATCH] =?UTF-8?q?remove=20`BrynetAny`=E3=80=81`BRYNET=5FNOEXCEPT?= =?UTF-8?q?`=E3=80=82=20(#145)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/brynet/base/Any.hpp | 30 ------------------- include/brynet/base/CPP_VERSION.hpp | 16 ---------- include/brynet/base/Noexcept.hpp | 9 ------ include/brynet/base/Timer.hpp | 3 +- include/brynet/net/EventLoop.hpp | 14 ++++----- include/brynet/net/SSLHelper.hpp | 7 ++--- include/brynet/net/TcpConnection.hpp | 28 ++++++++--------- include/brynet/net/detail/ConnectorDetail.hpp | 24 +-------------- .../brynet/net/detail/ConnectorWorkInfo.hpp | 10 ++----- .../brynet/net/detail/ListenThreadDetail.hpp | 3 +- .../brynet/net/detail/TCPServiceDetail.hpp | 5 ++-- include/brynet/net/detail/WakeupChannel.hpp | 8 ++--- include/brynet/net/port/Win.hpp | 3 +- 13 files changed, 35 insertions(+), 125 deletions(-) delete mode 100644 include/brynet/base/Any.hpp delete mode 100644 include/brynet/base/CPP_VERSION.hpp delete mode 100644 include/brynet/base/Noexcept.hpp diff --git a/include/brynet/base/Any.hpp b/include/brynet/base/Any.hpp deleted file mode 100644 index d8dd1d26..00000000 --- a/include/brynet/base/Any.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include - -#ifdef BRYNET_HAVE_LANG_CXX17 -#include -#else -#include -#endif - -namespace brynet { namespace base { - -#ifdef BRYNET_HAVE_LANG_CXX17 -using BrynetAny = std::any; - -template -auto cast(const BrynetAny& ud) -{ - return std::any_cast(&ud); -} -#else -using BrynetAny = int64_t; -template -const T* cast(const BrynetAny& ud) -{ - return static_cast(&ud); -} -#endif - -}}// namespace brynet::base diff --git a/include/brynet/base/CPP_VERSION.hpp b/include/brynet/base/CPP_VERSION.hpp deleted file mode 100644 index 2047b2db..00000000 --- a/include/brynet/base/CPP_VERSION.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#if (__cplusplus >= 201103L || \ - (defined(_MSC_VER) && _MSC_VER >= 1800)) -#define BRYNET_HAVE_LANG_CXX11 1 -#endif - -#if (__cplusplus >= 201402L || \ - (defined(_MSC_VER) && _MSC_VER >= 1900)) -#define BRYNET_HAVE_LANG_CXX14 1 -#endif - -#if (__cplusplus >= 201703L || \ - (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)) -#define BRYNET_HAVE_LANG_CXX17 1 -#endif diff --git a/include/brynet/base/Noexcept.hpp b/include/brynet/base/Noexcept.hpp deleted file mode 100644 index 316de5ef..00000000 --- a/include/brynet/base/Noexcept.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include - -#ifdef BRYNET_HAVE_LANG_CXX17 -#define BRYNET_NOEXCEPT noexcept -#else -#define BRYNET_NOEXCEPT -#endif diff --git a/include/brynet/base/Timer.hpp b/include/brynet/base/Timer.hpp index 4acfaa76..29791e4e 100644 --- a/include/brynet/base/Timer.hpp +++ b/include/brynet/base/Timer.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include #include @@ -22,7 +21,7 @@ class Timer final Timer(std::chrono::steady_clock::time_point startTime, std::chrono::nanoseconds lastTime, - Callback&& callback) BRYNET_NOEXCEPT + Callback&& callback) : mCallback(std::move(callback)), mStartTime(startTime), mLastTime(lastTime) diff --git a/include/brynet/net/EventLoop.hpp b/include/brynet/net/EventLoop.hpp index 601b1457..df95cc2f 100644 --- a/include/brynet/net/EventLoop.hpp +++ b/include/brynet/net/EventLoop.hpp @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -33,15 +32,14 @@ class EventLoop : public brynet::base::NonCopyable public: EventLoop() - BRYNET_NOEXCEPT : #ifdef BRYNET_PLATFORM_WINDOWS - mIOCP(CreateIoCompletionPort(INVALID_HANDLE_VALUE, 0, 0, 1)), - mWakeupChannel(std::make_unique(mIOCP)) + mIOCP(CreateIoCompletionPort(INVALID_HANDLE_VALUE, 0, 0, 1)), + mWakeupChannel(std::make_unique(mIOCP)) #elif defined BRYNET_PLATFORM_LINUX - mEpollFd(epoll_create(1)) + mEpollFd(epoll_create(1)) #elif defined BRYNET_PLATFORM_DARWIN || defined BRYNET_PLATFORM_FREEBSD - mKqueueFd(kqueue()) + mKqueueFd(kqueue()) #endif { #ifdef BRYNET_PLATFORM_WINDOWS @@ -82,7 +80,7 @@ class EventLoop : public brynet::base::NonCopyable mSelfThreadIDIsInitialized.store(false); } - virtual ~EventLoop() BRYNET_NOEXCEPT + virtual ~EventLoop() { #ifdef BRYNET_PLATFORM_WINDOWS CloseHandle(mIOCP); @@ -389,7 +387,7 @@ class EventLoop : public brynet::base::NonCopyable return mKqueueFd; } #endif - bool linkChannel(BrynetSocketFD fd, const Channel* ptr) BRYNET_NOEXCEPT + bool linkChannel(BrynetSocketFD fd, const Channel* ptr) { #ifdef BRYNET_PLATFORM_WINDOWS return CreateIoCompletionPort((HANDLE) fd, mIOCP, (ULONG_PTR) ptr, 0) != nullptr; diff --git a/include/brynet/net/SSLHelper.hpp b/include/brynet/net/SSLHelper.hpp index 78634315..4744836a 100644 --- a/include/brynet/net/SSLHelper.hpp +++ b/include/brynet/net/SSLHelper.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include @@ -86,7 +85,7 @@ class SSLHelper : public brynet::base::NonCopyable, { std::call_once(initCryptoThreadSafeSupportOnceFlag, InitCryptoThreadSafeSupport); - } + } bool initSSL(const std::string& certificate, const std::string& privatekey) @@ -157,14 +156,14 @@ class SSLHelper : public brynet::base::NonCopyable, } protected: - SSLHelper() BRYNET_NOEXCEPT + SSLHelper() { #ifdef BRYNET_USE_OPENSSL mOpenSSLCTX = nullptr; #endif } - virtual ~SSLHelper() BRYNET_NOEXCEPT + virtual ~SSLHelper() { #ifdef BRYNET_USE_OPENSSL destroySSL(); diff --git a/include/brynet/net/TcpConnection.hpp b/include/brynet/net/TcpConnection.hpp index 4a06188f..5a1e1d25 100644 --- a/include/brynet/net/TcpConnection.hpp +++ b/include/brynet/net/TcpConnection.hpp @@ -1,8 +1,6 @@ #pragma once -#include #include -#include #include #include #include @@ -240,21 +238,21 @@ class TcpConnection : public Channel, TcpConnection(TcpSocket::Ptr socket, size_t maxRecvBufferSize, EnterCallback&& enterCallback, - EventLoop::Ptr eventLoop) BRYNET_NOEXCEPT + EventLoop::Ptr eventLoop) : #ifdef BRYNET_PLATFORM_WINDOWS - mOvlRecv(port::Win::OverlappedType::OverlappedRecv), - mOvlSend(port::Win::OverlappedType::OverlappedSend), - mPostClose(false), + mOvlRecv(port::Win::OverlappedType::OverlappedRecv), + mOvlSend(port::Win::OverlappedType::OverlappedSend), + mPostClose(false), #endif - mIP(socket->getRemoteIP()), - mSocket(std::move(socket)), - mEventLoop(std::move(eventLoop)), - mAlreadyClose(false), - mMaxRecvBufferSize(maxRecvBufferSize), - mSendingMsgSize(0), - mEnterCallback(std::move(enterCallback)), - mHighWaterSize(0) + mIP(socket->getRemoteIP()), + mSocket(std::move(socket)), + mEventLoop(std::move(eventLoop)), + mAlreadyClose(false), + mMaxRecvBufferSize(maxRecvBufferSize), + mSendingMsgSize(0), + mEnterCallback(std::move(enterCallback)), + mHighWaterSize(0) { mRecvData = false; mCheckTime = std::chrono::steady_clock::duration::zero(); @@ -275,7 +273,7 @@ class TcpConnection : public Channel, #endif } - ~TcpConnection() BRYNET_NOEXCEPT override + ~TcpConnection() override { #ifdef BRYNET_USE_OPENSSL if (mSSL != nullptr) diff --git a/include/brynet/net/detail/ConnectorDetail.hpp b/include/brynet/net/detail/ConnectorDetail.hpp index 9d6207b0..67e6d8b0 100644 --- a/include/brynet/net/detail/ConnectorDetail.hpp +++ b/include/brynet/net/detail/ConnectorDetail.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include @@ -8,13 +7,8 @@ #include #include #include -#include - -#ifdef BRYNET_HAVE_LANG_CXX17 -#include -#else #include -#endif +#include namespace brynet { namespace net { namespace detail { @@ -23,11 +17,7 @@ class AsyncConnectorDetail : public brynet::base::NonCopyable protected: void startWorkerThread() { -#ifdef BRYNET_HAVE_LANG_CXX17 - std::lock_guard lck(mThreadGuard); -#else std::lock_guard lck(mThreadGuard); -#endif if (mThread != nullptr) { @@ -61,11 +51,7 @@ class AsyncConnectorDetail : public brynet::base::NonCopyable void stopWorkerThread() { -#ifdef BRYNET_HAVE_LANG_CXX17 - std::lock_guard lck(mThreadGuard); -#else std::lock_guard lck(mThreadGuard); -#endif if (mThread == nullptr) { @@ -96,11 +82,7 @@ class AsyncConnectorDetail : public brynet::base::NonCopyable void asyncConnect(detail::ConnectOption option) { -#ifdef BRYNET_HAVE_LANG_CXX17 - std::shared_lock lck(mThreadGuard); -#else std::lock_guard lck(mThreadGuard); -#endif if (option.completedCallback == nullptr && option.failedCallback == nullptr) { @@ -144,11 +126,7 @@ class AsyncConnectorDetail : public brynet::base::NonCopyable std::shared_ptr mWorkInfo; std::shared_ptr mThread; -#ifdef BRYNET_HAVE_LANG_CXX17 - std::shared_mutex mThreadGuard; -#else std::mutex mThreadGuard; -#endif std::shared_ptr mIsRun; }; diff --git a/include/brynet/net/detail/ConnectorWorkInfo.hpp b/include/brynet/net/detail/ConnectorWorkInfo.hpp index 89da3228..47fc63ce 100644 --- a/include/brynet/net/detail/ConnectorWorkInfo.hpp +++ b/include/brynet/net/detail/ConnectorWorkInfo.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include @@ -8,13 +7,8 @@ #include #include #include -#include - -#ifdef BRYNET_HAVE_LANG_CXX17 -#include -#else #include -#endif +#include namespace brynet { namespace net { namespace detail { @@ -85,7 +79,7 @@ class ConnectorWorkInfo final : public brynet::base::NonCopyable public: using Ptr = std::shared_ptr; - ConnectorWorkInfo() BRYNET_NOEXCEPT + ConnectorWorkInfo() { mPoller.reset(brynet::base::poller_new()); mPollResult.reset(brynet::base::stack_new(1024, sizeof(BrynetSocketFD))); diff --git a/include/brynet/net/detail/ListenThreadDetail.hpp b/include/brynet/net/detail/ListenThreadDetail.hpp index d100c7dc..d0666977 100644 --- a/include/brynet/net/detail/ListenThreadDetail.hpp +++ b/include/brynet/net/detail/ListenThreadDetail.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include @@ -128,7 +127,7 @@ class ListenThreadDetail : public brynet::base::NonCopyable mRunListen = std::make_shared(false); } - virtual ~ListenThreadDetail() BRYNET_NOEXCEPT + virtual ~ListenThreadDetail() { stopListen(); } diff --git a/include/brynet/net/detail/TCPServiceDetail.hpp b/include/brynet/net/detail/TCPServiceDetail.hpp index 6304c8b0..f6c7c79a 100644 --- a/include/brynet/net/detail/TCPServiceDetail.hpp +++ b/include/brynet/net/detail/TCPServiceDetail.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include @@ -53,14 +52,14 @@ class TcpServiceDetail : public brynet::base::NonCopyable using FrameCallback = std::function; const static unsigned int sDefaultLoopTimeOutMS = 100; - TcpServiceDetail() BRYNET_NOEXCEPT + TcpServiceDetail() : mRandom(static_cast( std::chrono::system_clock::now().time_since_epoch().count())) { mRunIOLoop = std::make_shared(false); } - virtual ~TcpServiceDetail() BRYNET_NOEXCEPT + virtual ~TcpServiceDetail() { stopWorkerThread(); } diff --git a/include/brynet/net/detail/WakeupChannel.hpp b/include/brynet/net/detail/WakeupChannel.hpp index ec06757e..1f323ff2 100644 --- a/include/brynet/net/detail/WakeupChannel.hpp +++ b/include/brynet/net/detail/WakeupChannel.hpp @@ -20,7 +20,7 @@ class WakeupChannel final : public Channel, public brynet::base::NonCopyable { } - bool wakeup() BRYNET_NOEXCEPT + bool wakeup() { return PostQueuedCompletionStatus(mIOCP, 0, @@ -29,17 +29,17 @@ class WakeupChannel final : public Channel, public brynet::base::NonCopyable } private: - void canRecv(bool) BRYNET_NOEXCEPT override + void canRecv(bool) override { ; } - void canSend() BRYNET_NOEXCEPT override + void canSend() override { ; } - void onClose() BRYNET_NOEXCEPT override + void onClose() override { ; } diff --git a/include/brynet/net/port/Win.hpp b/include/brynet/net/port/Win.hpp index a48845f5..a5707dbe 100644 --- a/include/brynet/net/port/Win.hpp +++ b/include/brynet/net/port/Win.hpp @@ -20,7 +20,8 @@ class Win OVERLAPPED base; const OverlappedType OP; - OverlappedExt(OverlappedType op) BRYNET_NOEXCEPT : OP(op) + OverlappedExt(OverlappedType op) + : OP(op) { memset(&base, 0, sizeof(base)); }