Debian Codegraph @

src/soaktest/soak.cpp

raw symbols SCIP
1 /************************************************************************************
2 *
3 * D++, A Lightweight C++ library for Discord
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 * Copyright 2021 Craig Edwards and D++ contributors
7 * (https://github.com/brainboxdotcc/DPP/graphs/contributors)
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 ************************************************************************************/
22
23 #include <dpp/dpp.h>
24 #include <iostream>
25 #include <thread>
26 #include <atomic>
27 #ifndef _WIN32
28 #include <csignal>
29 #endif
30
31 dpp::cluster* s{nullptr};
32 std::atomic_bool signalled{false};
33
34 int main() {
35 using namespace std::chrono_literals;
36 char* t = getenv("DPP_UNIT_TEST_TOKEN");
37 if (t) {
38 dpp::cluster soak_test(t, dpp::i_default_intents | dpp::i_guild_members, 1, 0, 1);
39 s = &soak_test;
40 //soak_test.set_websocket_protocol(dpp::ws_etf);
41 soak_test.on_log([&](const dpp::log_t& log) {
42 std::cout << "[" << dpp::utility::current_date_time() << "] " << dpp::utility::loglevel(log.severity) << ": " << log.message << std::endl;
43 });
44 soak_test.start(dpp::st_return);
45
46 #ifndef _WIN32
47 signal(SIGUSR1, [](int sig) {
48 signalled = true;
49 });
50 #endif
51
52 while (true) {
53 std::this_thread::sleep_for(1s);
54 dpp::discord_client* dc = soak_test.get_shard(0);
55 if (dc != nullptr) {
56 if (time(nullptr) % 60 == 0) {
57 std::cout << "Websocket latency: " << std::fixed << dc->websocket_ping << " Guilds: " << dpp::get_guild_count() << " Users: " << dpp::get_user_count() << "\n";
58 }
59 if (signalled) {
60 signalled = false;
61 dc->close();
62 }
63 }
64 }
65 }
66 }