From 679c6d37c104cfcd1235f3875922b802776ee251 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 14 May 2021 17:49:39 +0200 Subject: [PATCH] Removed the namespaces from brynet. --- core/http_server.cpp | 4 +- core/http_server.h | 6 +-- core/request.h | 4 -- libs/brynet/base/Any.hpp | 6 --- libs/brynet/base/AppStatus.hpp | 6 --- libs/brynet/base/Array.hpp | 6 --- libs/brynet/base/Buffer.hpp | 6 --- libs/brynet/base/NonCopyable.hpp | 5 -- libs/brynet/base/Packet.hpp | 30 +++++------ libs/brynet/base/Stack.hpp | 6 --- libs/brynet/base/Timer.hpp | 6 --- libs/brynet/base/WaitGroup.hpp | 5 -- libs/brynet/base/crypto/Base64.hpp | 8 --- libs/brynet/base/endian/Endian.hpp | 7 --- libs/brynet/net/AsyncConnector.hpp | 15 ++---- libs/brynet/net/Channel.hpp | 6 --- libs/brynet/net/CurrentThread.hpp | 8 --- libs/brynet/net/EventLoop.hpp | 28 ++++------- libs/brynet/net/Exception.hpp | 6 --- libs/brynet/net/ListenThread.hpp | 14 ++---- libs/brynet/net/Poller.hpp | 6 --- libs/brynet/net/PromiseReceive.hpp | 8 +-- libs/brynet/net/SSLHelper.hpp | 7 +-- libs/brynet/net/SendableMsg.hpp | 5 -- libs/brynet/net/Socket.hpp | 37 ++++++-------- libs/brynet/net/SocketLibFunction.hpp | 8 --- libs/brynet/net/TcpConnection.hpp | 32 +++++------- libs/brynet/net/TcpService.hpp | 20 +++----- libs/brynet/net/detail/ConnectionOption.hpp | 8 --- libs/brynet/net/detail/ConnectorDetail.hpp | 19 +++---- libs/brynet/net/detail/ConnectorWorkInfo.hpp | 50 ++++++++----------- libs/brynet/net/detail/IOLoopData.hpp | 10 +--- libs/brynet/net/detail/ListenThreadDetail.hpp | 16 ++---- libs/brynet/net/detail/TCPServiceDetail.hpp | 10 +--- libs/brynet/net/detail/WakeupChannel.hpp | 13 ++--- libs/brynet/net/http/HttpFormat.hpp | 8 --- libs/brynet/net/http/HttpParser.hpp | 8 --- libs/brynet/net/http/HttpService.hpp | 11 +--- libs/brynet/net/http/WebSocketFormat.hpp | 10 +--- libs/brynet/net/port/Win.hpp | 7 --- libs/brynet/net/wrapper/ConnectionBuilder.hpp | 14 ++---- .../net/wrapper/HttpConnectionBuilder.hpp | 13 ++--- .../brynet/net/wrapper/HttpServiceBuilder.hpp | 14 ++---- libs/brynet/net/wrapper/ServiceBuilder.hpp | 10 +--- 44 files changed, 122 insertions(+), 404 deletions(-) diff --git a/core/http_server.cpp b/core/http_server.cpp index 0c73c09..fe6d511 100644 --- a/core/http_server.cpp +++ b/core/http_server.cpp @@ -84,7 +84,7 @@ void HTTPServer::initialize() { if (listenBuilder) delete listenBuilder; - listenBuilder = new wrapper::HttpListenerBuilder(); + listenBuilder = new HttpListenerBuilder(); listenBuilder->WithService(service); listenBuilder->AddSocketProcess([](TcpSocket &socket) { @@ -112,7 +112,7 @@ void HTTPServer::main_loop() { //std::this_thread::sleep_for(std::chrono::seconds(1)); std::this_thread::sleep_for(std::chrono::milliseconds(10)); - if (brynet::base::app_kbhit()) { + if (app_kbhit()) { break; } diff --git a/core/http_server.h b/core/http_server.h index 4489a86..d78256d 100644 --- a/core/http_server.h +++ b/core/http_server.h @@ -14,10 +14,6 @@ #include #include -using namespace brynet; -using namespace brynet::net; -using namespace brynet::net::http; - class Request; class Application; @@ -26,7 +22,7 @@ public: int port; int threads; std::shared_ptr service; - wrapper::HttpListenerBuilder *listenBuilder; + HttpListenerBuilder *listenBuilder; void http_callback_handler(Request *response); diff --git a/core/request.h b/core/request.h index b8304c2..c3b5e6e 100644 --- a/core/request.h +++ b/core/request.h @@ -9,10 +9,6 @@ #include "handler_instance.h" -using namespace brynet; -using namespace brynet::net; -using namespace brynet::net::http; - class Application; class Request { diff --git a/libs/brynet/base/Any.hpp b/libs/brynet/base/Any.hpp index 10ef7dc..fa52c58 100644 --- a/libs/brynet/base/Any.hpp +++ b/libs/brynet/base/Any.hpp @@ -8,9 +8,6 @@ #include #endif -namespace brynet { -namespace base { - #ifdef BRYNET_HAVE_LANG_CXX17 using BrynetAny = std::any; @@ -25,6 +22,3 @@ const T *cast(const BrynetAny &ud) { return static_cast(&ud); } #endif - -} // namespace base -} // namespace brynet diff --git a/libs/brynet/base/AppStatus.hpp b/libs/brynet/base/AppStatus.hpp index 017ea95..dbe8bd9 100644 --- a/libs/brynet/base/AppStatus.hpp +++ b/libs/brynet/base/AppStatus.hpp @@ -14,9 +14,6 @@ #include #endif -namespace brynet { -namespace base { - static bool app_kbhit() { #ifdef BRYNET_PLATFORM_WINDOWS return _kbhit(); @@ -42,6 +39,3 @@ static bool app_kbhit() { return false; #endif } - -} // namespace base -} // namespace brynet diff --git a/libs/brynet/base/Array.hpp b/libs/brynet/base/Array.hpp index 0fb831c..f245d59 100644 --- a/libs/brynet/base/Array.hpp +++ b/libs/brynet/base/Array.hpp @@ -4,9 +4,6 @@ #include #include -namespace brynet { -namespace base { - struct array_s { void *buffer; size_t buffer_size; @@ -102,6 +99,3 @@ static bool array_increase(struct array_s *self, size_t increase_num) { static size_t array_num(const struct array_s *self) { return self->element_num; } - -} // namespace base -} // namespace brynet diff --git a/libs/brynet/base/Buffer.hpp b/libs/brynet/base/Buffer.hpp index 20321f2..dcb53bf 100644 --- a/libs/brynet/base/Buffer.hpp +++ b/libs/brynet/base/Buffer.hpp @@ -3,9 +3,6 @@ #include #include -namespace brynet { -namespace base { - struct buffer_s { char *data; size_t data_len; @@ -142,6 +139,3 @@ static bool buffer_write(struct buffer_s *self, const char *data, size_t len) { return write_ret; } - -} // namespace base -} // namespace brynet diff --git a/libs/brynet/base/NonCopyable.hpp b/libs/brynet/base/NonCopyable.hpp index 2a6bc8a..bfae215 100644 --- a/libs/brynet/base/NonCopyable.hpp +++ b/libs/brynet/base/NonCopyable.hpp @@ -1,8 +1,5 @@ #pragma once -namespace brynet { -namespace base { - class NonCopyable { public: NonCopyable(const NonCopyable &) = delete; @@ -13,5 +10,3 @@ protected: ~NonCopyable() = default; }; -} // namespace base -} // namespace brynet diff --git a/libs/brynet/base/Packet.hpp b/libs/brynet/base/Packet.hpp index ba30594..efe5ca8 100644 --- a/libs/brynet/base/Packet.hpp +++ b/libs/brynet/base/Packet.hpp @@ -7,9 +7,6 @@ #include #include -namespace brynet { -namespace base { - class BasePacketWriter : public NonCopyable { public: BasePacketWriter(char *buffer, @@ -62,27 +59,27 @@ public: return writeBuffer((char *)&value, sizeof(value)); } bool writeINT16(int16_t value) { - value = endian::hostToNetwork16(value, mBigEndian); + value = hostToNetwork16(value, mBigEndian); return writeBuffer((char *)&value, sizeof(value)); } bool writeUINT16(uint16_t value) { - value = endian::hostToNetwork16(value, mBigEndian); + value = hostToNetwork16(value, mBigEndian); return writeBuffer((char *)&value, sizeof(value)); } bool writeINT32(int32_t value) { - value = endian::hostToNetwork32(value, mBigEndian); + value = hostToNetwork32(value, mBigEndian); return writeBuffer((char *)&value, sizeof(value)); } bool writeUINT32(uint32_t value) { - value = endian::hostToNetwork32(value, mBigEndian); + value = hostToNetwork32(value, mBigEndian); return writeBuffer((char *)&value, sizeof(value)); } bool writeINT64(int64_t value) { - value = endian::hostToNetwork64(value, mBigEndian); + value = hostToNetwork64(value, mBigEndian); return writeBuffer((char *)&value, sizeof(value)); } bool writeUINT64(uint64_t value) { - value = endian::hostToNetwork64(value, mBigEndian); + value = hostToNetwork64(value, mBigEndian); return writeBuffer((char *)&value, sizeof(value)); } @@ -294,32 +291,32 @@ public: int16_t readINT16() { int16_t value = 0; read(value); - return endian::networkToHost16(value, mBigEndian); + return networkToHost16(value, mBigEndian); } uint16_t readUINT16() { uint16_t value = 0; read(value); - return endian::networkToHost16(value, mBigEndian); + return networkToHost16(value, mBigEndian); } int32_t readINT32() { int32_t value = 0; read(value); - return endian::networkToHost32(value, mBigEndian); + return networkToHost32(value, mBigEndian); } uint32_t readUINT32() { uint32_t value = 0; read(value); - return endian::networkToHost32(value, mBigEndian); + return networkToHost32(value, mBigEndian); } int64_t readINT64() { int64_t value = 0; read(value); - return endian::networkToHost64(value, mBigEndian); + return networkToHost64(value, mBigEndian); } uint64_t readUINT64() { uint64_t value = 0; read(value); - return endian::networkToHost64(value, mBigEndian); + return networkToHost64(value, mBigEndian); } private: @@ -359,6 +356,3 @@ private: }; using BigPacket = AutoMallocPacket<32 * 1024>; - -} // namespace base -} // namespace brynet diff --git a/libs/brynet/base/Stack.hpp b/libs/brynet/base/Stack.hpp index ec5815a..8b68018 100644 --- a/libs/brynet/base/Stack.hpp +++ b/libs/brynet/base/Stack.hpp @@ -3,9 +3,6 @@ #include #include -namespace brynet { -namespace base { - struct stack_s { struct array_s *array; size_t element_size; @@ -141,6 +138,3 @@ static void *stack_popback(struct stack_s *self) { return ret; } - -} // namespace base -} // namespace brynet diff --git a/libs/brynet/base/Timer.hpp b/libs/brynet/base/Timer.hpp index 97622c8..8a3ad7d 100644 --- a/libs/brynet/base/Timer.hpp +++ b/libs/brynet/base/Timer.hpp @@ -8,9 +8,6 @@ #include #include -namespace brynet { -namespace base { - class TimerMgr; class Timer final { @@ -140,6 +137,3 @@ private: std::priority_queue, CompareTimer> mTimers; }; - -} // namespace base -} // namespace brynet diff --git a/libs/brynet/base/WaitGroup.hpp b/libs/brynet/base/WaitGroup.hpp index ec11939..e07b5ea 100644 --- a/libs/brynet/base/WaitGroup.hpp +++ b/libs/brynet/base/WaitGroup.hpp @@ -7,9 +7,6 @@ #include #include -namespace brynet { -namespace base { - class WaitGroup : public NonCopyable { public: typedef std::shared_ptr Ptr; @@ -57,5 +54,3 @@ private: std::atomic mCounter; std::condition_variable mCond; }; -} // namespace base -} // namespace brynet diff --git a/libs/brynet/base/crypto/Base64.hpp b/libs/brynet/base/crypto/Base64.hpp index 6512dd0..c83c57f 100644 --- a/libs/brynet/base/crypto/Base64.hpp +++ b/libs/brynet/base/crypto/Base64.hpp @@ -3,10 +3,6 @@ #include -namespace brynet { -namespace base { -namespace crypto { - static const std::string base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" @@ -99,8 +95,4 @@ static std::string base64_decode(std::string const &encoded_string) { return ret; } -} // namespace crypto -} // namespace base -} // namespace brynet - #endif \ No newline at end of file diff --git a/libs/brynet/base/endian/Endian.hpp b/libs/brynet/base/endian/Endian.hpp index 10529b4..e49cdd7 100644 --- a/libs/brynet/base/endian/Endian.hpp +++ b/libs/brynet/base/endian/Endian.hpp @@ -12,9 +12,6 @@ #include #endif -namespace brynet { -namespace base { -namespace endian { inline uint64_t hl64ton(uint64_t hostValue) { uint64_t ret = 0; @@ -116,7 +113,3 @@ inline uint16_t networkToHost16(uint16_t net16, bool convert = true) { return convert ? ntohs(net16) : net16; } #endif - -} // namespace endian -} // namespace base -} // namespace brynet \ No newline at end of file diff --git a/libs/brynet/net/AsyncConnector.hpp b/libs/brynet/net/AsyncConnector.hpp index 12736a5..7a03a12 100644 --- a/libs/brynet/net/AsyncConnector.hpp +++ b/libs/brynet/net/AsyncConnector.hpp @@ -2,25 +2,23 @@ #include -namespace brynet { -namespace net { +using ConnectOption = ConnectOption; -using ConnectOption = detail::ConnectOption; -class AsyncConnector : public detail::AsyncConnectorDetail, +class AsyncConnector : public AsyncConnectorDetail, public std::enable_shared_from_this { public: using Ptr = std::shared_ptr; void startWorkerThread() { - detail::AsyncConnectorDetail::startWorkerThread(); + AsyncConnectorDetail::startWorkerThread(); } void stopWorkerThread() { - detail::AsyncConnectorDetail::stopWorkerThread(); + AsyncConnectorDetail::stopWorkerThread(); } void asyncConnect(const ConnectOption &option) { - detail::AsyncConnectorDetail::asyncConnect(option); + AsyncConnectorDetail::asyncConnect(option); } static Ptr Create() { @@ -32,6 +30,3 @@ public: private: AsyncConnector() = default; }; - -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/Channel.hpp b/libs/brynet/net/Channel.hpp index d9ffc68..b08775d 100644 --- a/libs/brynet/net/Channel.hpp +++ b/libs/brynet/net/Channel.hpp @@ -1,8 +1,5 @@ #pragma once -namespace brynet { -namespace net { - class EventLoop; class Channel { @@ -16,6 +13,3 @@ private: friend class EventLoop; }; - -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/CurrentThread.hpp b/libs/brynet/net/CurrentThread.hpp index ff62305..0c9c20a 100644 --- a/libs/brynet/net/CurrentThread.hpp +++ b/libs/brynet/net/CurrentThread.hpp @@ -18,10 +18,6 @@ #include #endif -namespace brynet { -namespace net { -namespace current_thread { - #ifdef BRYNET_PLATFORM_WINDOWS using THREAD_ID_TYPE = DWORD; #elif defined BRYNET_PLATFORM_LINUX || defined BRYNET_PLATFORM_DARWIN @@ -52,7 +48,3 @@ static THREAD_ID_TYPE &tid() { return cachedTid; } - -} // namespace current_thread -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/EventLoop.hpp b/libs/brynet/net/EventLoop.hpp index 582a103..39a36a2 100644 --- a/libs/brynet/net/EventLoop.hpp +++ b/libs/brynet/net/EventLoop.hpp @@ -18,14 +18,11 @@ #include #include -namespace brynet { -namespace net { - class Channel; class TcpConnection; using TcpConnectionPtr = std::shared_ptr; -class EventLoop : public brynet::base::NonCopyable { +class EventLoop : public NonCopyable { public: using Ptr = std::shared_ptr; using UserFunctor = std::function; @@ -54,11 +51,11 @@ public: } #elif defined BRYNET_PLATFORM_LINUX auto eventfd = ::eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); - mWakeupChannel.reset(new detail::WakeupChannel(eventfd)); + mWakeupChannel.reset(new WakeupChannel(eventfd)); linkChannel(eventfd, mWakeupChannel.get()); #elif defined BRYNET_PLATFORM_DARWIN const int NOTIFY_IDENT = 42; // Magic number we use for our filter ID. - mWakeupChannel.reset(new detail::WakeupChannel(mKqueueFd, NOTIFY_IDENT)); + mWakeupChannel.reset(new WakeupChannel(mKqueueFd, NOTIFY_IDENT)); //Add user event struct kevent ev; EV_SET(&ev, NOTIFY_IDENT, EVFILT_USER, EV_ADD | EV_CLEAR, 0, 0, NULL); @@ -72,7 +69,7 @@ public: reAllocEventSize(1024); mSelfThreadID = -1; - mTimer = std::make_shared(); + mTimer = std::make_shared(); } virtual ~EventLoop() BRYNET_NOEXCEPT { @@ -247,8 +244,8 @@ public: mAfterLoopFunctors.emplace_back(std::move(f)); } - brynet::base::Timer::WeakPtr runAfter(std::chrono::nanoseconds timeout, UserFunctor &&callback) { - auto timer = std::make_shared( + Timer::WeakPtr runAfter(std::chrono::nanoseconds timeout, UserFunctor &&callback) { + auto timer = std::make_shared( std::chrono::steady_clock::now(), std::chrono::nanoseconds(timeout), std::move(callback)); @@ -266,7 +263,7 @@ public: } inline bool isInLoopThread() const { - return mSelfThreadID == current_thread::tid(); + return mSelfThreadID == tid(); } private: @@ -345,7 +342,7 @@ private: } void tryInitThreadID() { std::call_once(mOnceInitThreadID, [this]() { - mSelfThreadID = current_thread::tid(); + mSelfThreadID = tid(); }); } @@ -363,7 +360,7 @@ private: std::vector mEventEntries; int mKqueueFd; #endif - std::unique_ptr mWakeupChannel; + std::unique_ptr mWakeupChannel; std::atomic_bool mIsInBlock; std::atomic_bool mIsAlreadyPostWakeup; @@ -376,13 +373,10 @@ private: std::vector mCopyAfterLoopFunctors; std::once_flag mOnceInitThreadID; - current_thread::THREAD_ID_TYPE mSelfThreadID; + THREAD_ID_TYPE mSelfThreadID; - brynet::base::TimerMgr::Ptr mTimer; + TimerMgr::Ptr mTimer; std::unordered_map mTcpConnections; friend class TcpConnection; }; - -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/Exception.hpp b/libs/brynet/net/Exception.hpp index 3a12cb2..2ba0d50 100644 --- a/libs/brynet/net/Exception.hpp +++ b/libs/brynet/net/Exception.hpp @@ -3,9 +3,6 @@ #include #include -namespace brynet { -namespace net { - class ConnectException : public std::runtime_error { public: explicit ConnectException(const std::string &message) : @@ -27,6 +24,3 @@ public: std::runtime_error(message) { } }; - -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/ListenThread.hpp b/libs/brynet/net/ListenThread.hpp index bea5a46..5cbbace 100644 --- a/libs/brynet/net/ListenThread.hpp +++ b/libs/brynet/net/ListenThread.hpp @@ -2,10 +2,7 @@ #include -namespace brynet { -namespace net { - -class ListenThread : public detail::ListenThreadDetail, +class ListenThread : public ListenThreadDetail, public std::enable_shared_from_this { public: using Ptr = std::shared_ptr; @@ -13,11 +10,11 @@ public: using TcpSocketProcessCallback = std::function; void startListen() { - detail::ListenThreadDetail::startListen(); + ListenThreadDetail::startListen(); } void stopListen() { - detail::ListenThreadDetail::stopListen(); + ListenThreadDetail::stopListen(); } public: @@ -47,8 +44,5 @@ protected: const AccepCallback &callback, const std::vector &processCallbacks, bool enabledReusePort) : - detail::ListenThreadDetail(isIPV6, ip, port, callback, processCallbacks, enabledReusePort) {} + ListenThreadDetail(isIPV6, ip, port, callback, processCallbacks, enabledReusePort) {} }; - -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/Poller.hpp b/libs/brynet/net/Poller.hpp index a24aad8..1828b64 100644 --- a/libs/brynet/net/Poller.hpp +++ b/libs/brynet/net/Poller.hpp @@ -9,9 +9,6 @@ #include #endif -namespace brynet { -namespace base { - #ifdef BRYNET_PLATFORM_WINDOWS const static int CHECK_READ_FLAG = (POLLIN | POLLRDNORM | POLLRDBAND); const static int CHECK_WRITE_FLAG = (POLLOUT | POLLWRNORM); @@ -213,6 +210,3 @@ static bool poller_check(struct poller_s *self, BrynetSocketFD fd, enum CheckTyp } return check_event(pf, type); } - -} // namespace base -} // namespace brynet diff --git a/libs/brynet/net/PromiseReceive.hpp b/libs/brynet/net/PromiseReceive.hpp index 8b76436..5d83512 100644 --- a/libs/brynet/net/PromiseReceive.hpp +++ b/libs/brynet/net/PromiseReceive.hpp @@ -2,9 +2,6 @@ #include -namespace brynet { -namespace net { - /* binary search in memory */ void memsearch(const char *hay, size_t haysize, const char *needle, size_t needlesize, size_t &result, bool &isOK) { size_t haypos, needlepos; @@ -121,7 +118,7 @@ private: std::shared_ptr setupPromiseReceive(const TcpConnection::Ptr &session) { auto promiseReceive = std::make_shared(); - session->setDataCallback([promiseReceive](brynet::base::BasePacketReader &reader) { + session->setDataCallback([promiseReceive](BasePacketReader &reader) { auto procLen = promiseReceive->process(reader.begin(), reader.size()); reader.addPos(procLen); reader.savePos(); @@ -129,6 +126,3 @@ std::shared_ptr setupPromiseReceive(const TcpConnection::Ptr &se return promiseReceive; } - -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/SSLHelper.hpp b/libs/brynet/net/SSLHelper.hpp index cadc09e..450bab8 100644 --- a/libs/brynet/net/SSLHelper.hpp +++ b/libs/brynet/net/SSLHelper.hpp @@ -22,9 +22,6 @@ extern "C" { #endif -namespace brynet { -namespace net { - #ifdef BRYNET_USE_OPENSSL #ifndef CRYPTO_THREADID_set_callback @@ -69,7 +66,7 @@ static void InitCryptoThreadSafeSupport() { } #endif -class SSLHelper : public brynet::base::NonCopyable, +class SSLHelper : public NonCopyable, public std::enable_shared_from_this { public: using Ptr = std::shared_ptr; @@ -152,5 +149,3 @@ private: #endif }; -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/SendableMsg.hpp b/libs/brynet/net/SendableMsg.hpp index 7730143..b0fa390 100644 --- a/libs/brynet/net/SendableMsg.hpp +++ b/libs/brynet/net/SendableMsg.hpp @@ -1,9 +1,6 @@ #include #include -namespace brynet { -namespace net { - class SendableMsg { public: using Ptr = std::shared_ptr; @@ -48,5 +45,3 @@ static SendableMsg::Ptr MakeStringMsg(std::string &&buffer) { return std::make_shared(std::move(buffer)); } -} // namespace net -} // namespace brynet \ No newline at end of file diff --git a/libs/brynet/net/Socket.hpp b/libs/brynet/net/Socket.hpp index 28f382e..53ad5a9 100644 --- a/libs/brynet/net/Socket.hpp +++ b/libs/brynet/net/Socket.hpp @@ -7,18 +7,15 @@ #include #include -namespace brynet { -namespace net { - class TcpConnection; -class UniqueFd final : public brynet::base::NonCopyable { +class UniqueFd final : public NonCopyable { public: explicit UniqueFd(BrynetSocketFD fd) : mFD(fd) {} ~UniqueFd() { - brynet::net::base::SocketClose(mFD); + SocketClose(mFD); } UniqueFd(const UniqueFd &other) = delete; @@ -32,7 +29,7 @@ private: BrynetSocketFD mFD; }; -class TcpSocket : public brynet::base::NonCopyable { +class TcpSocket : public NonCopyable { private: class TcpSocketDeleter { public: @@ -57,23 +54,23 @@ public: public: void setNodelay() const { - brynet::net::base::SocketNodelay(mFD); + SocketNodelay(mFD); } bool setNonblock() const { - return brynet::net::base::SocketNonblock(mFD); + return SocketNonblock(mFD); } void setSendSize(int sdSize) const { - brynet::net::base::SocketSetSendSize(mFD, sdSize); + SocketSetSendSize(mFD, sdSize); } void setRecvSize(int rdSize) const { - brynet::net::base::SocketSetRecvSize(mFD, rdSize); + SocketSetRecvSize(mFD, rdSize); } std::string getRemoteIP() const { - return brynet::net::base::GetIPOfSocket(mFD); + return GetIPOfSocket(mFD); } bool isServerSide() const { @@ -87,7 +84,7 @@ protected: } virtual ~TcpSocket() { - brynet::net::base::SocketClose(mFD); + SocketClose(mFD); } BrynetSocketFD getFD() const { @@ -118,7 +115,7 @@ private: int mErrorCode; }; -class ListenSocket : public brynet::base::NonCopyable { +class ListenSocket : public NonCopyable { private: class ListenSocketDeleter { public: @@ -132,7 +129,7 @@ public: public: TcpSocket::Ptr accept() { - const auto clientFD = brynet::net::base::Accept(mFD, nullptr, nullptr); + const auto clientFD = Accept(mFD, nullptr, nullptr); if (clientFD == BRYNET_INVALID_SOCKET) { #if defined BRYNET_PLATFORM_LINUX || defined BRYNET_PLATFORM_DARWIN if (BRYNET_ERRNO == EMFILE) { @@ -141,8 +138,8 @@ public: // accept()ing when you can't" in libev's doc. // By Marc Lehmann, author of libev. mIdle.reset(); - TcpSocket::Create(brynet::net::base::Accept(mFD, nullptr, nullptr), true); - mIdle = brynet::net::TcpSocket::Create(::open("/dev/null", O_RDONLY | O_CLOEXEC), true); + TcpSocket::Create(Accept(mFD, nullptr, nullptr), true); + mIdle = TcpSocket::Create(::open("/dev/null", O_RDONLY | O_CLOEXEC), true); } #endif if (BRYNET_ERRNO == EINTR) { @@ -170,22 +167,20 @@ protected: explicit ListenSocket(BrynetSocketFD fd) : mFD(fd) { #if defined BRYNET_PLATFORM_LINUX || defined BRYNET_PLATFORM_DARWIN - mIdle = brynet::net::TcpSocket::Create(::open("/dev/null", O_RDONLY | O_CLOEXEC), true); + mIdle = TcpSocket::Create(::open("/dev/null", O_RDONLY | O_CLOEXEC), true); #endif } virtual ~ListenSocket() { - brynet::net::base::SocketClose(mFD); + SocketClose(mFD); } private: const BrynetSocketFD mFD; #if defined BRYNET_PLATFORM_LINUX || defined BRYNET_PLATFORM_DARWIN - brynet::net::TcpSocket::Ptr mIdle; + TcpSocket::Ptr mIdle; #endif friend class TcpConnection; }; -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/SocketLibFunction.hpp b/libs/brynet/net/SocketLibFunction.hpp index 248cb78..d036d8d 100644 --- a/libs/brynet/net/SocketLibFunction.hpp +++ b/libs/brynet/net/SocketLibFunction.hpp @@ -5,10 +5,6 @@ #include #include -namespace brynet { -namespace net { -namespace base { - static bool InitSocket() { bool ret = true; #ifdef BRYNET_PLATFORM_WINDOWS @@ -289,7 +285,3 @@ static bool IsSelfConnect(BrynetSocketFD fd) { return false; } } - -} // namespace base -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/TcpConnection.hpp b/libs/brynet/net/TcpConnection.hpp index 437981f..8edeb0f 100644 --- a/libs/brynet/net/TcpConnection.hpp +++ b/libs/brynet/net/TcpConnection.hpp @@ -34,17 +34,14 @@ extern "C" { #endif -namespace brynet { -namespace net { - class TcpConnection : public Channel, - public brynet::base::NonCopyable, + public NonCopyable, public std::enable_shared_from_this { public: using Ptr = std::shared_ptr; using EnterCallback = std::function; - using DataCallback = std::function; + using DataCallback = std::function; using DisconnectedCallback = std::function; using PacketSendedCallback = std::function; using HighWaterCallback = std::function; @@ -132,7 +129,7 @@ public: send(MakeStringMsg(std::move(buffer)), std::move(callback)); } - // setDataCallback(std::function) + // setDataCallback(std::function) template void setDataCallback(Callback &&cb) { verifyArgType(cb, &Callback::operator()); @@ -280,7 +277,7 @@ private: void growRecvBuffer() { if (mRecvBuffer == nullptr) { - mRecvBuffer.reset(brynet::base::buffer_new(std::min(16 * 1024, mMaxRecvBufferSize))); + mRecvBuffer.reset(buffer_new(std::min(16 * 1024, mMaxRecvBufferSize))); mRecvBuffOriginSize = buffer_getsize(mRecvBuffer.get()); } else { if (buffer_getsize(mRecvBuffer.get()) >= mMaxRecvBufferSize) { @@ -293,7 +290,7 @@ private: const auto NewSize = mRecvBuffOriginSize + (maxSizeDiff * newTanh); assert(NewSize <= mMaxRecvBufferSize); - std::unique_ptr newBuffer(brynet::base::buffer_new(NewSize)); + std::unique_ptr newBuffer(buffer_new(NewSize)); buffer_write(newBuffer.get(), buffer_getreadptr(mRecvBuffer.get()), buffer_getreadvalidcount(mRecvBuffer.get())); @@ -310,8 +307,8 @@ private: return; } - std::unique_ptr - newBuffer(brynet::base::buffer_new(newSize)); + std::unique_ptr + newBuffer(buffer_new(newSize)); buffer_write(newBuffer.get(), buffer_getreadptr(mRecvBuffer.get()), buffer_getreadvalidcount(mRecvBuffer.get())); @@ -328,7 +325,7 @@ private: return false; } - if (!brynet::net::base::SocketNonblock(mSocket->getFD()) || + if (!SocketNonblock(mSocket->getFD()) || !mEventLoop->linkChannel(mSocket->getFD(), this)) { return false; } @@ -975,7 +972,7 @@ private: void processRecvMessage() { if (mDataCallback != nullptr && buffer_getreadvalidcount(mRecvBuffer.get()) > 0) { - auto reader = brynet::base::BasePacketReader(buffer_getreadptr(mRecvBuffer.get()), + auto reader = BasePacketReader(buffer_getreadptr(mRecvBuffer.get()), buffer_getreadvalidcount(mRecvBuffer.get()), false); mDataCallback(reader); const auto consumedLen = reader.savedPos(); @@ -1009,11 +1006,11 @@ private: class BufferDeleter { public: - void operator()(struct brynet::base::buffer_s *ptr) const { - brynet::base::buffer_delete(ptr); + void operator()(struct buffer_s *ptr) const { + buffer_delete(ptr); } }; - std::unique_ptr mRecvBuffer; + std::unique_ptr mRecvBuffer; double mCurrentTanhXDiff = 0; size_t mRecvBuffOriginSize = 0; const size_t mMaxRecvBufferSize; @@ -1043,8 +1040,5 @@ private: #endif bool mRecvData; std::chrono::nanoseconds mCheckTime{}; - brynet::base::Timer::WeakPtr mTimer; + Timer::WeakPtr mTimer; }; - -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/TcpService.hpp b/libs/brynet/net/TcpService.hpp index 854a82d..88fca99 100644 --- a/libs/brynet/net/TcpService.hpp +++ b/libs/brynet/net/TcpService.hpp @@ -2,15 +2,12 @@ #include -namespace brynet { -namespace net { - -using ConnectionOption = detail::ConnectionOption; -class TcpService : public detail::TcpServiceDetail, +using ConnectionOption = ConnectionOption; +class TcpService : public TcpServiceDetail, public std::enable_shared_from_this { public: using Ptr = std::shared_ptr; - using FrameCallback = detail::TcpServiceDetail::FrameCallback; + using FrameCallback = TcpServiceDetail::FrameCallback; public: static Ptr Create() { @@ -21,24 +18,21 @@ public: void startWorkerThread(size_t threadNum, FrameCallback callback = nullptr) { - detail::TcpServiceDetail::startWorkerThread(threadNum, callback); + TcpServiceDetail::startWorkerThread(threadNum, callback); } void stopWorkerThread() { - detail::TcpServiceDetail::stopWorkerThread(); + TcpServiceDetail::stopWorkerThread(); } bool addTcpConnection(TcpSocket::Ptr socket, ConnectionOption options) { - return detail::TcpServiceDetail::addTcpConnection(std::move(socket), options); + return TcpServiceDetail::addTcpConnection(std::move(socket), options); } EventLoop::Ptr getRandomEventLoop() { - return detail::TcpServiceDetail::getRandomEventLoop(); + return TcpServiceDetail::getRandomEventLoop(); } private: TcpService() = default; }; - -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/detail/ConnectionOption.hpp b/libs/brynet/net/detail/ConnectionOption.hpp index f9951cb..3281695 100644 --- a/libs/brynet/net/detail/ConnectionOption.hpp +++ b/libs/brynet/net/detail/ConnectionOption.hpp @@ -3,10 +3,6 @@ #include #include -namespace brynet { -namespace net { -namespace detail { - class ConnectionOption final { public: std::vector enterCallback; @@ -15,7 +11,3 @@ public: bool forceSameThreadLoop = false; size_t maxRecvBufferSize = 128; }; - -} // namespace detail -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/detail/ConnectorDetail.hpp b/libs/brynet/net/detail/ConnectorDetail.hpp index 371bc48..e21e735 100644 --- a/libs/brynet/net/detail/ConnectorDetail.hpp +++ b/libs/brynet/net/detail/ConnectorDetail.hpp @@ -15,11 +15,7 @@ #include #endif -namespace brynet { -namespace net { -namespace detail { - -class AsyncConnectorDetail : public brynet::base::NonCopyable { +class AsyncConnectorDetail : public NonCopyable { protected: void startWorkerThread() { #ifdef BRYNET_HAVE_LANG_CXX17 @@ -33,7 +29,7 @@ protected: } mIsRun = std::make_shared(true); - mWorkInfo = std::make_shared(); + mWorkInfo = std::make_shared(); mEventLoop = std::make_shared(); auto eventLoop = mEventLoop; @@ -42,7 +38,7 @@ protected: mThread = std::make_shared([eventLoop, workerInfo, isRun]() { while (*isRun) { - detail::RunOnceCheckConnect(eventLoop, workerInfo); + RunOnceCheckConnect(eventLoop, workerInfo); } workerInfo->causeAllFailed(); @@ -78,7 +74,7 @@ protected: mThread = nullptr; } - void asyncConnect(detail::ConnectOption option) { + void asyncConnect(ConnectOption option) { #ifdef BRYNET_HAVE_LANG_CXX17 std::shared_lock lck(mThreadGuard); #else @@ -97,7 +93,7 @@ protected: } auto workInfo = mWorkInfo; - auto address = detail::AsyncConnectAddr(std::move(option.ip), + auto address = AsyncConnectAddr(std::move(option.ip), option.port, option.timeout, std::move(option.completedCallback), @@ -120,7 +116,7 @@ protected: private: std::shared_ptr mEventLoop; - std::shared_ptr mWorkInfo; + std::shared_ptr mWorkInfo; std::shared_ptr mThread; #ifdef BRYNET_HAVE_LANG_CXX17 std::shared_mutex mThreadGuard; @@ -130,6 +126,3 @@ private: std::shared_ptr mIsRun; }; -} // namespace detail -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/detail/ConnectorWorkInfo.hpp b/libs/brynet/net/detail/ConnectorWorkInfo.hpp index 7b20a8e..059e272 100644 --- a/libs/brynet/net/detail/ConnectorWorkInfo.hpp +++ b/libs/brynet/net/detail/ConnectorWorkInfo.hpp @@ -16,10 +16,6 @@ #include #endif -namespace brynet { -namespace net { -namespace detail { - class AsyncConnectAddr final { public: using CompletedCallback = std::function; @@ -74,13 +70,13 @@ private: const std::vector mProcessCallbacks; }; -class ConnectorWorkInfo final : public brynet::base::NonCopyable { +class ConnectorWorkInfo final : public NonCopyable { public: using Ptr = std::shared_ptr; ConnectorWorkInfo() BRYNET_NOEXCEPT { - mPoller.reset(brynet::base::poller_new()); - mPollResult.reset(brynet::base::stack_new(1024, sizeof(BrynetSocketFD))); + mPoller.reset(poller_new()); + mPollResult.reset(stack_new(1024, sizeof(BrynetSocketFD))); } void checkConnectStatus(int millSecond) { @@ -91,7 +87,7 @@ public: std::set totalFds; std::set successFds; - poller_visitor(mPoller.get(), brynet::base::WriteCheck, mPollResult.get()); + poller_visitor(mPoller.get(), WriteCheck, mPollResult.get()); while (true) { auto p = stack_popfront(mPollResult.get()); if (p == nullptr) { @@ -101,7 +97,7 @@ public: const auto fd = *(BrynetSocketFD *)p; totalFds.insert(fd); if (isConnectSuccess(fd, false) && - !brynet::net::base::IsSelfConnect(fd)) { + !IsSelfConnect(fd)) { successFds.insert(fd); } } @@ -134,7 +130,7 @@ public: } bool isConnectSuccess(BrynetSocketFD clientfd, bool willCheckWrite) const { - if (willCheckWrite && !poller_check(mPoller.get(), clientfd, brynet::base::WriteCheck)) { + if (willCheckWrite && !poller_check(mPoller.get(), clientfd, WriteCheck)) { return false; } @@ -165,7 +161,7 @@ public: poller_remove(mPoller.get(), fd); mConnectingInfos.erase(it++); - brynet::net::base::SocketClose(fd); + SocketClose(fd); if (cb != nullptr) { //TODO::don't modify mConnectingInfos in cb cb(); @@ -184,21 +180,21 @@ public: #endif int n = 0; - brynet::net::base::InitSocket(); + InitSocket(); - clientfd = brynet::net::base::SocketCreate(AF_INET, SOCK_STREAM, 0); + clientfd = SocketCreate(AF_INET, SOCK_STREAM, 0); if (clientfd == BRYNET_INVALID_SOCKET) { goto FAILED; } - brynet::net::base::SocketNonblock(clientfd); + SocketNonblock(clientfd); server_addr.sin_family = AF_INET; inet_pton(AF_INET, addr.getIP().c_str(), &server_addr.sin_addr.s_addr); server_addr.sin_port = static_cast(htons(addr.getPort())); n = connect(clientfd, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)); if (n == 0) { - if (brynet::net::base::IsSelfConnect(clientfd)) { + if (IsSelfConnect(clientfd)) { goto FAILED; } } else if (BRYNET_ERRNO != ExpectedError) { @@ -212,7 +208,7 @@ public: ci.processCallbacks = addr.getProcessCallbacks(); mConnectingInfos[clientfd] = ci; - poller_add(mPoller.get(), clientfd, brynet::base::WriteCheck); + poller_add(mPoller.get(), clientfd, WriteCheck); return; } @@ -228,7 +224,7 @@ public: FAILED: if (clientfd != BRYNET_INVALID_SOCKET) { - brynet::net::base::SocketClose(clientfd); + SocketClose(clientfd); clientfd = BRYNET_INVALID_SOCKET; (void)clientfd; } @@ -246,7 +242,7 @@ public: auto cb = v.second.failedCB; poller_remove(mPoller.get(), fd); - brynet::net::base::SocketClose(fd); + SocketClose(fd); if (cb != nullptr) { cb(); } @@ -271,23 +267,23 @@ private: class PollerDeleter { public: - void operator()(struct brynet::base::poller_s *ptr) const { - brynet::base::poller_delete(ptr); + void operator()(struct poller_s *ptr) const { + poller_delete(ptr); } }; class StackDeleter { public: - void operator()(struct brynet::base::stack_s *ptr) const { - brynet::base::stack_delete(ptr); + void operator()(struct stack_s *ptr) const { + stack_delete(ptr); } }; - std::unique_ptr mPoller; - std::unique_ptr mPollResult; + std::unique_ptr mPoller; + std::unique_ptr mPollResult; }; static void RunOnceCheckConnect( - const std::shared_ptr &eventLoop, + const std::shared_ptr &eventLoop, const std::shared_ptr &workerInfo) { eventLoop->loop(std::chrono::milliseconds(10).count()); workerInfo->checkConnectStatus(0); @@ -303,7 +299,3 @@ public: AsyncConnectAddr::CompletedCallback completedCallback; AsyncConnectAddr::FailedCallback failedCallback; }; - -} // namespace detail -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/detail/IOLoopData.hpp b/libs/brynet/net/detail/IOLoopData.hpp index 4f57087..104ac46 100644 --- a/libs/brynet/net/detail/IOLoopData.hpp +++ b/libs/brynet/net/detail/IOLoopData.hpp @@ -5,13 +5,9 @@ #include #include -namespace brynet { -namespace net { -namespace detail { - class TcpServiceDetail; -class IOLoopData : public brynet::base::NonCopyable, +class IOLoopData : public NonCopyable, public std::enable_shared_from_this { public: using Ptr = std::shared_ptr; @@ -53,7 +49,3 @@ private: }; using IOLoopDataPtr = std::shared_ptr; - -} // namespace detail -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/detail/ListenThreadDetail.hpp b/libs/brynet/net/detail/ListenThreadDetail.hpp index 03b5e93..80ecdf9 100644 --- a/libs/brynet/net/detail/ListenThreadDetail.hpp +++ b/libs/brynet/net/detail/ListenThreadDetail.hpp @@ -14,11 +14,7 @@ #include #include -namespace brynet { -namespace net { -namespace detail { - -class ListenThreadDetail : public brynet::base::NonCopyable { +class ListenThreadDetail : public NonCopyable { protected: using AccepCallback = std::function; using TcpSocketProcessCallback = std::function; @@ -30,7 +26,7 @@ protected: return; } - const auto fd = brynet::net::base::Listen(mIsIPV6, mIP.c_str(), mPort, 512, mEnabledReusePort); + const auto fd = Listen(mIsIPV6, mIP.c_str(), mPort, 512, mEnabledReusePort); if (fd == BRYNET_INVALID_SOCKET) { throw BrynetCommonException( std::string("listen error of:") + std::to_string(BRYNET_ERRNO)); @@ -77,7 +73,7 @@ protected: connector->startWorkerThread(); //TODO:: if the listen enable reuse_port, one time connect may be can't wakeup listen. - wrapper::SocketConnectBuilder connectBuilder; + SocketConnectBuilder connectBuilder; (void)connectBuilder .WithConnector(connector) .WithTimeout(std::chrono::seconds(2)) @@ -118,7 +114,7 @@ protected: } private: - static brynet::net::TcpSocket::Ptr runOnceListen(const std::shared_ptr &listenSocket) { + static TcpSocket::Ptr runOnceListen(const std::shared_ptr &listenSocket) { try { return listenSocket->accept(); } catch (const EintrError &e) { @@ -142,7 +138,3 @@ private: std::shared_ptr mListenThread; std::mutex mListenThreadGuard; }; - -} // namespace detail -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/detail/TCPServiceDetail.hpp b/libs/brynet/net/detail/TCPServiceDetail.hpp index 9a323fd..a8ee7bb 100644 --- a/libs/brynet/net/detail/TCPServiceDetail.hpp +++ b/libs/brynet/net/detail/TCPServiceDetail.hpp @@ -13,11 +13,7 @@ #include #include -namespace brynet { -namespace net { -namespace detail { - -class TcpServiceDetail : public brynet::base::NonCopyable { +class TcpServiceDetail : public NonCopyable { protected: using FrameCallback = std::function; const static unsigned int sDefaultLoopTimeOutMS = 100; @@ -144,7 +140,3 @@ private: std::mutex mServiceGuard; std::mt19937 mRandom; }; - -} // namespace detail -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/detail/WakeupChannel.hpp b/libs/brynet/net/detail/WakeupChannel.hpp index 2fb4ae7..00ec1c7 100644 --- a/libs/brynet/net/detail/WakeupChannel.hpp +++ b/libs/brynet/net/detail/WakeupChannel.hpp @@ -8,12 +8,8 @@ #include #include -namespace brynet { -namespace net { -namespace detail { - #ifdef BRYNET_PLATFORM_WINDOWS -class WakeupChannel final : public Channel, public brynet::base::NonCopyable { +class WakeupChannel final : public Channel, public NonCopyable { public: explicit WakeupChannel(HANDLE iocp) : mIOCP(iocp), @@ -44,7 +40,7 @@ private: port::Win::OverlappedExt mWakeupOvl; }; #elif defined BRYNET_PLATFORM_LINUX -class WakeupChannel final : public Channel, public brynet::base::NonCopyable { +class WakeupChannel final : public Channel, public NonCopyable { public: explicit WakeupChannel(BrynetSocketFD fd) : mUniqueFd(fd) { @@ -77,7 +73,7 @@ private: }; #elif defined BRYNET_PLATFORM_DARWIN -class WakeupChannel final : public Channel, public brynet::base::NonCopyable { +class WakeupChannel final : public Channel, public NonCopyable { public: explicit WakeupChannel(int kqueuefd, int ident) : mKqueueFd(kqueuefd), @@ -108,6 +104,3 @@ private: }; #endif -} // namespace detail -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/http/HttpFormat.hpp b/libs/brynet/net/http/HttpFormat.hpp index 3824fdb..bd360cb 100644 --- a/libs/brynet/net/http/HttpFormat.hpp +++ b/libs/brynet/net/http/HttpFormat.hpp @@ -5,10 +5,6 @@ #include #include -namespace brynet { -namespace net { -namespace http { - class HttpQueryParameter final { public: void add(const std::string &k, const std::string &v) { @@ -198,7 +194,3 @@ private: std::map mHeadField; std::string mBody; }; - -} // namespace http -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/http/HttpParser.hpp b/libs/brynet/net/http/HttpParser.hpp index 4809de8..39e21f8 100644 --- a/libs/brynet/net/http/HttpParser.hpp +++ b/libs/brynet/net/http/HttpParser.hpp @@ -8,10 +8,6 @@ #include "http_parser.h" -namespace brynet { -namespace net { -namespace http { - class HttpService; class HTTPParser { @@ -284,7 +280,3 @@ private: private: friend class HttpService; }; - -} // namespace http -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/http/HttpService.hpp b/libs/brynet/net/http/HttpService.hpp index c42b357..08cdd7c 100644 --- a/libs/brynet/net/http/HttpService.hpp +++ b/libs/brynet/net/http/HttpService.hpp @@ -6,14 +6,10 @@ #include #include -namespace brynet { -namespace net { -namespace http { - class HttpService; class HttpSessionHandlers; -class HttpSession : public brynet::base::NonCopyable { +class HttpSession : public NonCopyable { public: using Ptr = std::shared_ptr; @@ -172,7 +168,7 @@ private: }); session->setDataCallback([httpSession, httpParser]( - brynet::base::BasePacketReader &reader) { + BasePacketReader &reader) { size_t retLen = 0; if (httpParser->isWebSocket()) { @@ -301,6 +297,3 @@ private: } }; -} // namespace http -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/http/WebSocketFormat.hpp b/libs/brynet/net/http/WebSocketFormat.hpp index 42484a3..0994f8b 100644 --- a/libs/brynet/net/http/WebSocketFormat.hpp +++ b/libs/brynet/net/http/WebSocketFormat.hpp @@ -8,10 +8,6 @@ #include #include -namespace brynet { -namespace net { -namespace http { - class WebSocketFormat { public: enum class WebSocketFrameType { @@ -33,7 +29,7 @@ public: unsigned char puDest[20]; s1.GetHash(puDest); - std::string base64Str = brynet::base::crypto::base64_encode((const unsigned char *)puDest, 20); + std::string base64Str = base64_encode((const unsigned char *)puDest, 20); std::string response = "HTTP/1.1 101 Switching Protocols\r\n" @@ -206,7 +202,3 @@ public: isFin); } }; - -} // namespace http -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/port/Win.hpp b/libs/brynet/net/port/Win.hpp index 91a9946..7d21a0e 100644 --- a/libs/brynet/net/port/Win.hpp +++ b/libs/brynet/net/port/Win.hpp @@ -2,9 +2,6 @@ #include -namespace brynet { -namespace net { -namespace port { #ifdef BRYNET_PLATFORM_WINDOWS class Win { @@ -25,7 +22,3 @@ public: }; }; #endif - -} // namespace port -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/wrapper/ConnectionBuilder.hpp b/libs/brynet/net/wrapper/ConnectionBuilder.hpp index b650701..a60a1fa 100644 --- a/libs/brynet/net/wrapper/ConnectionBuilder.hpp +++ b/libs/brynet/net/wrapper/ConnectionBuilder.hpp @@ -6,13 +6,9 @@ #include #include -namespace brynet { -namespace net { -namespace wrapper { - -using CompletedCallback = detail::AsyncConnectAddr::CompletedCallback; -using ProcessTcpSocketCallback = detail::AsyncConnectAddr::ProcessTcpSocketCallback; -using FailedCallback = detail::AsyncConnectAddr::FailedCallback; +using CompletedCallback = AsyncConnectAddr::CompletedCallback; +using ProcessTcpSocketCallback = AsyncConnectAddr::ProcessTcpSocketCallback; +using FailedCallback = AsyncConnectAddr::FailedCallback; template class BaseSocketConnectBuilder { @@ -179,7 +175,3 @@ private: class ConnectionBuilder : public BaseConnectionBuilder { }; - -} // namespace wrapper -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/wrapper/HttpConnectionBuilder.hpp b/libs/brynet/net/wrapper/HttpConnectionBuilder.hpp index 08f08c3..1f9fc2f 100644 --- a/libs/brynet/net/wrapper/HttpConnectionBuilder.hpp +++ b/libs/brynet/net/wrapper/HttpConnectionBuilder.hpp @@ -4,10 +4,6 @@ #include #include -namespace brynet { -namespace net { -namespace wrapper { - class HttpConnectionBuilder { public: HttpConnectionBuilder &WithService(TcpService::Ptr service) { @@ -35,7 +31,7 @@ public: return *this; } - HttpConnectionBuilder &WithEnterCallback(http::HttpSession::EnterCallback &&callback) { + HttpConnectionBuilder &WithEnterCallback(HttpSession::EnterCallback &&callback) { mHttpEnterCallback = std::move(callback); return *this; } @@ -69,16 +65,13 @@ public: auto callback = mHttpEnterCallback; auto builder = mBuilder; builder.AddEnterCallback([callback](const TcpConnection::Ptr &session) { - http::HttpService::setup(session, callback); + HttpService::setup(session, callback); }); builder.asyncConnect(); } private: - http::HttpSession::EnterCallback mHttpEnterCallback; + HttpSession::EnterCallback mHttpEnterCallback; ConnectionBuilder mBuilder; }; -} // namespace wrapper -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/wrapper/HttpServiceBuilder.hpp b/libs/brynet/net/wrapper/HttpServiceBuilder.hpp index ca5820d..001ed6c 100644 --- a/libs/brynet/net/wrapper/HttpServiceBuilder.hpp +++ b/libs/brynet/net/wrapper/HttpServiceBuilder.hpp @@ -4,10 +4,6 @@ #include #include -namespace brynet { -namespace net { -namespace wrapper { - class HttpListenerBuilder { public: HttpListenerBuilder &WithService(TcpService::Ptr service) { @@ -15,7 +11,7 @@ public: return *this; } - HttpListenerBuilder &WithEnterCallback(http::HttpSession::EnterCallback &&callback) { + HttpListenerBuilder &WithEnterCallback(HttpSession::EnterCallback &&callback) { mHttpEnterCallback = std::move(callback); return *this; } @@ -57,16 +53,12 @@ public: auto callback = mHttpEnterCallback; mBuilder.AddEnterCallback([callback](const TcpConnection::Ptr &session) { - http::HttpService::setup(session, callback); + HttpService::setup(session, callback); }); mBuilder.asyncRun(); } private: - http::HttpSession::EnterCallback mHttpEnterCallback; + HttpSession::EnterCallback mHttpEnterCallback; ListenerBuilder mBuilder; }; - -} // namespace wrapper -} // namespace net -} // namespace brynet diff --git a/libs/brynet/net/wrapper/ServiceBuilder.hpp b/libs/brynet/net/wrapper/ServiceBuilder.hpp index 75430f0..f1ebd03 100644 --- a/libs/brynet/net/wrapper/ServiceBuilder.hpp +++ b/libs/brynet/net/wrapper/ServiceBuilder.hpp @@ -6,10 +6,6 @@ #include #include -namespace brynet { -namespace net { -namespace wrapper { - template class BaseListenerBuilder { public: @@ -72,7 +68,7 @@ public: mIsIpV6, mListenAddr, mPort, - [service, option](brynet::net::TcpSocket::Ptr socket) { + [service, option](TcpSocket::Ptr socket) { service->addTcpConnection(std::move(socket), option); }, mSocketProcessCallbacks, @@ -99,7 +95,3 @@ private: class ListenerBuilder : public BaseListenerBuilder { }; - -} // namespace wrapper -} // namespace net -} // namespace brynet