Skip to content

Commit

Permalink
refactor: use uint8_t instead of char & make method const
Browse files Browse the repository at this point in the history
  • Loading branch information
MilkeeyCat committed Mar 11, 2024
1 parent 42f5fb1 commit 50f871c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
21 changes: 20 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ jobs:
# sudo apt-get upgrade -y
sudo apt-get install pkg-config cmake ninja-build libfreetype6-dev libnotify-dev libsdl2-dev libsqlite3-dev libvulkan-dev glslang-tools spirv-tools libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libx264-dev libpng-dev valgrind gcovr -y
# high iq solution
git clone https://github.com/protocolbuffers/protobuf.git --branch v3.21.12 --single-branch
cd protobuf
git submodule update --init --recursive
Expand Down Expand Up @@ -106,6 +105,26 @@ jobs:
echo /Library/Frameworks/Python.framework/Versions/3.12/bin >> $GITHUB_PATH
sudo rm -rf /Library/Developer/CommandLineTools
git clone https://github.com/protocolbuffers/protobuf.git --branch v3.21.12 --single-branch
cd protobuf
git submodule update --init --recursive
mkdir build
cd build
cmake ..
sudo make install
- name: Prepare Windows
if: contains(matrix.os, 'windows')
run: |
git clone https://github.com/protocolbuffers/protobuf.git --branch v3.21.12 --single-branch
cd protobuf
git submodule update --init --recursive
mkdir build
cd build
cmake ..
#cmake --build .
cmake -E env CXXFLAGS=/WX LDFLAGS=/WX cmake -A x64 -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG=. --config Release --target install ..
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2

Expand Down
17 changes: 9 additions & 8 deletions src/engine/server/ddts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "base/system.h"
#include <arpa/inet.h>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <fcntl.h>
Expand All @@ -18,11 +19,11 @@
const int PORT = 42069;
const std::string HOST = "127.0.0.1";

const std::string SHM_NAME = "/ddts2";
const std::string SHM_NAME = "/ddts";
const size_t SHM_SIZE = 10;

CDDTS::CDDTS(unsigned int id, unsigned int happeningId) :
m_HappeningId(happeningId), m_Id(id), m_Shutdown(false)
CDDTS::CDDTS(unsigned int Id, unsigned int HappeningId) :
m_HappeningId(HappeningId), m_Id(Id), m_Shutdown(false)
{
fd = shm_open(SHM_NAME.c_str(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IXUSR);

Expand All @@ -40,7 +41,7 @@ CDDTS::CDDTS(unsigned int id, unsigned int happeningId) :

bool CDDTS::CheckShutdownSignal()
{
char *mem = static_cast<char *>(sharedMemory);
uint8_t *mem = static_cast<uint8_t *>(sharedMemory);

if(mem[m_Id] == 1)
{
Expand All @@ -51,7 +52,7 @@ bool CDDTS::CheckShutdownSignal()
return false;
}

void CDDTS::Shutdown()
void CDDTS::Shutdown() const
{
if(!m_Shutdown)
{
Expand All @@ -71,19 +72,19 @@ void CDDTS::Shutdown()
request.set_origin(::Origin::DDNET);

const size_t size = request.ByteSizeLong();
char *bytes = new char[size];
uint8_t *bytes = new uint8_t[size];

request.SerializeToArray(bytes, size);

send(sock, bytes, size, 0);

std::vector<char> gottem(1024);
std::vector<uint8_t> gottem(1024);

// wait for the response owo. works for now
recv(sock, gottem.data(), gottem.size(), 0);
}

char *mem = static_cast<char *>(sharedMemory);
uint8_t *mem = static_cast<uint8_t *>(sharedMemory);
mem[m_Id] = 0;

munmap(sharedMemory, SHM_SIZE);
Expand Down
4 changes: 2 additions & 2 deletions src/engine/server/ddts.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class CDDTS
unsigned int m_Id;
bool m_Shutdown;

CDDTS(unsigned int id, unsigned int happeningId);
CDDTS(unsigned int Id, unsigned int HappeningId);
bool CheckShutdownSignal();
void Shutdown();
void Shutdown() const;
};

0 comments on commit 50f871c

Please sign in to comment.