-
Notifications
You must be signed in to change notification settings - Fork 0
/
stdafx.h
88 lines (68 loc) · 1.79 KB
/
stdafx.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef STDAFX_H
#define STDAFX_H
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <list>
#include <unistd.h>
#include <time.h>
#include <fcntl.h>
#define MAX_NODES 64
#define PORT_RANGE_START 1126
#define MAX_BUFFER_SIZE 1024
/***************************************
* GLOBAL VARIABLE Declaration
* *************************************/
static int sockSend[MAX_NODES];
static int sockReceive[MAX_NODES];
static int portNums[MAX_NODES];
static int node_num, thread_num;
static int msgNum;
static pthread_t enThread;
static pthread_mutex_t fileMutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t dataMutex = PTHREAD_MUTEX_INITIALIZER;
/***************************************
* ENUM Declaration
* *************************************/
typedef enum
{
CS_INITMUTEXREQUEST,
CS_REQUEST,
CS_ACK,
CS_COMPLETION,
CS_EXIT
}MessageType;
typedef struct
{
MessageType msgType;
int senderId;
int receiverId;
int timeStamp[MAX_NODES];
}MessagePacket;
typedef struct
{
int nodeID; // Request node
int timeStamp[MAX_NODES]; // Request timestamp
}QueueData;
/***************************************
* FUNCTION Declaration
* *************************************/
void* serverNode( void* arg);
void* clientNode( void* arg);
int serverInit(int port);
int clientInit(char *serv_addr, int port);
MessagePacket messageToPkt(char* msg);
int sendPktToNode(MessagePacket msgPkt, int receriverId);
int insertIntoQueue(std::list<QueueData> &queue, QueueData &enQueue);
#endif