]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/messenger/simple_server.cc
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / test / messenger / simple_server.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2013 CohortFS, LLC
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15 #include <sys/types.h>
16
17 #include <iostream>
18 #include <string>
19
20 using namespace std;
21
22 #include "common/config.h"
23 #include "msg/Messenger.h"
24 #include "common/Timer.h"
25 #include "common/ceph_argparse.h"
26 #include "global/global_init.h"
27 #include "global/signal_handler.h"
28 #include "perfglue/heap_profiler.h"
29 #include "common/address_helper.h"
30 #include "simple_dispatcher.h"
31
32 #define dout_subsys ceph_subsys_simple_server
33
34
35 int main(int argc, const char **argv)
36 {
37 vector<const char*> args;
38 Messenger *messenger;
39 Dispatcher *dispatcher;
40 std::vector<const char*>::iterator arg_iter;
41 std::string val;
42 entity_addr_t bind_addr;
43 int r = 0;
44
45 using std::endl;
46
47 std::string addr = "localhost";
48 std::string port = "1234";
49
50 cout << "Simple Server starting..." << endl;
51
52 argv_to_vec(argc, argv, args);
53 env_to_vec(args);
54
55 auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_ANY,
56 CODE_ENVIRONMENT_DAEMON,
57 0);
58
59 for (arg_iter = args.begin(); arg_iter != args.end();) {
60 if (ceph_argparse_witharg(args, arg_iter, &val, "--addr",
61 (char*) NULL)) {
62 addr = val;
63 } else if (ceph_argparse_witharg(args, arg_iter, &val, "--port",
64 (char*) NULL)) {
65 port = val;
66 } else {
67 ++arg_iter;
68 }
69 };
70
71 string dest_str = "tcp://";
72 dest_str += addr;
73 dest_str += ":";
74 dest_str += port;
75 entity_addr_from_url(&bind_addr, dest_str.c_str());
76
77 messenger = Messenger::create(g_ceph_context, g_conf->get_val<std::string>("ms_type"),
78 entity_name_t::MON(-1),
79 "simple_server",
80 0 /* nonce */,
81 0 /* flags */);
82 // enable timing prints
83 messenger->set_magic(MSG_MAGIC_TRACE_CTR);
84 messenger->set_default_policy(
85 Messenger::Policy::stateless_server(0));
86
87 r = messenger->bind(bind_addr);
88 if (r < 0)
89 goto out;
90
91 // Set up crypto, daemonize, etc.
92 //global_init_daemonize(g_ceph_context, 0);
93 common_init_finish(g_ceph_context);
94
95 dispatcher = new SimpleDispatcher(messenger);
96
97 messenger->add_dispatcher_head(dispatcher); // should reach ready()
98 messenger->start();
99 messenger->wait(); // can't be called until ready()
100
101 // done
102 delete messenger;
103
104 out:
105 cout << "Simple Server exit" << endl;
106 return r;
107 }
108