Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed warnings and packet.hpp encoding #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/BroadCastClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<BigPacket> sp = std::make_shared<BigPacket>(1);
sp->writeUINT32(HEAD_LEN + sizeof(int64_t) + packetLen);
Expand Down
2 changes: 1 addition & 1 deletion include/brynet/base/AppStatus.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once

#include <cstdbool>
#include <cstdio>
#include <signal.h>

#include <brynet/base/Platform.hpp>
#include <brynet/base/Bool.hpp>

#ifdef BRYNET_PLATFORM_WINDOWS
#include <conio.h>
Expand Down
2 changes: 1 addition & 1 deletion include/brynet/base/Array.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <cstdbool>
#include <brynet/base/Bool.hpp>
#include <cstring>
#include <cstdlib>
#include <cassert>
Expand Down
4 changes: 4 additions & 0 deletions include/brynet/base/Bool.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "CPP_VERSION.hpp"
#ifndef BRYNET_HAVE_LANG_CXX17
#include <cstdbool>
#endif
2 changes: 1 addition & 1 deletion include/brynet/base/Buffer.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <cstdbool>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请问是为了什么警告呢? 我看 https://en.cppreference.com/w/cpp/header/cstdbool, 反而C++17时,不需要cstdbool

#include <brynet/base/Bool.hpp>
#include <cstdint>
#include <cstdlib>
#include <cstring>
Expand Down
12 changes: 10 additions & 2 deletions include/brynet/base/Packet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <cstdint>
#include <cassert>
#include <cstdbool>
#include <brynet/base/Bool.hpp>
#include <cstring>
#include <string>

Expand Down Expand Up @@ -359,9 +359,17 @@ namespace brynet { namespace base {
void read(T& value)
{
static_assert(std::is_same<T, typename std::remove_pointer<T>::type>::value,
"T must a nomal type");
"T must be a nomal type");
#ifdef BRYNET_HAVE_LANG_CXX17
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

高版本的时候不需要判断pod 了么

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not removed, it has been fixed.
The word 'be' has been added for a proper grammer

static_assert(std::is_trivially_copyable_v<T>,
"T must be trivially copyable");

static_assert(std::is_standard_layout_v<T>,
"T must have a standard layout");
#else
static_assert(std::is_pod<T>::value,
"T must a pod type");
#endif

if ((mPos + sizeof(value)) > mMaxLen)
{
Expand Down
8 changes: 4 additions & 4 deletions include/brynet/base/Stack.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#pragma once

#include <cstdbool>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdint>

#include <brynet/base/Array.hpp>
#include <brynet/base/Bool.hpp>

namespace brynet { namespace base {

Expand All @@ -16,8 +16,8 @@ namespace brynet { namespace base {
size_t element_size;

size_t element_num;
size_t front; /* ջ�� */
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请问为何注释去掉了呢。

size_t num; /* ջ��ЧԪ�ش�С */
size_t front; /* TODO: add comment */
size_t num; /* TODO: add comment */
};

static void stack_delete(struct stack_s* self)
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion include/brynet/base/endian/Endian.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include <cstdint>
#include <cassert>
#include <cstring>
#include <cstdbool>
#include <cstring>

#include <brynet/base/Bool.hpp>
#include <brynet/net/SocketLibTypes.hpp>

#ifdef BRYNET_PLATFORM_LINUX
Expand Down
2 changes: 1 addition & 1 deletion include/brynet/net/Poller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#include <cstdlib>
#include <cstdio>
#include <cassert>
#include <cstdbool>
#include <string>

#include <brynet/net/SocketLibTypes.hpp>
#include <brynet/base/Stack.hpp>
#include <brynet/base/Bool.hpp>

#if defined BRYNET_PLATFORM_LINUX || defined BRYNET_PLATFORM_DARWIN
#include <poll.h>
Expand Down