-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.cpp
94 lines (73 loc) · 1.97 KB
/
util.cpp
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
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "util.h"
#include "constant.h"
using namespace std;
void log(string msg){
if(VERBOSITY_LEVEL >= 1)
cout << "[LOG PROC-" << getpid() << "] " << msg << endl;
}
void vlog(string msg){
if(VERBOSITY_LEVEL >= 2)
cout << "[VLOG PROC-" << getpid() << "] " << msg << endl;
}
void vvlog(string msg){
if(VERBOSITY_LEVEL >= 3)
cout << "[VVLOG PROC-" << getpid() << "] " << msg << endl;
}
void errorHandler(uint16_t errorId = GEN_ERR)
{
printf(" ERR - ");
switch (errorId)
{
case GEN_ERR:
printf("Generic Error\n");
break;
case BIND_ERR:
printf("Bind Error\n");
break;
case LISTEN_ERR:
printf("Listen Error\n");
break;
case CONN_ERR:
perror("Connection Error\n");
break;
case SEND_ERR:
perror("Error during sending\n");
break;
case REC_ERR:
perror("Error during receiving\n");
break;
case MALLOC_ERR:
printf("Malloc failed\n");
break;
case INT_OW_ERR:
printf("Integer overflow avoided\n");
break;
case SEM_OPEN_ERR:
printf("Error on sem_open\n");
break;
case SEM_POST_ERR:
printf("Error on sem_post\n");
break;
case SEM_WAIT_ERR:
printf("Error on sem_wait\n");
break;
case SEM_CLOSE_ERR:
printf("Error on sem_close\n");
break;
case SRV_INTERNAL_ERR:
printf("Server internal error\n");
break;
case AUTHENTICATION_ERR:
printf("Error during authentication Phase\n");
break;
default:
printf("Generic Error\n");
break;
}
// exit(-1);
}