Joedb 10.2.1
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
joedb_server.cpp
Go to the documentation of this file.
7
8#include <iostream>
9#include <cstring>
10#include <cstdlib>
11
12namespace joedb
13{
14 /////////////////////////////////////////////////////////////////////////////
15 static int server(Arguments &arguments)
16 /////////////////////////////////////////////////////////////////////////////
17 {
18 std::string default_endpoint_path = "joedb.sock";
19 for (size_t i = 1; i < arguments.size(); i++)
20 {
21 const std::string_view v = arguments[i];
22 if (v.size() > 6 && v.compare(v.size() - 6, 6, ".joedb") == 0)
23 {
24 default_endpoint_path = std::string(v) + ".sock";
25 break;
26 }
27 }
28
29 const int log_level = arguments.get_option<int>("log_level", "level", 100);
30
31 const std::string_view endpoint_path = arguments.get_string_option
32 (
33 "socket",
34 "endpoint_path",
35 default_endpoint_path.c_str()
36 );
37
38 const float timeout_seconds = arguments.get_option<float>
39 (
40 "timeout",
41 "seconds",
42 0.0f
43 );
44
45 const Open_Mode default_open_mode = Open_Mode::write_existing_or_create_new;
46
47 Client_Parser client_parser
48 (
49 default_open_mode,
51 arguments
52 );
53
54 if (!client_parser.get())
55 {
56 arguments.print_help(std::cerr) << '\n';
57 client_parser.print_help(std::cerr);
58 return 1;
59 }
60
61 Client &client = *client_parser.get();
62
63 std::cout << "Creating server (endpoint_path = " << endpoint_path;
64 std::cout << "; timeout = " << timeout_seconds << ")\n";
65
66 Stream_Logger logger(std::cerr);
67
68 const int thread_count = 1;
69
70 Server server
71 (
72 logger,
73 log_level,
74 thread_count,
75 std::string(endpoint_path),
76 client,
77 std::chrono::milliseconds(std::lround(timeout_seconds * 1000))
78 );
79
80 server.join();
81
82 return 0;
83 }
84}
85
86/////////////////////////////////////////////////////////////////////////////
87int main(int argc, char **argv)
88/////////////////////////////////////////////////////////////////////////////
89{
90 return joedb::main_wrapper(joedb::server, argc, argv);
91}
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.