-
Notifications
You must be signed in to change notification settings - Fork 4
/
mpzrpcprovider.h
43 lines (34 loc) · 1.12 KB
/
mpzrpcprovider.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
#pragma once
#include <google/protobuf/service.h>
#include <muduo/net/TcpConnection.h>
#include <muduo/net/EventLoop.h>
#include <muduo/net/TcpServer.h>
#include <muduo/net/InetAddress.h>
#include <unordered_map>
#include <string>
#include <google/protobuf/descriptor.h>
class MpzrpcProvider
{
public:
void publishService(::google::protobuf::Service *service);
void run();
void onConnectionCallback(const muduo::net::TcpConnectionPtr &conn)
{
if (!conn->connected())
{
// 和rpc client的连接断开了
conn->shutdown();
}
};
void onMessageCallback(const muduo::net::TcpConnectionPtr &conn,
muduo::net::Buffer *buffer,
muduo::Timestamp receiveTime);
void SendRpcResponse(const muduo::net::TcpConnectionPtr &conn, google::protobuf::Message *response);
private:
struct ServiceInfo
{
google::protobuf::Service *m_service;
std::unordered_map<std::string, const google::protobuf::MethodDescriptor *> m_methodmap;
};
std::unordered_map<std::string, ServiceInfo> m_servicemap;
};