-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathslave.h
More file actions
36 lines (35 loc) · 1.27 KB
/
Copy pathslave.h
File metadata and controls
36 lines (35 loc) · 1.27 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
#include "SlaveInfo.h"
class Slave{
public:
Slave(){};
Slave(string username, string host, string master_host, UInt16 port, UInt16 master_port )
:username_(username),host_(host),master_host_(master_host),
port_(port),master_port_(master_port)
{
SlaveInfo self{username_, host_, port_};
friendlist.push_back(self);
//一开始先发送一个心跳
auto master = caf::io::remote_actor(master_host_, master_port_);
caf::scoped_actor scoped_self;
try{
scoped_self ->sync_send(master, Heartbeat::value, username_, host_, port_).await(
[=](OkAtom){ cout<<username+"log in successfully"<<endl;
});
}catch(caf::network_error & e) {
cout << "cannot't connect to master <"<< master_host_ <<","<< master_port_<<">" <<endl;
}
auto client = spawn(mainBehaveior, this);
};
//向某个slave发送消息
void sendMessage( const string msg , const int id);
void sendFile(const string filename , const int id);
void showFriendList();
void requestFriendList();
private:
string username_, host_,master_host_;
UInt16 port_,master_port_;
actor client;
//向master发送心跳,获取存活列表,接受消息。
static void mainBehaveior(event_based_actor* self,Slave *client_self);
vector<SlaveInfo> friendlist;
};