This commit is contained in:
quackerd 2023-03-13 09:49:28 +01:00
parent 1f8a006678
commit e97dd8ee9e
13 changed files with 70 additions and 69 deletions

View File

@ -9,8 +9,7 @@ pkg_check_modules(bsock REQUIRED bsock)
set(CXXFLAGS -Wall -Wextra -Werror -std=c++20 -O3 -g)
set(CFLAGS -Wall -Wextra -Werror -std=c2x -O3 -g)
add_library(common OBJECT ${CMAKE_CURRENT_SOURCE_DIR}/common/io.cc
${CMAKE_CURRENT_SOURCE_DIR}/common/logger.cc)
add_library(common OBJECT ${CMAKE_CURRENT_SOURCE_DIR}/common/io.cc)
target_link_directories(common PRIVATE ${bsock_LIBRARY_DIRS})
target_link_libraries(common ${bsock_LIBRARIES})
target_compile_options(common PRIVATE ${CXXFLAGS})

View File

@ -6,8 +6,8 @@
#include <bsock/bsock.h>
#include "logger.h"
#include "msg.h"
#include "io.h"
#include "msg.hh"
#include "io.hh"
#include <algorithm>

View File

@ -1,15 +0,0 @@
#include <logger.h>
static unsigned int verbosity = 0;
void
logger_set_verbosity(unsigned int v)
{
verbosity = v;
}
unsigned int
logger_get_verbosity(void)
{
return verbosity;
}

View File

@ -1,6 +1,6 @@
#include <sys/endian.h>
#include "dmsg.h"
#include "io.h"
#include "dmsg.hh"
#include "io.hh"
#include <cstdlib>
#include <netinet/in.h>

View File

@ -19,12 +19,12 @@
#include <semaphore.h>
#include <unistd.h>
#include "dmsg.h"
#include "generator.h"
#include "io.h"
#include "dmsg.hh"
#include "generator.hh"
#include "io.hh"
#include "logger.h"
#include "mod.h"
#include "msg.h"
#include "msg.hh"
#include "util.h"
#include <atomic>
@ -40,6 +40,8 @@
#include <unordered_map>
#include <vector>
LOGGER_VAR_DECL;
static constexpr int MAX_MOD_ARGS = 32;
static constexpr int MAX_MOD_ARG_LEN = 128;
static constexpr int MAX_SLAVES = 32;

View File

@ -1,5 +1,5 @@
// modified from mutilate
#include "generator.h"
#include "generator.hh"
Generator* createFacebookKey() { return new GEV(30.7984, 8.20449, 0.078688); }

View File

@ -3,34 +3,52 @@
#ifdef __cplusplus
extern "C" {
#define LOGGER_VAR_DECL extern "C" { unsigned int logger_verbosity = 0; }
#else
#define LOGGER_VAR_DECL unsigned int logger_verbosity = 0
#endif
void logger_set_verbosity(unsigned int v);
unsigned int logger_get_verbosity(void);
extern unsigned int logger_verbosity;
static inline void
logger_set_verbosity(unsigned int v)
{
logger_verbosity = v;
}
static inline unsigned int
logger_get_verbosity(void)
{
return logger_verbosity;
}
#define DEBUG_VERBOSITY (2)
#define INFO_VERBOSITY (1)
#define W(fmt, ...) do { \
fprintf(stderr, "[WARNING] %s: " fmt, __func__, ##__VA_ARGS__); \
} while(0)
#define W(fmt, ...) \
do { \
fprintf(stderr, "[WARNING] %s: " fmt, __func__, ##__VA_ARGS__); \
} while (0)
#define E(fmt, ...) do { \
fprintf(stderr, "[ERROR] %s: " fmt, __func__, ##__VA_ARGS__); \
exit(1); \
} while(0)
#define E(fmt, ...) \
do { \
fprintf(stderr, "[ERROR] %s: " fmt, __func__, ##__VA_ARGS__); \
exit(1); \
} while (0)
#define V(fmt, ...) do { \
if (logger_get_verbosity() >= INFO_VERBOSITY) { \
fprintf(stdout, "[INFO] %s: " fmt, __func__, ##__VA_ARGS__); \
} \
} while(0)
#define V(fmt, ...) \
do { \
if (logger_get_verbosity() >= INFO_VERBOSITY) { \
fprintf(stdout, "[INFO] %s: " fmt, __func__, ##__VA_ARGS__); \
} \
} while (0)
#define D(fmt, ...) do { \
if (logger_get_verbosity() >= DEBUG_VERBOSITY) { \
fprintf(stdout, "[DEBUG] %s: " fmt, __func__, ##__VA_ARGS__); \
} \
} while(0)
#define D(fmt, ...) \
do { \
if (logger_get_verbosity() >= DEBUG_VERBOSITY) { \
fprintf(stdout, "[DEBUG] %s: " fmt, __func__, ##__VA_ARGS__); \
} \
} while (0)
#ifdef __cplusplus
}

View File

@ -1,22 +0,0 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
// Max 16MB per message
struct ppd_msg {
uint32_t size;
char data[0];
} __attribute__((packed));
#define PPD_MSG_MAX_SZ (1024 * 16 * 1024)
#define PPD_MSG_HDR_SZ (offsetof(struct ppd_msg, data))
_Static_assert(PPD_MSG_HDR_SZ == sizeof(struct ppd_msg));
#define PPD_MSG_MAX_DATA_SZ (PPD_MSG_MAX_SZ - PPD_MSG_HDR_SZ)
#ifdef __cplusplus
}
#endif

15
include/msg.hh Normal file
View File

@ -0,0 +1,15 @@
#pragma once
#include <cstdint>
// Max 16MB per message
struct ppd_msg {
uint32_t size;
char data[0];
} __attribute__((packed));
static constexpr int PPD_MSG_MAX_SZ = (1024 * 16 * 1024);
static constexpr int PPD_MSG_HDR_SZ = offsetof(struct ppd_msg, data);
static_assert(PPD_MSG_HDR_SZ == sizeof(struct ppd_msg));
static constexpr int PPD_MSG_MAX_DATA_SZ = (PPD_MSG_MAX_SZ - PPD_MSG_HDR_SZ);

View File

@ -19,9 +19,9 @@
#include "logger.h"
#include "mod.h"
#include "msg.h"
#include "msg.hh"
#include "util.h"
#include "io.h"
#include "io.hh"
#include <cerrno>
#include <csignal>
@ -34,6 +34,10 @@
#include <unordered_map>
#include <vector>
extern "C" {
LOGGER_VAR_DECL;
}
static constexpr int NEVENT = 64;
static constexpr int SOCK_BACKLOG = 10000;
static constexpr int SINGLE_LEGACY = -1;