]> git.sesse.net Git - nageru/commitdiff
Deal better with the HTTP port being busy.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 13 Aug 2016 14:16:44 +0000 (16:16 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 13 Aug 2016 14:17:03 +0000 (16:17 +0200)
httpd.cpp

index 6f94409f3a55fea4244dd441d1fd466f8250d92f..3fbab5d6d6630e97e6133a2df44b890b8484cf50 100644 (file)
--- 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)