-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.h
More file actions
75 lines (63 loc) · 1.73 KB
/
Copy pathserver.h
File metadata and controls
75 lines (63 loc) · 1.73 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
71
72
73
74
75
/*
* Copyright (c) 2024, Gutanu Tiberiu-Mihnea <tiberiugutanu@gmail.com>
*/
#ifndef SERVER_H
#define SERVER_H
#include "utils.h"
#include "constants.h"
#include "lru_cache.h"
#define TASK_QUEUE_SIZE 1000
#define MAX_LOG_LENGTH 1000
#define MAX_RESPONSE_LENGTH 4096
typedef struct queue_t queue_t;
struct queue_t
{
unsigned int max_size;
unsigned int size;
unsigned int data_size;
unsigned int read_idx;
unsigned int write_idx;
void **buff;
};
typedef struct server {
lru_cache *cache;
queue_t *task_queue;
lru_cache *local_db;
unsigned int server_id;
unsigned int hash;
struct server *original_server;
} 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);
#endif /* SERVER_H */