-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.h
49 lines (40 loc) · 1.79 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Copyright (c) 2024, <>
*/
#ifndef UTILS_H
#define UTILS_H
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "constants.h"
#define DIE(assertion, call_description) \
do { \
if (assertion) { \
fprintf(stderr, "(%s, %d): ", __FILE__, __LINE__); \
perror(call_description); \
exit(errno); \
} \
} while (0)
#define PRINT_RESPONSE(response_ptr) ({ \
if (response_ptr) { \
printf(GENERIC_MSG, response_ptr->server_id, \
response_ptr->server_response, response_ptr->server_id, \
response_ptr->server_log); \
free(response_ptr->server_response); \
free(response_ptr->server_log); \
free(response_ptr);} \
})
/**
* @brief Should be used as hash function for server IDs,
* to find server's position on the hash ring
*/
unsigned int hash_uint(void *key);
/**
* @brief Should be used as hash function for document names,
* to find the proper server on the hash ring
*/
unsigned int hash_string(void *key);
char *get_request_type_str(request_type req_type);
request_type get_request_type(char *request_type_str);
#endif /* UTILS_H */