MCPcopy Create free account
hub / github.com/ByConity/ByConity / receiveResult

Method receiveResult

programs/client/Client.cpp:2060–2126  ·  view source on GitHub ↗

Receives and processes packets coming from server. Also checks if query execution should be cancelled.

Source from the content-addressed store, hash-verified

2058 /// Receives and processes packets coming from server.
2059 /// Also checks if query execution should be cancelled.
2060 void receiveResult()
2061 {
2062 InterruptListener interrupt_listener;
2063 bool cancelled = false;
2064
2065 // TODO: get the poll_interval from commandline.
2066 const auto receive_timeout = connection_parameters.timeouts.receive_timeout;
2067 constexpr size_t default_poll_interval = 1000000; /// in microseconds
2068 constexpr size_t min_poll_interval = 5000; /// in microseconds
2069 const size_t poll_interval
2070 = std::max(min_poll_interval, std::min<size_t>(receive_timeout.totalMicroseconds(), default_poll_interval));
2071
2072 while (true)
2073 {
2074 Stopwatch receive_watch(CLOCK_MONOTONIC_COARSE);
2075
2076 while (true)
2077 {
2078 /// Has the Ctrl+C been pressed and thus the query should be cancelled?
2079 /// If this is the case, inform the server about it and receive the remaining packets
2080 /// to avoid losing sync.
2081 if (!cancelled)
2082 {
2083 auto cancel_query = [&] {
2084 connection->sendCancel();
2085 cancelled = true;
2086 if (is_interactive)
2087 {
2088 progress_indication.clearProgressOutput();
2089 std::cout << "Cancelling query." << std::endl;
2090 }
2091
2092 /// Pressing Ctrl+C twice results in shut down.
2093 interrupt_listener.unblock();
2094 };
2095
2096 if (interrupt_listener.check())
2097 {
2098 cancel_query();
2099 }
2100 else
2101 {
2102 double elapsed = receive_watch.elapsedSeconds();
2103 if (elapsed > receive_timeout.totalSeconds())
2104 {
2105 std::cout << "Timeout exceeded while receiving data from server."
2106 << " Waited for " << static_cast<size_t>(elapsed) << " seconds,"
2107 << " timeout is " << receive_timeout.totalSeconds() << " seconds." << std::endl;
2108
2109 cancel_query();
2110 }
2111 }
2112 }
2113
2114 /// Poll for changes after a cancellation check, otherwise it never reached
2115 /// because of progress updates from server.
2116 if (connection->poll(poll_interval))
2117 break;

Callers

nothing calls this directly

Calls 9

totalMicrosecondsMethod · 0.80
clearProgressOutputMethod · 0.80
unblockMethod · 0.80
totalSecondsMethod · 0.80
maxFunction · 0.50
sendCancelMethod · 0.45
checkMethod · 0.45
elapsedSecondsMethod · 0.45
pollMethod · 0.45

Tested by

no test coverage detected