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