Skip to content

Commit

Permalink
Applied formatting according to clangd, fixed cmakelists
Browse files Browse the repository at this point in the history
  • Loading branch information
codepr committed Dec 12, 2024
1 parent 8ce19a3 commit 09362ee
Show file tree
Hide file tree
Showing 16 changed files with 1,147 additions and 950 deletions.
12 changes: 12 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
IndentWidth: 4
BreakBeforeBraces: Custom
BraceWrapping:
AfterFunction: true
AlignConsecutiveMacros:
Enabled: true
AcrossEmptyLines: true
AcrossComments: true
AlignConsecutiveAssignments:
Enabled: true
AcrossEmptyLines: true
AcrossComments: true
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ set(LICENSE "BSD2 license")
add_executable(llb ${SOURCES} include/llb_internal.h)

if (APPLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/usr/local/opt/openssl/include")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/local/opt/openssl/include")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/opt/openssl/lib")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/opt/homebrew/opt/openssl@3/include")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/opt/homebrew/opt/openssl@3/include")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/opt/homebrew/opt/openssl@3/lib")
endif (APPLE)

if (DEBUG)
Expand Down
42 changes: 22 additions & 20 deletions include/llb_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@
#ifndef LLB_INTERNAL
#define LLB_INTERNAL

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>

#define RANDOM(A,B) A + rand()/(RAND_MAX/(B - A))
#define RANDOM(A, B) A + rand() / (RAND_MAX / (B - A))

/* Load-balancing mode */
#define LLB_TCP_MODE 0
#define LLB_HTTP_MODE 1
#define LLB_TCP_MODE 0
#define LLB_HTTP_MODE 1

#define LLB_SUCCESS 0
#define LLB_FAILURE -1
#define LLB_SUCCESS 0
#define LLB_FAILURE -1

/* Load-balancing algorithms */
#define ROUND_ROBIN 0
Expand All @@ -50,46 +50,48 @@
#define LEASTTRAFFIC 4
#define WEIGHTED_ROUND_ROBIN 5

static inline void *llb_malloc(size_t size) {
static inline void *llb_malloc(size_t size)
{
void *ptr = malloc(size);
if (!ptr && size != 0) {
fprintf(stderr, "[%s:%ul] Out of memory (%lu bytes)\n",
__FILE__, __LINE__, size);
fprintf(stderr, "[%s:%ul] Out of memory (%lu bytes)\n", __FILE__,
__LINE__, size);
exit(EXIT_FAILURE);
}
return ptr;
}

static inline void *llb_calloc(size_t n, size_t size) {
static inline void *llb_calloc(size_t n, size_t size)
{
void *ptr = calloc(n, size);
if (!ptr && size != 0 && n != 0) {
fprintf(stderr, "[%s:%ul] Out of memory (%lu bytes)\n",
__FILE__, __LINE__, size);
fprintf(stderr, "[%s:%ul] Out of memory (%lu bytes)\n", __FILE__,
__LINE__, size);
exit(EXIT_FAILURE);
}
return ptr;
}

static inline void *llb_realloc(void *ptr, size_t size) {
static inline void *llb_realloc(void *ptr, size_t size)
{
assert(ptr && size > 0);
void *new_ptr = realloc(ptr, size);
if (!new_ptr && size != 0) {
fprintf(stderr, "[%s:%ul] Out of memory (%lu bytes)\n",
__FILE__, __LINE__, size);
fprintf(stderr, "[%s:%ul] Out of memory (%lu bytes)\n", __FILE__,
__LINE__, size);
exit(EXIT_FAILURE);
}
return new_ptr;
}

static inline void llb_free(void *ptr) {
free(ptr);
}
static inline void llb_free(void *ptr) { free(ptr); }

/* D. J. Bernstein hash function */
static inline size_t djb_hash(const char *str) {
static inline size_t djb_hash(const char *str)
{
size_t hash = 5381;
while (*str)
hash = 33 * hash ^ (unsigned char) *str++;
hash = 33 * hash ^ (unsigned char)*str++;
return hash;
}

Expand Down
Loading

0 comments on commit 09362ee

Please sign in to comment.