From 07a7854fa01245ad5f07c257d887ac55a9f1ed30 Mon Sep 17 00:00:00 2001 From: Lior Lahav Date: Sun, 31 May 2020 02:22:24 +0300 Subject: [PATCH] fixed warnings and packet.hpp encoding --- examples/BroadCastClient.cpp | 2 +- include/brynet/base/AppStatus.hpp | 2 +- include/brynet/base/Array.hpp | 2 +- include/brynet/base/Bool.hpp | 4 ++++ include/brynet/base/Buffer.hpp | 2 +- include/brynet/base/Packet.hpp | 12 ++++++++++-- include/brynet/base/Stack.hpp | 8 ++++---- include/brynet/base/endian/Endian.hpp | 2 +- include/brynet/net/Poller.hpp | 2 +- 9 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 include/brynet/base/Bool.hpp diff --git a/examples/BroadCastClient.cpp b/examples/BroadCastClient.cpp index ed887c74..16047e51 100644 --- a/examples/BroadCastClient.cpp +++ b/examples/BroadCastClient.cpp @@ -51,7 +51,7 @@ int main(int argc, char** argv) auto enterCallback = [packetLen](TcpConnection::Ptr datasSocket) { static_assert(sizeof(datasSocket.get()) <= sizeof(int64_t), ""); - auto HEAD_LEN = sizeof(uint32_t) + sizeof(uint16_t); + uint32_t HEAD_LEN = sizeof(uint32_t) + sizeof(uint16_t); std::shared_ptr sp = std::make_shared(1); sp->writeUINT32(HEAD_LEN + sizeof(int64_t) + packetLen); diff --git a/include/brynet/base/AppStatus.hpp b/include/brynet/base/AppStatus.hpp index 88867fc4..e5a3948e 100644 --- a/include/brynet/base/AppStatus.hpp +++ b/include/brynet/base/AppStatus.hpp @@ -1,10 +1,10 @@ #pragma once -#include #include #include #include +#include #ifdef BRYNET_PLATFORM_WINDOWS #include diff --git a/include/brynet/base/Array.hpp b/include/brynet/base/Array.hpp index 0b0624f0..7a9cb12a 100644 --- a/include/brynet/base/Array.hpp +++ b/include/brynet/base/Array.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include #include diff --git a/include/brynet/base/Bool.hpp b/include/brynet/base/Bool.hpp new file mode 100644 index 00000000..b88c31b3 --- /dev/null +++ b/include/brynet/base/Bool.hpp @@ -0,0 +1,4 @@ +#include "CPP_VERSION.hpp" +#ifndef BRYNET_HAVE_LANG_CXX17 + #include +#endif \ No newline at end of file diff --git a/include/brynet/base/Buffer.hpp b/include/brynet/base/Buffer.hpp index f1ed8b30..19573a87 100644 --- a/include/brynet/base/Buffer.hpp +++ b/include/brynet/base/Buffer.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include #include diff --git a/include/brynet/base/Packet.hpp b/include/brynet/base/Packet.hpp index a836dcad..f0706e0b 100644 --- a/include/brynet/base/Packet.hpp +++ b/include/brynet/base/Packet.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include @@ -359,9 +359,17 @@ namespace brynet { namespace base { void read(T& value) { static_assert(std::is_same::type>::value, - "T must a nomal type"); + "T must be a nomal type"); +#ifdef BRYNET_HAVE_LANG_CXX17 + static_assert(std::is_trivially_copyable_v, + "T must be trivially copyable"); + + static_assert(std::is_standard_layout_v, + "T must have a standard layout"); +#else static_assert(std::is_pod::value, "T must a pod type"); +#endif if ((mPos + sizeof(value)) > mMaxLen) { diff --git a/include/brynet/base/Stack.hpp b/include/brynet/base/Stack.hpp index 339bad32..b541440f 100644 --- a/include/brynet/base/Stack.hpp +++ b/include/brynet/base/Stack.hpp @@ -1,12 +1,12 @@ #pragma once -#include #include #include #include #include #include +#include namespace brynet { namespace base { @@ -16,8 +16,8 @@ namespace brynet { namespace base { size_t element_size; size_t element_num; - size_t front; /* 栈底 */ - size_t num; /* 栈有效元素大小 */ + size_t front; /* TODO: add comment */ + size_t num; /* TODO: add comment */ }; static void stack_delete(struct stack_s* self) @@ -115,7 +115,7 @@ namespace brynet { namespace base { return (self->num == self->element_num); } - /* stack的stack_push会在空间不足的时候自动增长(通过stack_increase) */ + /* TODO: fix comment */ static bool stack_push(struct stack_s* self, const void* data) { if (stack_isfull(self)) diff --git a/include/brynet/base/endian/Endian.hpp b/include/brynet/base/endian/Endian.hpp index c797e83d..2f2df51f 100644 --- a/include/brynet/base/endian/Endian.hpp +++ b/include/brynet/base/endian/Endian.hpp @@ -3,9 +3,9 @@ #include #include #include -#include #include +#include #include #ifdef BRYNET_PLATFORM_LINUX diff --git a/include/brynet/net/Poller.hpp b/include/brynet/net/Poller.hpp index 820a9410..b61c86b0 100644 --- a/include/brynet/net/Poller.hpp +++ b/include/brynet/net/Poller.hpp @@ -3,11 +3,11 @@ #include #include #include -#include #include #include #include +#include #if defined BRYNET_PLATFORM_LINUX || defined BRYNET_PLATFORM_DARWIN #include