Joedb 10.2.1
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
joedb_push.cpp
Go to the documentation of this file.
4#include "joedb/Signal.h"
5
6#include <iostream>
7#include <limits>
8#include <thread>
9#include <chrono>
10#include <cstring>
11#include <cstdlib>
12
13namespace joedb
14{
15 ////////////////////////////////////////////////////////////////////////////
16 static int push(Arguments &arguments)
17 ////////////////////////////////////////////////////////////////////////////
18 {
19 const bool follow = arguments.has_flag("follow");
20 const int64_t until_checkpoint = arguments.get_option<int64_t>
21 (
22 "until",
23 "checkpoint",
24 std::numeric_limits<int64_t>::max()
25 );
26
27 Client_Parser client_parser
28 (
31 arguments
32 );
33
34 if (!client_parser.get())
35 {
36 arguments.print_help(std::cerr) << '\n';
37 client_parser.print_help(std::cerr);
38 return 1;
39 }
40
41 Client &client = *client_parser.get();
42 client.push_if_ahead(until_checkpoint);
43
44 if (follow)
45 {
47
48 while
49 (
50 client.get_connection_checkpoint() < until_checkpoint &&
51 Signal::get_signal() != SIGINT
52 )
53 {
54 std::this_thread::sleep_for(std::chrono::seconds(1));
55 client.push_if_ahead(until_checkpoint);
56 }
57 }
58
59 return 0;
60 }
61}
62
63/////////////////////////////////////////////////////////////////////////////
64int main(int argc, char **argv)
65/////////////////////////////////////////////////////////////////////////////
66{
67 return joedb::main_wrapper(joedb::push, argc, argv);
68}
static int get_signal()
Definition Signal.cpp:27
static void start()
Definition Signal.cpp:34
int main()
@ read_existing
fails if does not exist
int main_wrapper(int(*main)(Arguments &), int argc, char **argv)
Process command-line arguments and catch exceptions from main.