Joedb 9.1.4
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
joedb_server.cpp
Go to the documentation of this file.
6
7#include <iostream>
8#include <cstring>
9#include <cstdlib>
10
11namespace joedb
12{
13 /////////////////////////////////////////////////////////////////////////////
14 static int joedb_server(int argc, char **argv)
15 /////////////////////////////////////////////////////////////////////////////
16 {
17 const bool local = true;
18 const Open_Mode default_open_mode = Open_Mode::write_existing_or_create_new;
19 const bool with_database = false;
20
21 Client_Parser client_parser(local, default_open_mode, with_database);
22
23 if (argc <= 1)
24 {
25 std::cerr << "usage: " << argv[0];
26 std::cerr << " [--port p] [--timeout t] [--share]";
27 client_parser.print_help(std::cerr);
28 std::cerr << R"RRR(
29The timeout is the time (in seconds) during which a client lock is kept.
300 (the default) means there is no timeout, and the lock is kept until the
31client unlocks or is disconnected. A client that timed out is not disconnected,
32and can still push data: the push will succeed only if there is no conflict.
33)RRR";
34 return 1;
35 }
36
37 int32_t index = 1;
38
39 uint16_t port = 0;
40 if (index + 1 < argc && std::strcmp(argv[index], "--port") == 0)
41 {
42 port = uint16_t(std::atoi(argv[index + 1]));
43 index += 2;
44 }
45
46 uint32_t timeout = 0;
47 if (index + 1 < argc && std::strcmp(argv[index], "--timeout") == 0)
48 {
49 timeout = uint32_t(std::atoi(argv[index + 1]));
50 index += 2;
51 }
52
53 bool share = false;
54 if (index < argc && std::strcmp(argv[index], "--share") == 0)
55 {
56 share = true;
57 index += 1;
58 }
59
60 Client &client = client_parser.parse(argc - index, argv + index);
61
62 IO_Context_Wrapper io_context_wrapper;
63
64 std::cout << "Creating server (port = " << port;
65 std::cout << "; timeout = " << timeout;
66 std::cout << "; share = " << share << ")\n";
67
68 Server server
69 (
70 client,
71 share,
72 io_context_wrapper.io_context,
73 port,
74 std::chrono::seconds(timeout),
75 &std::cerr
76 );
77
78 io_context_wrapper.run();
79
80 return 0;
81 }
82}
83
84/////////////////////////////////////////////////////////////////////////////
85int main(int argc, char **argv)
86/////////////////////////////////////////////////////////////////////////////
87{
88 return joedb::main_exception_catcher(joedb::joedb_server, argc, argv);
89}
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