#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/epoll.h>
+#include <signal.h>
#include <errno.h>
#include <vector>
#include <string>
#include "metacube.h"
#include "server.h"
#include "input.h"
+#include "state.pb.h"
#define NUM_SERVERS 4
#define STREAM_ID "stream"
using namespace std;
Server *servers = NULL;
+volatile bool hupped = false;
+
+void hup(int ignored)
+{
+ hupped = true;
+}
int create_server_socket(int port)
{
exit(1);
}
+ int one = 1;
+ if (setsockopt(server_sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) == -1) {
+ perror("setsockopt(SO_REUSEADDR)");
+ exit(1);
+ }
+
// We want dual-stack sockets. (Sorry, OpenBSD and Windows XP...)
int zero = 0;
if (setsockopt(server_sock, IPPROTO_IPV6, IPV6_V6ONLY, &zero, sizeof(zero)) == -1) {
pthread_t acceptor_thread;
pthread_create(&acceptor_thread, NULL, acceptor_thread_run, reinterpret_cast<void *>(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());
}