-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.h
executable file
·109 lines (87 loc) · 1.92 KB
/
lib.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <sys/types.h> /* See NOTES */
#include <sys/socket.h>
#include <netdb.h>
#include "string.h"
#include "errno.h"
#include "stdio.h"
#include "stdlib.h"
#include <unistd.h>
#include <fcntl.h>
#include <sys/epoll.h>
#include <signal.h>
#include <time.h>
#include <string>
#include "Buffer.h"
#ifndef __LIB__H
#define __LIB__H
enum {
JOIN=0,
UNJOIN,
CLI_JOIN,
TM_CONTROL_MESSAGE,
CLI_CONTROL_MESSAGE
};
enum{
TASK_TYPE_MAP,
TASK_TYPE_REDUCE
};
enum{
IE_TYPE_TASK_TYPE,
IE_TYPE_INPUT_FILE,
IE_TYPE_INPUT_FILE2,
IE_TYPE_OUTPUT_FILE,
IE_TYPE_DELIMITER
};
enum{
CLI_CONTROL_START_TASK,
CLI_CONTROL_STOP_TASK,
CLI_CONTROL_TASK_COMPLETE,
CLI_CONTROL_SHOW_GROUPS,
CLI_CONTROL_GROUPS
};
struct Msg
{
uint16_t reqType;
uint16_t grpId;
};
struct TaskControlMessage{
uint16_t reqType;
uint16_t grpId; //not required
uint8_t taskType;
uint16_t taskId;
uint64_t startOffset;
uint64_t endOffset;
std::string taskName; //LV
std::string inputFile; //LV
std::string inputFile2; //LV
std::string outputFile; //LV
void decode(Buffer &buf);
void encode(Buffer &buf);
};
struct CliControlMessage{
uint16_t reqType;
uint16_t subType;
uint16_t taskTimeOut;
std::string taskType; //LV
std::string inputFile; //LV
std::string delimiter; //LV
std::string output; //LV
std::string stats; //LV
void decode(Buffer& buf);
void encode(Buffer& buf);
};
int
create_and_bind (char *port, int socketType); //could also provide a specific IP address and port to bind
int
make_socket_non_blocking (int sfd);
int
connect_to_server(int socketType, char* serverIp, char* serverPort);
void
join_server_conn(int fd,int grpId,int reqType);
timer_t
registerTimer(int milliseconds,
void (*timerHandlerCB)( int sig, siginfo_t *si, void *uc ),
void *timerStruct);
void deRegisterTimer(timer_t timert);
void printpeername(int fd);
#endif