-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.h
71 lines (57 loc) · 2.46 KB
/
server.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef SERVERTHREADS_H
#define SERVERTHREADS_H
#include "common.h"
//POSIX library for threads
#include <pthread.h>
#include <unistd.h>
#include <stdlib.h>
#include <map>
class ServerThreads {
public:
ServerThreads();
~ServerThreads();
static bool BankersSimulation(int *request);
void readConfigurationFile(const char *fileName);
void createAndStart();
void initializationOfDataStructures();
static void processRequest(int threadID, int socketFD);
void printAndSaveResults(const char* fileName);
private:
//Internal server parameters
int numServerThreads; // Number of different threads that the server will use to accept connections
int backlog; // Maximum number of pending connections for each thread
int port; // The port that the server will listen to
static int numResources; // Number of diferent resources
static int numClients; // Number of different clients (threads) that will connect to the server
static int numRequestsPerClient; // Number of requests to be received by each client
bool initDataProvided;
/**
* Vérouille!
*/
static pthread_mutex_t available_lock;
static pthread_mutex_t accept_lock;
static int sock; // Main server Socket File Descriptor
static int timeout; // Maximum number of seconds that the server program will run
static int requestProcessed; // Number of request already processed
static int totalNumRequests; // Total number of request to be processed (numClients*numRequestPerClient)
static bool *ClientsRunning;
//Banker's Algorithm data structures (see the book for further details)
static int *Available;
static int **Max;
static int **Allocation;
static int **Need;
// Results variables
static int countAccepted; // Result counter for total acepted requests
static int countOnWait; // Result counter for total request denied and put to wait
static int countInvalid; // Result counter for total invalid requests
static int countClientsDispatched; // Result counter for total clients correctly finished
//Server threads
int *realID; // Real ID of each thread (from 0 to numServerThreads-1)
pthread_t *pt_tid; // The thread identifier
pthread_attr_t *pt_attr; // Set of thread identifiers
//Function that will be called by every server thread
static void *threadCode(void * param);
//Function to write the Max values to a file
void writeMaxToFile();
};
#endif // SERVERTHREADS_H