drogon icon indicating copy to clipboard operation
drogon copied to clipboard

catch SIGINT signal

Open albaropereyra22 opened this issue 1 year ago • 5 comments

Notice If you need support or clarification regarding the usage of Drogon in your project, visit the official Drogon support channel at gitter

Please create a new issue only if you think you have found a bug or if have a feature request/enhancement.

Is your feature request related to a problem? Please describe. It would be nice if Drogon would catch the SIGINT and allowed me to run a subroutine.

Describe the solution you'd like catch SIGINT and end program without warnings.

Describe alternatives you've considered I am not sure how to do this in c but in a shell script I would run something like trap on SIGINT.

Additional context image

albaropereyra22 avatar Aug 25 '23 06:08 albaropereyra22

Drogon has this member function:

HttpAppFramework &setIntSignalHandler(
        const std::function<void()> &handler)

I never try, but something like this should work: app().setIntSignalHandler(my function); or even

app().setIntSignalHandler([&]{std::cerr << "Alarm! SIGINT!";});

VladlenPopolitov avatar Aug 26 '23 03:08 VladlenPopolitov

I added this to main but I am still seeing the warning. Is there a way to get rid of the warning?

albaropereyra22 avatar Aug 26 '23 10:08 albaropereyra22

Also I have a follow up question, after I print out std::cout "good bye" how can I exit. I tried exit and return 0 to no avail. How do I get my terminal back. Please advice. Thanks.

albaropereyra22 avatar Aug 26 '23 12:08 albaropereyra22

Would you like drogon stop running and exit? I suppose app().quit(); will do this work (stop all threads , plugins and return to main (where you called it from))

VladlenPopolitov avatar Aug 27 '23 09:08 VladlenPopolitov

Perfect! That worked thanks.

albaropereyra22 avatar Aug 29 '23 09:08 albaropereyra22