Skip to content

Asio SSL client timeout/error-handling patch. Make POSIX signal-friendly interface.#356

Open
officer-34762 wants to merge 2 commits into
reo7sp:masterfrom
officer-34762:master
Open

Asio SSL client timeout/error-handling patch. Make POSIX signal-friendly interface.#356
officer-34762 wants to merge 2 commits into
reo7sp:masterfrom
officer-34762:master

Conversation

@officer-34762
Copy link
Copy Markdown

Hi. First of all, I updated ssl client using boost asio to handle timeout of read-write/connect more carefully also throwing detailed errors. Second, launch_once function was created to customize limit/timeout values and allowed notify types array without new object creation. Instead of creating TgLongPoll object every time so as to change values of arguments start function in an every cycle of a loop i can make launch_once call with another values.
Next you got like this in your samples:

    signal(SIGINT, [](int s) {
        printf("SIGINT got\n");
        exit(0); // It must be '_exit(0)'
    });

I have to get special processing on signal fired so i can't just do what i would want and call exit(0) because it's recommended to use async thread safe only functions in such handlers. And more, long_poll.start() might freeze if i get unstable network connection and an application receive a signal. This is my walkthrough of how I achieved this:

std::atomic<int> g_received_signal{0};

void interrupt_handler(int signal) {
  g_received_signal = signal;
}

// in main func
signal(SIGINT, interrupt_handler);
signal(SIGTERM, interrupt_handler);
signal(SIGHUP, force_reconf_handler);

int received_signal = 0;
TgBot::TgLongPoll long_poll(bot);
  while (received_signal = g_received_signal.load(), !exit_tg(received_signal)) {
    try {
      if(1/*trigger*/)
         long_poll.launch_once(100, 0, {});
      else // Something specific happened wherever
         long_poll.launch_once(1000, 50, {"inline_query", "callback_query"/*, etc*/});
    } catch (const std::exception &e) {
      spdlog::error("Error in long poll: {}", e.what());
    }
  }

// Some important things should be finished here instead doing it in signal handler
return EXIT_SUCCESS; // or exit(0)

I tried to save support of Asio library from Boost 1.65.1 version. Though i didn't check working it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant