Joedb 10.3.0
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 Parsed_Logger logger(arguments);
19
20 std::string default_endpoint_path = "joedb.sock";
21 for (size_t i = 1; i < arguments.size(); i++)
22 {
23 const std::string_view v = arguments[i];
24 if (v.size() > 6 && v.compare(v.size() - 6, 6, ".joedb") == 0)
25 {
26 default_endpoint_path = std::string(v) + ".sock";
27 break;
28 }
29 }
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 logger.get(),
50 default_open_mode,
52 arguments
53 );
54
55 if (!client_parser.get())
56 {
57 arguments.print_help(std::cerr) << '\n';
58 client_parser.print_help(std::cerr);
59 return 1;
60 }
61
62 Client &client = *client_parser.get();
63
64 logger.get().log
65 (
66 "creating server, endpoint_path = " + std::string(endpoint_path) +
67 "; timeout = " + std::to_string(timeout_seconds)
68 );
69
70 const int thread_count = 1;
71
72 Server server
73 (
74 logger.get(),
75 logger.get_log_level(),
76 thread_count,
77 std::string(endpoint_path),
78 client,
79 std::chrono::milliseconds(std::lround(timeout_seconds * 1000))
80 );
81
82 server.join();
83
84 return 0;
85 }
86}
87
88/////////////////////////////////////////////////////////////////////////////
89int main(int argc, char **argv)
90/////////////////////////////////////////////////////////////////////////////
91{
92 return joedb::main_wrapper(joedb::server, argc, argv);
93}
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.