]> git.sesse.net Git - cubemap/blobdiff - cubemap.cpp
Fire off worker threads (that do nothing right now).
[cubemap] / cubemap.cpp
index 6095ce547b99d2a0c448b1d940e0cb4fc6c09aa8..9f5e42e6a23b0f5cff0c37b3fecaded17b13b522 100644 (file)
@@ -77,15 +77,52 @@ struct Stream {
 
 class Server {
 public:
+       Server();
+
+       // Start a new thread that handles clients.
+       void run();
        void add_socket(int server_sock);
        void add_stream(const string &stream_id);
        void set_header(const string &stream_id, const string &header);
        void add_data(const string &stream_id, const char *data, size_t bytes);
 
 private:
+       pthread_mutex_t mutex;
        map<string, Stream> streams;
+
+       // Recover the this pointer, and call do_work().
+       static void *do_work_thunk(void *arg);
+
+       // The actual worker thread.
+       void do_work();
 };
 
+Server::Server()
+{
+       pthread_mutex_init(&mutex, NULL);
+}
+
+void Server::run()
+{
+       pthread_t thread;
+       pthread_create(&thread, NULL, Server::do_work_thunk, this);
+}
+
+void *Server::do_work_thunk(void *arg)
+{
+       Server *server = static_cast<Server *>(arg);
+       server->do_work();
+       return NULL;
+}
+
+void Server::do_work()
+{
+       for ( ;; ) {
+               printf("server thread running\n");
+               sleep(1);
+       }
+}
+
 class Input {
 public:
        Input();
@@ -168,7 +205,7 @@ void Input::process_block(const char *data, uint32_t size, uint32_t flags)
        // TODO: treat it right here
        printf("Block: %d bytes, flags=0x%x\n", size, flags);
 }
-                       
+
 void Input::drop_pending_data(size_t num_bytes)
 {
        if (num_bytes == 0) {
@@ -240,11 +277,13 @@ void *acceptor_thread_run(void *arg)
        }
 }
 
+Server *servers = NULL;
+
 int main(int argc, char **argv)
 {
+       servers = new Server[NUM_SERVERS];
        for (int i = 0; i < NUM_SERVERS; ++i) {
-               Server *s = new Server;
-               //s->run();
+               servers[i].run();
        }
 
        int server_sock = create_server_socket(PORT);