]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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/xio/XioMessenger.h" | |
24 | #include "msg/xio/FastStrategy.h" | |
25 | #include "msg/xio/QueueStrategy.h" | |
26 | #include "common/Timer.h" | |
27 | #include "common/ceph_argparse.h" | |
28 | #include "global/global_init.h" | |
29 | #include "global/signal_handler.h" | |
30 | #include "perfglue/heap_profiler.h" | |
31 | #include "common/address_helper.h" | |
32 | #include "xio_dispatcher.h" | |
33 | ||
34 | #define dout_subsys ceph_subsys_simple_server | |
35 | ||
36 | ||
37 | int main(int argc, const char **argv) | |
38 | { | |
39 | vector<const char*> args; | |
40 | Messenger *messenger; | |
41 | Dispatcher *dispatcher; | |
42 | std::vector<const char*>::iterator arg_iter; | |
43 | std::string val; | |
44 | entity_addr_t bind_addr; | |
45 | int r = 0; | |
46 | ||
47 | using std::endl; | |
48 | ||
49 | std::string addr = "localhost"; | |
50 | std::string port = "1234"; | |
51 | bool dfast = false; | |
52 | ||
53 | cout << "Xio Server starting..." << endl; | |
54 | ||
55 | argv_to_vec(argc, argv, args); | |
7c673cae FG |
56 | |
57 | global_init(NULL, args, CEPH_ENTITY_TYPE_ANY, CODE_ENVIRONMENT_DAEMON, | |
11fdf7f2 | 58 | CINIT_FLAG_NO_DEFAULT_CONFIG_FILE); |
7c673cae FG |
59 | |
60 | for (arg_iter = args.begin(); arg_iter != args.end();) { | |
61 | if (ceph_argparse_witharg(args, arg_iter, &val, "--addr", | |
62 | (char*) NULL)) { | |
63 | addr = val; | |
64 | } else if (ceph_argparse_witharg(args, arg_iter, &val, "--port", | |
65 | (char*) NULL)) { | |
66 | port = val; | |
67 | } else if (ceph_argparse_flag(args, arg_iter, "--dfast", | |
68 | (char*) NULL)) { | |
69 | dfast = true; | |
70 | } else { | |
71 | ++arg_iter; | |
72 | } | |
73 | }; | |
74 | ||
75 | string dest_str = "tcp://"; | |
76 | dest_str += addr; | |
77 | dest_str += ":"; | |
78 | dest_str += port; | |
79 | entity_addr_from_url(&bind_addr, dest_str.c_str()); | |
80 | ||
81 | DispatchStrategy* dstrategy; | |
82 | if (dfast) | |
83 | dstrategy = new FastStrategy(); | |
84 | else | |
85 | dstrategy = new QueueStrategy(2); | |
86 | ||
87 | messenger = new XioMessenger(g_ceph_context, | |
88 | entity_name_t::MON(-1), | |
89 | "xio_server", | |
90 | 0 /* nonce */, | |
91 | 0 /* cflags */, | |
92 | dstrategy); | |
93 | ||
94 | static_cast<XioMessenger*>(messenger)->set_magic( | |
95 | MSG_MAGIC_REDUPE /* resubmit messages on delivery (REQUIRED) */ | | |
96 | MSG_MAGIC_TRACE_CTR /* timing prints */); | |
97 | ||
98 | messenger->set_default_policy( | |
99 | Messenger::Policy::stateless_server(0)); | |
100 | ||
101 | r = messenger->bind(bind_addr); | |
102 | if (r < 0) | |
103 | goto out; | |
104 | ||
105 | // Set up crypto, daemonize, etc. | |
106 | //global_init_daemonize(g_ceph_context, 0); | |
107 | common_init_finish(g_ceph_context); | |
108 | ||
109 | dispatcher = new XioDispatcher(messenger); | |
110 | ||
111 | messenger->add_dispatcher_head(dispatcher); // should reach ready() | |
112 | messenger->start(); | |
113 | messenger->wait(); // can't be called until ready() | |
114 | ||
115 | // done | |
116 | delete messenger; | |
117 | ||
118 | out: | |
119 | cout << "Simple Server exit" << endl; | |
120 | return r; | |
121 | } | |
122 |