Joedb 10.0.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 std::string_view endpoint_path = arguments.get_string_option
30 (
31 "socket",
32 "endpoint_path",
33 default_endpoint_path.c_str()
34 );
35
36 const float timeout_seconds = arguments.get_option<float>
37 (
38 "timeout",
39 "seconds",
40 0.0f
41 );
42
43 const Open_Mode default_open_mode = Open_Mode::write_existing_or_create_new;
44
45 Client_Parser client_parser(default_open_mode, Client_Parser::DB_Type::none, arguments);
46
47 if (!client_parser.get())
48 {
49 arguments.print_help(std::cerr) << '\n';
50 client_parser.print_help(std::cerr);
51 return 1;
52 }
53
54 Client &client = *client_parser.get();
55
56 IO_Context_Wrapper io_context_wrapper;
57
58 std::cout << "Creating server (endpoint_path = " << endpoint_path;
59 std::cout << "; timeout = " << timeout_seconds << ")\n";
60
61 Server server
62 (
63 client,
64 io_context_wrapper.io_context,
65 std::string(endpoint_path),
66 std::chrono::milliseconds(int(timeout_seconds * 1000)),
67 &std::cerr
68 );
69
70 io_context_wrapper.run();
71
72 return 0;
73 }
74}
75
76/////////////////////////////////////////////////////////////////////////////
77int main(int argc, char **argv)
78/////////////////////////////////////////////////////////////////////////////
79{
80 return joedb::main_wrapper(joedb::server, argc, argv);
81}
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.
Definition Blob.h:7