From 2e46944df68ecd4910a96b2ff4ee55936d606ef7 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 13 Aug 2016 16:16:44 +0200 Subject: [PATCH] Deal better with the HTTP port being busy. --- httpd.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/httpd.cpp b/httpd.cpp index 6f94409..3fbab5d 100644 --- a/httpd.cpp +++ b/httpd.cpp @@ -26,11 +26,13 @@ HTTPD::HTTPD() HTTPD::~HTTPD() { - MHD_quiesce_daemon(mhd); - for (Stream *stream : streams) { - stream->stop(); + if (mhd) { + MHD_quiesce_daemon(mhd); + for (Stream *stream : streams) { + stream->stop(); + } + MHD_stop_daemon(mhd); } - MHD_stop_daemon(mhd); } void HTTPD::start(int port) @@ -41,6 +43,9 @@ void HTTPD::start(int port) &answer_to_connection_thunk, this, MHD_OPTION_NOTIFY_COMPLETED, nullptr, this, MHD_OPTION_END); + if (mhd == nullptr) { + fprintf(stderr, "Warning: Could not open HTTP server. (Port already in use?)\n"); + } } void HTTPD::add_data(const char *buf, size_t size, bool keyframe) -- 2.39.2