RDFS
The Rice Comp413 2017 class' continuation on the work of the 2016 RDFS.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
rpcserver.h
1 // Copyright 2017 Rice University, COMP 413 2017
2 
3 #include <easylogging++.h>
4 #include <google/protobuf/io/coded_stream.h>
5 #include <unistd.h>
6 #include <thread>
7 #include <iostream>
8 #include <string>
9 #include <unordered_map>
10 #include <functional>
11 
12 #include <asio.hpp>
13 
14 #include <RpcHeader.pb.h>
15 #include <ProtobufRpcEngine.pb.h>
16 #include <IpcConnectionContext.pb.h>
17 
18 #include "socket_writes.h"
19 #include "socket_reads.h"
20 
21 #include <unistd.h>
22 
23 #pragma once
24 
25 using asio::ip::tcp;
26 
27 class RPCServer {
28  public:
32  explicit RPCServer(int port);
36  void serve(asio::io_service &io_service);
47  void register_handler(
48  std::string key,
49  std::function<std::string(std::string)> handler);
50 
55  std::string getUsername();
56 
57  private:
61  int port;
65  std::unordered_map<std::string, std::function<std::string(std::string)>>
66  dispatch_table;
71  bool receive_handshake(
72  tcp::socket &sock,
73  int16_t *version,
74  int16_t *service,
75  int16_t *auth_protocol);
81  bool receive_prelude(tcp::socket &sock);
86  void handle_rpc(tcp::socket sock);
94  bool send_error_header(
95  hadoop::common::RpcRequestHeaderProto rpc_request_header,
97  std::string response_header_str,
98  tcp::socket &sock);
99 
100  // **RPCSserver**
101  static const std::string CLASS_NAME;
102 };
std::string getUsername()
Definition: rpcserver.cc:271
void register_handler(std::string key, std::function< std::string(std::string)> handler)
Definition: rpcserver.cc:247
Definition: RpcHeader.pb.h:445
RPCServer(int port)
Definition: rpcserver.cc:19
Definition: rpcserver.h:27
Definition: RpcHeader.pb.h:264
void serve(asio::io_service &io_service)
Definition: rpcserver.cc:257