forked from wxdwfc/rlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
msg_interface.hpp
102 lines (80 loc) · 2.03 KB
/
msg_interface.hpp
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
#pragma once
#include <string>
#include <set>
#include <functional>
#include "common.hpp"
namespace rdmaio {
typedef std::function<void(const char *,int,int)> msg_callback_t_;
/**
* An abstract message interface
* Assumption: one per thread
*/
class MsgAdapter {
public:
MsgAdapter(msg_callback_t_ callback)
: callback_(callback) {
}
MsgAdapter() {
}
void set_callback(msg_callback_t_ callback) {
callback_ = callback;
}
virtual ConnStatus connect(std::string ip,int port) = 0;
/**
* Basic send interfaces
*/
virtual ConnStatus send_to(int node_id,const char *msg,int len) = 0;
virtual ConnStatus send_to(int node_id,int tid,const char *msg,int len) {
return send_to(node_id,msg,len);
}
/**
* Interfaces which allow batching at the sender's side
*/
virtual void prepare_pending() {
}
virtual ConnStatus send_pending(int node_id,const char *msg,int len) {
RDMA_ASSERT(false); // not implemented
}
virtual ConnStatus send_pending(int node_id,int tid,const char *msg,int len) {
return send_pending(node_id,msg,len);
}
/**
* Flush all the currently pended message
*/
virtual ConnStatus flush_pending() {
return SUCC;
}
/**
* Examples to use batching at the sender side
* Broadcast the message to a set of servers
*/
virtual ConnStatus broadcast_to(const std::set<int> &nodes, const char *msg,int len) {
prepare_pending();
for(auto it = nodes.begin(); it != nodes.end(); ++it) {
send_pending(*it,msg,len);
}
flush_pending();
return SUCC; // TODO
}
virtual ConnStatus broadcast_to(int *nodes,int num, const char *msg,int len) {
prepare_pending();
for(int i = 0;i < num;++i) {
send_pending(nodes[i],msg,len);
}
flush_pending();
return SUCC; // TODO
}
/**
* The receive function
*/
virtual void poll_comps() = 0;
/**
* The size of meta data used by the MsgAdapter for each message
*/
virtual int msg_meta_len() {
return 0;
}
protected:
msg_callback_t_ callback_;
};
};