-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.h
More file actions
70 lines (58 loc) · 1.72 KB
/
server.h
File metadata and controls
70 lines (58 loc) · 1.72 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Copyright (c) 2024, Andrei Rusanescu <andreirusanescu154gmail.com>
*/
#ifndef SERVER_H
#define SERVER_H
#include "utils.h"
#include "constants.h"
#include "lru_cache.h"
#include "queue.h"
#define TASK_QUEUE_SIZE 1000
#define MAX_LOG_LENGTH 1000
#define MAX_RESPONSE_LENGTH 4096
typedef struct server {
lru_cache *cache;
queue_t *queue;
hashtable_t *data_base;
int id;
/* used when the load balancer uses replicas,
* maps the index of the replica to its hash */
unsigned int repid_to_hash[3];
} server;
typedef struct request {
request_type type;
char *doc_name;
char *doc_content;
} request;
typedef struct response {
char *server_log;
char *server_response;
int server_id;
} response;
server *init_server(unsigned int cache_size);
/**
* @brief Should deallocate completely the memory used by server,
* taking care of deallocating the elements in the queue, if any,
* without executing the tasks
*/
void free_server(server **s);
/**
* server_handle_request() - Receives a request from the load balancer
* and processes it according to the request type
*
* @param s: Server which processes the request.
* @param req: Request to be processed.
*
* @return response*: Response of the requested operation, which will
* then be printed in main.
*
* @brief Based on the type of request, should call the appropriate
* solver, and should execute the tasks from queue if needed (in
* this case, after executing each task, PRINT_RESPONSE should
* be called).
*/
response
*server_handle_request(server *s, request *req, unsigned int id);
/* Executes the requests for the server `s` with id `id` */
void execute_queue(server *s, unsigned int id);
#endif /* SERVER_H */