From 1ed5d98c2b8041b60f20b84f32ad00501f58fc34 Mon Sep 17 00:00:00 2001 From: "irons.du" Date: Wed, 17 Oct 2018 09:44:54 +0800 Subject: [PATCH] none --- src/brynet/net/Any.h | 5 +---- src/brynet/net/Channel.h | 7 ++----- src/brynet/net/Connector.cpp | 26 +++++++++++--------------- src/brynet/net/Connector.h | 7 ++----- src/brynet/net/CurrentThread.h | 5 +---- src/brynet/net/DataSocket.cpp | 26 ++++++++++++++------------ src/brynet/net/DataSocket.h | 7 ++----- src/brynet/net/EventLoop.h | 7 ++----- src/brynet/net/ListenThread.h | 5 +---- src/brynet/net/Noexcept.h | 5 +---- src/brynet/net/Platform.h | 5 +---- src/brynet/net/PromiseReceive.h | 5 +---- src/brynet/net/SSLHelper.h | 5 +---- src/brynet/net/Socket.h | 9 +++------ src/brynet/net/SocketLibFunction.h | 5 +---- src/brynet/net/SocketLibTypes.h | 5 +---- src/brynet/net/SyncConnector.h | 5 +---- src/brynet/net/TCPService.h | 5 +---- src/brynet/net/fdset.h | 5 +---- src/brynet/net/http/HttpFormat.h | 9 +++------ src/brynet/net/http/HttpParser.h | 7 ++----- src/brynet/net/http/HttpService.cpp | 12 ++++-------- src/brynet/net/http/HttpService.h | 7 ++----- src/brynet/net/http/WebSocketFormat.h | 17 ++++++----------- src/brynet/timer/Timer.h | 7 ++----- src/brynet/utils/CPP_VERSION.h | 5 +---- src/brynet/utils/MsgQueue.h | 7 ++----- src/brynet/utils/NonCopyable.h | 14 ++++++-------- src/brynet/utils/Typeids.h | 7 ++----- src/brynet/utils/WaitGroup.h | 8 ++------ src/brynet/utils/app_status.h | 7 +------ src/brynet/utils/array.h | 5 +---- src/brynet/utils/buffer.h | 5 +---- src/brynet/utils/packet.h | 17 ++++++----------- src/brynet/utils/stack.h | 5 +---- 35 files changed, 90 insertions(+), 198 deletions(-) diff --git a/src/brynet/net/Any.h b/src/brynet/net/Any.h index ddd52463..5ceb05d2 100644 --- a/src/brynet/net/Any.h +++ b/src/brynet/net/Any.h @@ -1,5 +1,4 @@ -#ifndef _BRYNET_NET_ANY_H -#define _BRYNET_NET_ANY_H +#pragma once #include @@ -31,5 +30,3 @@ namespace brynet #endif } } - -#endif diff --git a/src/brynet/net/Channel.h b/src/brynet/net/Channel.h index fbdffe3d..121222e8 100644 --- a/src/brynet/net/Channel.h +++ b/src/brynet/net/Channel.h @@ -1,5 +1,4 @@ -#ifndef BRYNET_NET_CHANNEL_H_ -#define BRYNET_NET_CHANNEL_H_ +#pragma once namespace brynet { @@ -20,6 +19,4 @@ namespace brynet friend class EventLoop; }; } -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/brynet/net/Connector.cpp b/src/brynet/net/Connector.cpp index a3719827..e98f0411 100644 --- a/src/brynet/net/Connector.cpp +++ b/src/brynet/net/Connector.cpp @@ -1,14 +1,10 @@ #include #include -#include #include #include -#include -#include #include #include -#include #include @@ -22,16 +18,16 @@ namespace brynet class AsyncConnectAddr { public: - AsyncConnectAddr(const std::string& ip, + AsyncConnectAddr(std::string ip, int port, std::chrono::nanoseconds timeout, - const AsyncConnector::COMPLETED_CALLBACK& successCB, - const AsyncConnector::FAILED_CALLBACK& failedCB) : - mIP(ip), + AsyncConnector::COMPLETED_CALLBACK successCB, + AsyncConnector::FAILED_CALLBACK failedCB) : + mIP(std::move(ip)), mPort(port), mTimeout(timeout), - mSuccessCB(successCB), - mFailedCB(failedCB) + mSuccessCB(std::move(successCB)), + mFailedCB(std::move(failedCB)) { } @@ -61,11 +57,11 @@ namespace brynet } private: - std::string mIP; - int mPort; - std::chrono::nanoseconds mTimeout; - AsyncConnector::COMPLETED_CALLBACK mSuccessCB; - AsyncConnector::FAILED_CALLBACK mFailedCB; + const std::string mIP; + const int mPort; + const std::chrono::nanoseconds mTimeout; + const AsyncConnector::COMPLETED_CALLBACK mSuccessCB; + const AsyncConnector::FAILED_CALLBACK mFailedCB; }; class ConnectorWorkInfo final : public NonCopyable diff --git a/src/brynet/net/Connector.h b/src/brynet/net/Connector.h index c93d6b46..4bc6041a 100644 --- a/src/brynet/net/Connector.h +++ b/src/brynet/net/Connector.h @@ -1,5 +1,4 @@ -#ifndef BRYNET_NET_CONNECTOR_H_ -#define BRYNET_NET_CONNECTOR_H_ +#pragma once #include #include @@ -58,6 +57,4 @@ namespace brynet std::shared_ptr mIsRun; }; } -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/brynet/net/CurrentThread.h b/src/brynet/net/CurrentThread.h index 9b8a3d83..04a68bff 100644 --- a/src/brynet/net/CurrentThread.h +++ b/src/brynet/net/CurrentThread.h @@ -1,5 +1,4 @@ -#ifndef BRYNET_NET_CURRENTTHREAD_H_ -#define BRYNET_NET_CURRENTTHREAD_H_ +#pragma once #include #include @@ -29,5 +28,3 @@ namespace brynet } } } - -#endif diff --git a/src/brynet/net/DataSocket.cpp b/src/brynet/net/DataSocket.cpp index 3d9977a0..601c06aa 100644 --- a/src/brynet/net/DataSocket.cpp +++ b/src/brynet/net/DataSocket.cpp @@ -21,7 +21,7 @@ DataSocket::DataSocket(TcpSocket::PTR socket, #endif mIP(socket->GetIP()), mSocket(std::move(socket)), - mEventLoop(eventLoop), + mEventLoop(std::move(eventLoop)), mAlreadyClose(false), mMaxRecvBufferSize(maxRecvBufferSize) { @@ -42,7 +42,7 @@ DataSocket::DataSocket(TcpSocket::PTR socket, mSSL = nullptr; mIsHandsharked = false; #endif - mEnterCallback = enterCallback; + mEnterCallback = std::move(enterCallback); } DataSocket::~DataSocket() BRYNET_NOEXCEPT @@ -81,10 +81,14 @@ DataSocket::PTR DataSocket::Create(TcpSocket::PTR socket, ENTER_CALLBACK enterCallback, EventLoop::PTR eventLoop) : - DataSocket(std::move(socket), maxRecvBufferSize, enterCallback, eventLoop) + DataSocket(std::move(socket), maxRecvBufferSize, std::move(enterCallback), std::move(eventLoop)) {} }; - return std::make_shared(std::move(socket), maxRecvBufferSize, enterCallback, eventLoop); + return std::make_shared( + std::move(socket), + maxRecvBufferSize, + std::move(enterCallback), + std::move(eventLoop)); } bool DataSocket::onEnterEventLoop() @@ -488,14 +492,12 @@ void DataSocket::quickFlush() { int num = 0; size_t ready_send_len = 0; - for (PACKET_LIST_TYPE::iterator it = mSendList.begin(); it != mSendList.end();) + for(const auto& p : mSendList) { - pending_packet& b = *it; - iov[num].iov_base = (void*)(b.data->c_str() + (b.data->size() - b.left)); - iov[num].iov_len = b.left; - ready_send_len += b.left; + iov[num].iov_base = (void*)(p.data->c_str() + (p.data->size() - p.left)); + iov[num].iov_len = p.left; + ready_send_len += p.left; - ++it; num++; if (num >= MAX_IOVEC) { @@ -524,7 +526,7 @@ void DataSocket::quickFlush() } auto tmp_len = static_cast(send_len); - for (PACKET_LIST_TYPE::iterator it = mSendList.begin(); it != mSendList.end();) + for (auto it = mSendList.begin(); it != mSendList.end();) { pending_packet& b = *it; if (b.left > tmp_len) @@ -582,7 +584,7 @@ void DataSocket::procCloseInLoop() onClose(); } #else - struct epoll_event ev = { 0, { 0 } }; + struct epoll_event ev = { 0, { nullptr } }; epoll_ctl(mEventLoop->getEpollHandle(), EPOLL_CTL_DEL, mSocket->getFD(), &ev); onClose(); #endif diff --git a/src/brynet/net/DataSocket.h b/src/brynet/net/DataSocket.h index 83676d4e..3becb5b5 100644 --- a/src/brynet/net/DataSocket.h +++ b/src/brynet/net/DataSocket.h @@ -1,5 +1,4 @@ -#ifndef BRYNET_NET_DATASOCKET_H_ -#define BRYNET_NET_DATASOCKET_H_ +#pragma once #include #include @@ -166,6 +165,4 @@ namespace brynet Timer::WeakPtr mTimer; }; } -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/brynet/net/EventLoop.h b/src/brynet/net/EventLoop.h index 7a2b90ac..6c6fd574 100644 --- a/src/brynet/net/EventLoop.h +++ b/src/brynet/net/EventLoop.h @@ -1,5 +1,4 @@ -#ifndef BRYNET_NET_EVENTLOOP_H_ -#define BRYNET_NET_EVENTLOOP_H_ +#pragma once #include #include @@ -115,6 +114,4 @@ namespace brynet friend class DataSocket; }; } -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/brynet/net/ListenThread.h b/src/brynet/net/ListenThread.h index 167dbf5a..a2144d35 100644 --- a/src/brynet/net/ListenThread.h +++ b/src/brynet/net/ListenThread.h @@ -1,5 +1,4 @@ -#ifndef BRYNET_NET_TCP_ACCEPTOR_H_ -#define BRYNET_NET_TCP_ACCEPTOR_H_ +#pragma once #include #include @@ -44,5 +43,3 @@ namespace brynet }; } } - -#endif diff --git a/src/brynet/net/Noexcept.h b/src/brynet/net/Noexcept.h index 8e9c1f8f..f3be2dec 100644 --- a/src/brynet/net/Noexcept.h +++ b/src/brynet/net/Noexcept.h @@ -1,5 +1,4 @@ -#ifndef _BRYNET_NET_NOEXCEPT_H -#define _BRYNET_NET_NOEXCEPT_H +#pragma once #include @@ -8,5 +7,3 @@ #else #define BRYNET_NOEXCEPT #endif - -#endif diff --git a/src/brynet/net/Platform.h b/src/brynet/net/Platform.h index 50a30fbf..40473546 100644 --- a/src/brynet/net/Platform.h +++ b/src/brynet/net/Platform.h @@ -1,10 +1,7 @@ -#ifndef _PLATFORM_H -#define _PLATFORM_H +#pragma once #if defined _MSC_VER || defined __MINGW32__ #define PLATFORM_WINDOWS #else #define PLATFORM_LINUX #endif - -#endif diff --git a/src/brynet/net/PromiseReceive.h b/src/brynet/net/PromiseReceive.h index b834ebf6..bbb927dc 100644 --- a/src/brynet/net/PromiseReceive.h +++ b/src/brynet/net/PromiseReceive.h @@ -1,5 +1,4 @@ -#ifndef _BRYNET_NET_PROMISE_RECEIVE_H -#define _BRYNET_NET_PROMISE_RECEIVE_H +#pragma once #include @@ -161,5 +160,3 @@ namespace brynet } } } - -#endif diff --git a/src/brynet/net/SSLHelper.h b/src/brynet/net/SSLHelper.h index 9cc1ebcf..b425ee25 100644 --- a/src/brynet/net/SSLHelper.h +++ b/src/brynet/net/SSLHelper.h @@ -1,5 +1,4 @@ -#ifndef BRYNET_NET_SSL_HELPER_H_ -#define BRYNET_NET_SSL_HELPER_H_ +#pragma once #include #include @@ -48,5 +47,3 @@ namespace brynet }; } } - -#endif diff --git a/src/brynet/net/Socket.h b/src/brynet/net/Socket.h index cc3bc0b7..044438d9 100644 --- a/src/brynet/net/Socket.h +++ b/src/brynet/net/Socket.h @@ -1,5 +1,4 @@ -#ifndef BRYNET_NET_SOCKET_H_ -#define BRYNET_NET_SOCKET_H_ +#pragma once #include #include @@ -59,7 +58,7 @@ namespace brynet class AcceptError : public std::runtime_error { public: - AcceptError(int errorCode) + explicit AcceptError(int errorCode) : std::runtime_error(std::to_string(errorCode)), mErrorCode(errorCode) @@ -103,6 +102,4 @@ namespace brynet friend class DataSocket; }; } -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/brynet/net/SocketLibFunction.h b/src/brynet/net/SocketLibFunction.h index 138fcad0..405239be 100644 --- a/src/brynet/net/SocketLibFunction.h +++ b/src/brynet/net/SocketLibFunction.h @@ -1,5 +1,4 @@ -#ifndef BRYNET_NET_SOCKETLIBFUNCTION_H_ -#define BRYNET_NET_SOCKETLIBFUNCTION_H_ +#pragma once #include #include @@ -29,5 +28,3 @@ namespace brynet } } } - -#endif diff --git a/src/brynet/net/SocketLibTypes.h b/src/brynet/net/SocketLibTypes.h index c02f6776..2c834f1f 100644 --- a/src/brynet/net/SocketLibTypes.h +++ b/src/brynet/net/SocketLibTypes.h @@ -1,5 +1,4 @@ -#ifndef DODO_NET_SOCKETLIBTYPES_H_ -#define DODO_NET_SOCKETLIBTYPES_H_ +#pragma once #include @@ -53,5 +52,3 @@ typedef int sock; typedef unsigned short int port; typedef unsigned long int ipaddress; #define IP_SIZE (20) - -#endif diff --git a/src/brynet/net/SyncConnector.h b/src/brynet/net/SyncConnector.h index 5a7a3519..14659ad6 100644 --- a/src/brynet/net/SyncConnector.h +++ b/src/brynet/net/SyncConnector.h @@ -1,5 +1,4 @@ -#ifndef BRYNET_NET_SYNC_CONNECT_H_ -#define BRYNET_NET_SYNC_CONNECT_H_ +#pragma once #include #include @@ -25,5 +24,3 @@ namespace brynet brynet::net::AsyncConnector::PTR asyncConnector = nullptr); } } - -#endif diff --git a/src/brynet/net/TCPService.h b/src/brynet/net/TCPService.h index 7dc68376..f9da93f2 100644 --- a/src/brynet/net/TCPService.h +++ b/src/brynet/net/TCPService.h @@ -1,5 +1,4 @@ -#ifndef BRYNET_NET_TCP_SERVICE_H_ -#define BRYNET_NET_TCP_SERVICE_H_ +#pragma once #include #include @@ -75,5 +74,3 @@ namespace brynet }; } } - -#endif diff --git a/src/brynet/net/fdset.h b/src/brynet/net/fdset.h index 08969c66..4d9b1a37 100644 --- a/src/brynet/net/fdset.h +++ b/src/brynet/net/fdset.h @@ -1,5 +1,4 @@ -#ifndef _BRYNET_NET_FDSET_INCLUDED_H -#define _BRYNET_NET_FDSET_INCLUDED_H +#pragma once #include #include @@ -30,5 +29,3 @@ bool ox_fdset_check(struct fdset_s* self, sock fd, enum CheckType type); #ifdef __cplusplus } #endif - -#endif diff --git a/src/brynet/net/http/HttpFormat.h b/src/brynet/net/http/HttpFormat.h index e29467da..46f52162 100644 --- a/src/brynet/net/http/HttpFormat.h +++ b/src/brynet/net/http/HttpFormat.h @@ -1,5 +1,4 @@ -#ifndef BRYNET_NET_HTTPFORMAT_H_ -#define BRYNET_NET_HTTPFORMAT_H_ +#pragma once #include #include @@ -20,7 +19,7 @@ namespace brynet void add(const std::string& k, const std::string& v) { - if (mParameter.size() > 0) + if (!mParameter.empty()) { mParameter += "&"; } @@ -222,6 +221,4 @@ namespace brynet std::string mBody; }; } -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/brynet/net/http/HttpParser.h b/src/brynet/net/http/HttpParser.h index facb4af6..ab85bc44 100644 --- a/src/brynet/net/http/HttpParser.h +++ b/src/brynet/net/http/HttpParser.h @@ -1,5 +1,4 @@ -#ifndef BRYNET_NET_HTTPPARSER_H_ -#define BRYNET_NET_HTTPPARSER_H_ +#pragma once #include #include @@ -86,6 +85,4 @@ namespace brynet friend class HttpService; }; } -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/brynet/net/http/HttpService.cpp b/src/brynet/net/http/HttpService.cpp index c02b4111..29275d0d 100644 --- a/src/brynet/net/http/HttpService.cpp +++ b/src/brynet/net/http/HttpService.cpp @@ -1,10 +1,5 @@ #include -#include -#include -#include -#include -#include #include #include @@ -28,7 +23,7 @@ const BrynetAny& HttpSession::getUD() const void HttpSession::setUD(BrynetAny ud) { - mUD = ud; + mUD = std::move(ud); } void HttpSession::setHttpCallback(HTTPPARSER_CALLBACK callback) @@ -99,7 +94,7 @@ HttpSession::PTR HttpSession::Create(DataSocket::PTR session) struct make_shared_enabler : public HttpSession { public: - make_shared_enabler(DataSocket::PTR session) : HttpSession(std::move(session)) + explicit make_shared_enabler(DataSocket::PTR session) : HttpSession(std::move(session)) {} }; return std::make_shared(std::move(session)); @@ -144,7 +139,8 @@ size_t HttpService::ProcessWebSocket(const char* buffer, // 如果当前fram的fin为false或者opcode为延续包,则将当前frame的payload添加到cache if (!isFin || opcode == WebSocketFormat::WebSocketFrameType::CONTINUATION_FRAME) { - cacheFrame += std::move(parseString); + cacheFrame += parseString; + parseString.clear(); } // 如果当前fram的fin为false,并且opcode不为延续包,则表示收到分段payload的第一个段(frame),需要缓存当前frame的opcode if (!isFin && opcode != WebSocketFormat::WebSocketFrameType::CONTINUATION_FRAME) diff --git a/src/brynet/net/http/HttpService.h b/src/brynet/net/http/HttpService.h index a2b49b7e..b015ba4b 100644 --- a/src/brynet/net/http/HttpService.h +++ b/src/brynet/net/http/HttpService.h @@ -1,5 +1,4 @@ -#ifndef BRYNET_NET_HTTPSERVICE_H_ -#define BRYNET_NET_HTTPSERVICE_H_ +#pragma once #include @@ -89,6 +88,4 @@ namespace brynet const HttpSession::PTR& httpSession); }; } -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/brynet/net/http/WebSocketFormat.h b/src/brynet/net/http/WebSocketFormat.h index ed97f3ed..00248c54 100644 --- a/src/brynet/net/http/WebSocketFormat.h +++ b/src/brynet/net/http/WebSocketFormat.h @@ -1,5 +1,4 @@ -#ifndef BRYNET_NET_WEBSOCKETFORMAT_H_ -#define BRYNET_NET_WEBSOCKETFORMAT_H_ +#pragma once #include #include @@ -47,7 +46,6 @@ namespace brynet return response; } - // TODO::Ƿֶγpayload( static bool wsFrameBuild(const char* payload, size_t payloadLen, std::string& frame, @@ -92,10 +90,10 @@ namespace brynet { frame[1] = ((uint8_t)frame[1]) | 0x80; uint8_t mask[4]; - for (size_t i = 0; i < sizeof(mask) / sizeof(mask[0]); i++) + for (auto& m : mask) { - mask[i] = rand(); - frame.push_back(mask[i]); + m = rand(); + frame.push_back(m); } frame.reserve(frame.size() + payloadLen); @@ -129,7 +127,7 @@ namespace brynet size_t& frameSize, bool& outfin) { - const unsigned char* buffer = (const unsigned char*)inbuffer; + const auto buffer = (const unsigned char*)inbuffer; if (bufferSize < 2) { @@ -220,7 +218,4 @@ namespace brynet } }; } -} - - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/brynet/timer/Timer.h b/src/brynet/timer/Timer.h index d28b6455..9e0f23da 100644 --- a/src/brynet/timer/Timer.h +++ b/src/brynet/timer/Timer.h @@ -1,5 +1,4 @@ -#ifndef BRYNET_TIMER_H_ -#define BRYNET_TIMER_H_ +#pragma once #include #include @@ -81,6 +80,4 @@ namespace brynet std::priority_queue, CompareTimer> mTimers; }; -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/brynet/utils/CPP_VERSION.h b/src/brynet/utils/CPP_VERSION.h index c3b0bb09..1399a610 100644 --- a/src/brynet/utils/CPP_VERSION.h +++ b/src/brynet/utils/CPP_VERSION.h @@ -1,5 +1,4 @@ -#ifndef _BRYNET_UTILS_CPP_VERSION_H -#define _BRYNET_UTILS_CPP_VERSION_H +#pragma once #if (__cplusplus >= 201103L || \ (defined(_MSC_VER) && _MSC_VER >= 1800)) @@ -14,6 +13,4 @@ #if (__cplusplus >= 201703L || \ (defined(_MSC_VER) && _MSC_VER >= 1910)) #define HAVE_LANG_CXX17 1 -#endif - #endif \ No newline at end of file diff --git a/src/brynet/utils/MsgQueue.h b/src/brynet/utils/MsgQueue.h index 72d79474..a36eeaff 100644 --- a/src/brynet/utils/MsgQueue.h +++ b/src/brynet/utils/MsgQueue.h @@ -1,5 +1,4 @@ -#ifndef BRYNET_MSGQUEUE_H_ -#define BRYNET_MSGQUEUE_H_ +#pragma once #include #include @@ -169,6 +168,4 @@ namespace brynet Container mSharedList; Container mReadList; }; -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/brynet/utils/NonCopyable.h b/src/brynet/utils/NonCopyable.h index fce9a517..febae1f2 100644 --- a/src/brynet/utils/NonCopyable.h +++ b/src/brynet/utils/NonCopyable.h @@ -1,17 +1,15 @@ -#ifndef BRYNET_NONCOPYABLE_H_ -#define BRYNET_NONCOPYABLE_H_ +#pragma once namespace brynet { class NonCopyable { + public: + NonCopyable(const NonCopyable&) = delete; + const NonCopyable& operator=(const NonCopyable&) = delete; + protected: NonCopyable() = default; ~NonCopyable() = default; - - NonCopyable(const NonCopyable&) = delete; - const NonCopyable& operator=(const NonCopyable&) = delete; }; -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/brynet/utils/Typeids.h b/src/brynet/utils/Typeids.h index c6a655ff..0386bb4c 100644 --- a/src/brynet/utils/Typeids.h +++ b/src/brynet/utils/Typeids.h @@ -1,5 +1,4 @@ -#ifndef BRYNET_TYPEIDS_H_ -#define BRYNET_TYPEIDS_H_ +#pragma once #include #include @@ -99,6 +98,4 @@ namespace brynet std::vector mValues; std::vector mIds; }; -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/brynet/utils/WaitGroup.h b/src/brynet/utils/WaitGroup.h index 9812b198..dc326e40 100644 --- a/src/brynet/utils/WaitGroup.h +++ b/src/brynet/utils/WaitGroup.h @@ -1,5 +1,4 @@ -#ifndef _WAIT_GROUP_H -#define _WAIT_GROUP_H +#pragma once #include #include @@ -56,8 +55,7 @@ namespace brynet { } - virtual ~WaitGroup() - {} + virtual ~WaitGroup() = default; private: std::mutex mMutex; @@ -65,5 +63,3 @@ namespace brynet std::condition_variable mCond; }; } - -#endif diff --git a/src/brynet/utils/app_status.h b/src/brynet/utils/app_status.h index b7ded29b..05975616 100644 --- a/src/brynet/utils/app_status.h +++ b/src/brynet/utils/app_status.h @@ -1,7 +1,4 @@ -#ifndef _APP_STATUS_H -#define _APP_STATUS_H - -/* ״̬ */ +#pragma once #include @@ -17,6 +14,4 @@ int app_kbhit(void); #ifdef __cplusplus } -#endif - #endif \ No newline at end of file diff --git a/src/brynet/utils/array.h b/src/brynet/utils/array.h index 6f2f9400..d30ff42f 100644 --- a/src/brynet/utils/array.h +++ b/src/brynet/utils/array.h @@ -1,5 +1,4 @@ -#ifndef _ARRAY_H_INCLUDED_ -#define _ARRAY_H_INCLUDED_ +#pragma once #include @@ -19,5 +18,3 @@ int ox_array_num(const struct array_s* self); #ifdef __cplusplus } #endif - -#endif diff --git a/src/brynet/utils/buffer.h b/src/brynet/utils/buffer.h index 423fa759..1ee7f72a 100644 --- a/src/brynet/utils/buffer.h +++ b/src/brynet/utils/buffer.h @@ -1,5 +1,4 @@ -#ifndef _BUFFER_H_INCLUDED -#define _BUFFER_H_INCLUDED +#pragma once #ifdef __cplusplus extern "C" { @@ -33,5 +32,3 @@ bool ox_buffer_write(struct buffer_s* self, const char* data, size_t len); #ifdef __cplusplus } #endif - -#endif diff --git a/src/brynet/utils/packet.h b/src/brynet/utils/packet.h index 98bac4f6..633b2cca 100644 --- a/src/brynet/utils/packet.h +++ b/src/brynet/utils/packet.h @@ -1,5 +1,4 @@ -#ifndef _BRYNET_UTILS_PACKET_H -#define _BRYNET_UTILS_PACKET_H +#pragma once #include #include @@ -282,7 +281,7 @@ class BasePacketWriter } private: - // Ϊ˱ֱ<<ûԽֽBUG,Ϊ˺Ϊ˽ + // 为了避免直接<<导致没有指定字节序导致隐藏BUG,因为此函数设置为私有 template BasePacketWriter & operator << (const T& v) { @@ -312,7 +311,7 @@ class BasePacketWriter return; } - char* newBuffer = (char*)malloc(mMaxLen + len); + auto newBuffer = (char*)malloc(mMaxLen + len); if (newBuffer == nullptr) { return; @@ -353,9 +352,7 @@ class BasePacketReader mBuffer = buffer; } - virtual ~BasePacketReader() - { - } + virtual ~BasePacketReader() = default; size_t getLeft() const { @@ -448,7 +445,7 @@ class BasePacketReader } private: - // Ϊ˱ֱread(uintXXX)ûָֽBUG,Ϊ˺Ϊ˽ + // 为了避免直接read(uintXXX)导致没有指定字节序造成隐患BUG,因为此函数设置为私有 template void read(T& value) { @@ -478,7 +475,7 @@ template class AutoMallocPacket : public BasePacketWriter { public: - AutoMallocPacket(bool useBigEndian = true, + explicit AutoMallocPacket(bool useBigEndian = true, bool isAutoMalloc = false) : BasePacketWriter(mData, SIZE, useBigEndian, isAutoMalloc) @@ -488,5 +485,3 @@ class AutoMallocPacket : public BasePacketWriter }; typedef AutoMallocPacket<32 * 1024> BigPacket; - -#endif diff --git a/src/brynet/utils/stack.h b/src/brynet/utils/stack.h index 34e83d1c..4c042e12 100644 --- a/src/brynet/utils/stack.h +++ b/src/brynet/utils/stack.h @@ -1,5 +1,4 @@ -#ifndef _STACK_H_INCLUDED_ -#define _STACK_H_INCLUDED_ +#pragma once #include @@ -24,5 +23,3 @@ int ox_stack_num(struct stack_s* self); #ifdef __cplusplus } #endif - -#endif