-
Notifications
You must be signed in to change notification settings - Fork 0
/
ping_server.cpp
72 lines (55 loc) · 1.42 KB
/
ping_server.cpp
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
//
// Copyright (c) 2023-present DeepGrace (complex dot invoke at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/deepgrace/srpc
//
#define BOOST_ASIO_HAS_IO_URING
#define BOOST_ASIO_DISABLE_EPOLL
#include <iostream>
#include <srpc.hpp>
#include <ping.pb.h>
namespace net = boost::asio;
namespace gp = google::protobuf;
void done()
{
std::cout << "got called" << std::endl;
}
class service : public pb::service
{
public:
service()
{
}
void execute(gp::RpcController* controller, const pb::request* request, pb::response* response, gp::Closure* done)
{
std::cout << request->DebugString();
if (request->command() != "ping")
controller->SetFailed("unknown command");
else
response->set_results("pong");
done->Run();
}
~service()
{
}
};
int main(int argc, char* argv[])
{
if (argc != 3)
{
std::cout << "Usage: " << argv[0] << " <host> <port>" << std::endl;
return 1;
}
std::string host(argv[1]);
std::string port(argv[2]);
snp::asio_context ctx;
service s;
srpc::server server(ctx, host, port);
server.register_service(&s, gp::NewPermanentCallback(&done));
server.run();
ctx.run();
return 0;
}