X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=cubemap.cpp;h=5ef003640ff1cc5780c6cd79c43687324193fcc6;hp=4ee5d6f3c4d6a95fcc5dfc556a437b5cf2077a76;hb=62d560b67de3a922bc26ef5c0c2a72a9a09e7905;hpb=fcdb2b3926312cbd42e2d45bb4cec8f984fb325c diff --git a/cubemap.cpp b/cubemap.cpp index 4ee5d6f..5ef0036 100644 --- a/cubemap.cpp +++ b/cubemap.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -17,6 +18,7 @@ #include "metacube.h" #include "server.h" #include "input.h" +#include "state.pb.h" #define NUM_SERVERS 4 #define STREAM_ID "stream" @@ -26,6 +28,12 @@ using namespace std; Server *servers = NULL; +volatile bool hupped = false; + +void hup(int ignored) +{ + hupped = true; +} int create_server_socket(int port) { @@ -35,7 +43,7 @@ int create_server_socket(int port) exit(1); } - int one; + int one = 1; if (setsockopt(server_sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) == -1) { perror("setsockopt(SO_REUSEADDR)"); exit(1); @@ -110,6 +118,32 @@ int main(int argc, char **argv) pthread_t acceptor_thread; pthread_create(&acceptor_thread, NULL, acceptor_thread_run, reinterpret_cast(server_sock)); - Input input(STREAM_ID); - input.run(STREAM_URL); + Input input(STREAM_ID, STREAM_URL); + input.run(); + + signal(SIGHUP, hup); + + while (!hupped) { + usleep(100000); + } + + input.stop(); + + CubemapStateProto state; + for (int i = 0; i < NUM_SERVERS; ++i) { + servers[i].stop(); + + CubemapStateProto local_state = servers[i].serialize(); + + // The stream state should be identical between the servers, so we only store it once. + if (i == 0) { + state.mutable_streams()->MergeFrom(local_state.streams()); + } + for (int j = 0; j < local_state.clients_size(); ++j) { + state.add_clients()->MergeFrom(local_state.clients(j)); + } + } + delete[] servers; + + printf("SERIALIZED: [%s]\n", state.DebugString().c_str()); }