]> git.sesse.net Git - nageru/blobdiff - httpd.h
Write 1.4.0 changelog.
[nageru] / httpd.h
diff --git a/httpd.h b/httpd.h
index 94de03199827f5282e4e195ee23e0150bc4fbb4f..902745a5845b85d5e873914189057846c3a90585 100644 (file)
--- a/httpd.h
+++ b/httpd.h
@@ -3,22 +3,22 @@
 
 // A class dealing with stream output to HTTP.
 
-#include <microhttpd.h>
 #include <stddef.h>
 #include <stdint.h>
 #include <sys/types.h>
 #include <condition_variable>
 #include <deque>
-#include <memory>
 #include <mutex>
 #include <set>
 #include <string>
 
 struct MHD_Connection;
+struct MHD_Daemon;
 
 class HTTPD {
 public:
        HTTPD();
+       ~HTTPD();
 
        // Should be called before start().
        void set_header(const std::string &data) {
@@ -41,10 +41,6 @@ private:
 
        static void free_stream(void *cls);
 
-       static void request_completed_thunk(void *cls, struct MHD_Connection *connection, void **con_cls, enum MHD_RequestTerminationCode toe);
-
-       void request_completed(struct MHD_Connection *connection, void **con_cls, enum MHD_RequestTerminationCode toe);
-
 
        class Stream {
        public:
@@ -52,7 +48,7 @@ private:
                        FRAMING_RAW,
                        FRAMING_METACUBE
                };
-               Stream(Framing framing) : framing(framing) {}
+               Stream(HTTPD *parent, Framing framing) : parent(parent), framing(framing) {}
 
                static ssize_t reader_callback_thunk(void *cls, uint64_t pos, char *buf, size_t max);
                ssize_t reader_callback(uint64_t pos, char *buf, size_t max);
@@ -63,17 +59,22 @@ private:
                        DATA_TYPE_OTHER
                };
                void add_data(const char *buf, size_t size, DataType data_type);
+               void stop();
+               HTTPD *get_parent() const { return parent; }
 
        private:
+               HTTPD *parent;
                Framing framing;
 
                std::mutex buffer_mutex;
+               bool should_quit = false;  // Under <buffer_mutex>.
                std::condition_variable has_buffered_data;
-               std::deque<std::string> buffered_data;  // Protected by <mutex>.
+               std::deque<std::string> buffered_data;  // Protected by <buffer_mutex>.
                size_t used_of_buffered_data = 0;  // How many bytes of the first element of <buffered_data> that is already used. Protected by <mutex>.
                size_t seen_keyframe = false;
        };
 
+       MHD_Daemon *mhd = nullptr;
        std::mutex streams_mutex;
        std::set<Stream *> streams;  // Not owned.
        std::string header;