Joedb 9.1.4
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
joedb_multi_server.cpp
Go to the documentation of this file.
7
8#include <iostream>
9#include <list>
10#include <memory>
11
12namespace joedb
13{
14 ////////////////////////////////////////////////////////////////////////////
16 ////////////////////////////////////////////////////////////////////////////
17 {
18 private:
19 File file;
20 Connection connection;
22 Server server;
23
24 public:
26 (
27 asio::io_context &io_context,
28 const std::string &file_name,
29 uint16_t port,
30 std::chrono::seconds timeout
31 ):
33 client(file, connection),
34 server
35 (
36 client,
37 false,
38 io_context,
39 port,
40 timeout,
41 &std::cerr
42 )
43 {
44 }
45 };
46
47 ////////////////////////////////////////////////////////////////////////////
48 static int main(int argc, char **argv)
49 ////////////////////////////////////////////////////////////////////////////
50 {
51 if (argc != 2)
52 {
53 std::cerr << "usage: " << argv[0] << " <config.joedbi>\n";
54 return 1;
55 }
56
57 const char * const config_file_name = argv[1];
58 db::multi_server::Readonly_Database db
59 (
60 Readonly_Interpreted_File{config_file_name}
61 );
62
63 IO_Context_Wrapper io_context_wrapper;
64
65 std::list<std::unique_ptr<Server_Data>> servers;
66
67 for (auto server: db.get_server_table())
68 {
69 servers.emplace_back
70 (
71 new Server_Data
72 (
73 io_context_wrapper.io_context,
74 db.get_file_name(server),
75 uint16_t(db.get_port(server)),
76 std::chrono::seconds(db.get_timeout(server))
77 )
78 );
79 }
80
81 io_context_wrapper.run();
82
83 return 0;
84 }
85}
86
87/////////////////////////////////////////////////////////////////////////////
88int main(int argc, char **argv)
89/////////////////////////////////////////////////////////////////////////////
90{
91 return joedb::main_exception_catcher(joedb::main, argc, argv);
92}
Server_Data(asio::io_context &io_context, const std::string &file_name, uint16_t port, std::chrono::seconds 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_exception_catcher(int(*main)(int, char **), int argc, char **argv)
Catch exception from main.
Definition Blob.h:7
JOEDB_FILE File
Definition File.h:25