-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathincomingMsg_handler.cpp
More file actions
57 lines (34 loc) · 1.32 KB
/
incomingMsg_handler.cpp
File metadata and controls
57 lines (34 loc) · 1.32 KB
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
#include "globals.hpp"
#include "node_controller.hpp"
#include "message_buffer.hpp"
#include <iostream>
extern nodeController::LogicalClock node_clock;
extern unsigned MY_NODE_ID;
void * nodeController::incoming_msg_handler( void* argument )
{
using std::cerr;
using std::endl;
using namespace nodeController::incomingMsgHandler;
using nodeController::Message;
thread_arg arg = *(thread_arg *) argument;
//delete (thread_arg *) argument;
while ( true ) {
Message incoming;
incoming = arg.in_buffer->consume_msg( 0 );
//handles both uninit timestamp from local clients and
//compares peer's timestamps with local node's clock
node_clock( incoming.time_stamp );
int row_offset = ( incoming.type == MESSAGE_T::REPLY ) ? 1 : 0;
int whichrow = row_offset + ( 2 * static_cast<int> ( incoming.sub_act ) );
arg.rqstQ_buffer->produce_msg( whichrow,
incoming );
if ( incoming.loc_msg ) {
//need to set loc_msg pointer to NULL before sending over network
//but loc_msg pointer remains for local RQST queue
Message localOut = incoming;
localOut.loc_msg = nullptr;
arg.out_buffer->produce_msg( 0, localOut );
}
}
return nullptr;
}