Joedb 10.4.3
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#include <cmath>
12
13namespace joedb
14{
15 /////////////////////////////////////////////////////////////////////////////
16 static int server(Arguments &arguments)
17 /////////////////////////////////////////////////////////////////////////////
18 {
19 Parsed_Logger logger(arguments);
20
21 std::string default_endpoint_path = "joedb.sock";
22 for (size_t i = 1; i < arguments.size(); i++)
23 {
24 const beman::cstring_view v = arguments[i];
25 if (v.ends_with(".joedb"))
26 {
27 default_endpoint_path = std::string(v) + ".sock";
28 break;
29 }
30 }
31
32 const std::string_view endpoint_path = arguments.get_string_option
33 (
34 "socket",
35 "endpoint_path",
36 default_endpoint_path.c_str()
37 );
38
39 const float timeout_seconds = arguments.get_option<float>
40 (
41 "timeout",
42 "seconds",
43 0.0f
44 );
45
46 const Open_Mode default_open_mode = Open_Mode::write_existing_or_create_new;
47
48 Parsed_Client parsed_client
49 (
50 logger.get(),
51 default_open_mode,
53 arguments
54 );
55
56 if (!parsed_client.get())
57 {
58 arguments.print_help(std::cerr) << '\n';
59 parsed_client.print_help(std::cerr);
60 return 1;
61 }
62
63 Client &client = *parsed_client.get();
64
65 logger.get().log
66 (
67 "creating server, endpoint_path = " + std::string(endpoint_path) +
68 "; timeout = " + std::to_string(timeout_seconds)
69 );
70
71 const int thread_count = 1;
72
73 Server server
74 (
75 logger.get(),
76 logger.get_log_level(),
77 thread_count,
78 std::string(endpoint_path),
79 client,
80 std::chrono::milliseconds(std::lround(timeout_seconds * 1000))
81 );
82
83 server.join();
84
85 return 0;
86 }
87}
88
89/////////////////////////////////////////////////////////////////////////////
90int main(int argc, char **argv)
91/////////////////////////////////////////////////////////////////////////////
92{
93 return joedb::main_wrapper(joedb::server, argc, argv);
94}
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.