Joedb 10.3.0
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
keepalive_test.cpp
Go to the documentation of this file.
7
8#include <iostream>
9
10namespace joedb
11{
12 /// test how long we can wait without losing connection
13 static int keepalive_test(Arguments &arguments)
14 {
15 Parsed_Logger logger(arguments);
16
17 const std::string_view user = arguments.get_next("user");
18 const std::string_view host = arguments.get_next("host");
19 const std::string_view endpoint_path = arguments.get_next("endpoint_path");
20
21 if (arguments.missing())
22 {
23 arguments.print_help(std::cerr);
24 return 1;
25 }
26
27 std::chrono::seconds wait(1);
28 std::chrono::seconds increment(1);
29
30 Memory_File file;
31 Writable_Journal journal(file);
32
33 while (true)
34 {
35 ssh::Session session(user.data(), host.data(), 22, 0);
36 ssh::Forward_Channel channel(session, endpoint_path.data());
37 Server_Connection connection(channel, logger.get());
38 Writable_Client client(journal, connection, Content_Check::none);
39
40 try
41 {
42 channel.set_timeout(wait + increment + std::chrono::seconds(30));
43 client.pull(wait + increment);
44 wait = wait + increment;
45 increment *= 2;
46 }
47 catch (const std::exception &e)
48 {
49 std::cerr << "Caught exception: " << e.what() << '\n';
50 increment = (std::chrono::seconds(3) + increment) / 4;
51 }
52 }
53
54 return 0;
55 }
56}
57
58int main(int argc, char **argv)
59{
60 return joedb::main_wrapper(joedb::keepalive_test, argc, argv);
61}
int main()
int main_wrapper(int(*main)(Arguments &), int argc, char **argv)
Process command-line arguments and catch exceptions from main.