Joedb 9.5.0
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::seconds 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 main(int argc, char **argv)
47 ////////////////////////////////////////////////////////////////////////////
48 {
49 if (argc < 3)
50 {
51 std::cerr << "usage: " << argv[0] << " <timeout_seconds> <db>+\n";
52 std::cerr << "file name: <db>.joedb\n";
53 std::cerr << "socket name: <db>.sock\n";
54 std::cerr << "example: " << argv[0] << " 10 db1 db2 db3 db4\n";
55 return 1;
56 }
57
58 std::chrono::seconds timeout(std::stoi(argv[1]));
59
60 IO_Context_Wrapper io_context_wrapper;
61
62 std::list<std::unique_ptr<Server_Data>> servers;
63
64 for (int i = 2; i < argc; i++)
65 {
66 std::string base_name(argv[i]);
67 servers.emplace_back
68 (
69 new Server_Data
70 (
71 io_context_wrapper.io_context,
72 base_name + ".joedb",
73 base_name + ".sock",
74 timeout
75 )
76 );
77 }
78
79 io_context_wrapper.run();
80
81 return 0;
82 }
83}
84
85/////////////////////////////////////////////////////////////////////////////
86int main(int argc, char **argv)
87/////////////////////////////////////////////////////////////////////////////
88{
89 return joedb::main_exception_catcher(joedb::main, argc, argv);
90}
Server_Data(asio::io_context &io_context, const std::string &file_name, const std::string &endpoint_path, 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