Joedb 10.0.1
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
joedb_multi_server.cpp
Go to the documentation of this file.
6
7#include <iostream>
8#include <list>
9#include <memory>
10
11namespace joedb
12{
13 ////////////////////////////////////////////////////////////////////////////
15 ////////////////////////////////////////////////////////////////////////////
16 {
17 private:
18 File file;
19 Connection connection;
21 Server server;
22
23 public:
25 (
26 asio::io_context &io_context,
27 const std::string &file_name,
28 const std::string &endpoint_path,
29 std::chrono::milliseconds timeout
30 ):
32 client(file, connection),
33 server
34 (
35 client,
36 io_context,
37 endpoint_path,
38 timeout,
39 &std::cerr
40 )
41 {
42 }
43 };
44
45 ////////////////////////////////////////////////////////////////////////////
46 static int multi_server(Arguments &arguments)
47 ////////////////////////////////////////////////////////////////////////////
48 {
49 const float timeout_seconds = arguments.get_option<float>
50 (
51 "timeout",
52 "seconds",
53 0.0f
54 );
55
56 arguments.add_parameter("<file.joedb>+");
57
58 if (arguments.get_remaining_count() == 0)
59 {
60 arguments.print_help(std::cerr);
61 return 1;
62 }
63
64 IO_Context_Wrapper io_context_wrapper;
65
66 std::list<std::unique_ptr<Server_Data>> servers;
67
68 while (arguments.get_remaining_count())
69 {
70 const std::string file_name(arguments.get_next());
71 std::cerr << "Creating server for: " << file_name << '\n';
72 servers.emplace_back
73 (
74 new Server_Data
75 (
76 io_context_wrapper.io_context,
77 file_name,
78 file_name + ".sock",
79 std::chrono::milliseconds(int(timeout_seconds * 1000))
80 )
81 );
82 }
83
84 io_context_wrapper.run();
85
86 return 0;
87 }
88}
89
90/////////////////////////////////////////////////////////////////////////////
91int main(int argc, char **argv)
92/////////////////////////////////////////////////////////////////////////////
93{
94 return joedb::main_wrapper(joedb::multi_server, argc, argv);
95}
Server_Data(asio::io_context &io_context, const std::string &file_name, const std::string &endpoint_path, std::chrono::milliseconds timeout)
int main()
Open_Mode
Definition Open_Mode.h:8
@ write_existing_or_create_new
either write_existing or create_new depending on whether the file exists. Racy in Posix,...
int main_wrapper(int(*main)(Arguments &), int argc, char **argv)
Process command-line arguments and catch exceptions from main.
Definition Blob.h:7
JOEDB_FILE File
Definition File.h:25