-
Notifications
You must be signed in to change notification settings - Fork 0
/
backend.cpp
59 lines (49 loc) · 1.47 KB
/
backend.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
#include "dcp.h"
#include "handler.h"
#include "mysql_connection.h"
#include "logger.h"
#include "socket.h"
#include <cstring>
int main() {
char* buf;
struct message* header = new struct message;
db_connection* conn = new db_connection;
net_connection* net_conn = new net_connection;
while ( 1 ){
buf = net_conn->receive( );
memcpy( header, buf, sizeof( struct message));
/** Only allow DCP messages */
if ( header->proto != Proto_Dispatcher )
{
log_err() << header->num << ": unhandled protocol " << header->proto;
continue;
}
log_err() << header->num << ": " << header->type;
switch ( header->type )
{
case Msg_Heartbeat:
if ( checksum<struct msg_heartbeat>( (const uint8_t*)buf) )
{
log_err() << "Incorrect checksum";
continue;
}
heartbeat( buf, conn);
break;
case Msg_ReqConfirm:
conf_request( buf);
break;
case Msg_Confirm:
confirm( buf);
break;
case Msg_Report:
report( buf);
break;
default:
log_err() << header->num << ": unhandled message type " << header->type;
continue;
}
delete buf;
}
log_norm() << "Server terminated";
return 0;
}