-
Notifications
You must be signed in to change notification settings - Fork 243
/
Copy pathrpc_server.h
47 lines (39 loc) · 1.3 KB
/
rpc_server.h
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
#ifndef TEST_RPC_RPCSERVER_HEADER
#define TEST_RPC_RPCSERVER_HEADER
#include <map>
#include <mutex>
#include <memory>
#include <atomic>
#include "common_struct.h"
#include "include/cppnet.h"
#include "common/alloter/alloter_interface.h"
class InfoRouter;
class ParsePackage;
class RPCServer {
public:
RPCServer();
~RPCServer();
//create func thread and add to router
void Init(int thread);
//Destroy func thread
void Destroy();
//start work
void Start(short port, std::string ip);
bool RegisterFunc(std::string name, std::string func_str, const CommonFunc& func);
bool RemoveFunc(std::string name);
private:
void _DoRead(cppnet::Handle handle, cppnet::BufferPtr data,
uint32_t len);
void _DoWrite(cppnet::Handle handle, uint32_t len);
void _DoAccept(cppnet::Handle handle, uint32_t err);
void _PackageAndSend(cppnet::Handle handle, FuncCallInfo* info, int code);
private:
std::shared_ptr<InfoRouter> _info_router;
std::shared_ptr<ParsePackage> _parse_package;
cppnet::CppNet _net;
cppnet::AlloterWrap _pool;
std::atomic_bool _need_mutex;
std::mutex _mutex;
std::map<std::string, std::string> _func_map;
};
#endif