+ int server_sock;
+ if (argc == 4 && strcmp(argv[2], "-state") == 0) {
+ fprintf(stderr, "Deserializing state from previous process... ");
+ int state_fd = atoi(argv[3]);
+ CubemapStateProto loaded_state = read_tempfile(state_fd);
+
+ // Deserialize the streams.
+ for (int i = 0; i < loaded_state.streams_size(); ++i) {
+ for (int j = 0; j < NUM_SERVERS; ++j) {
+ servers[j].add_stream_from_serialized(loaded_state.streams(i));
+ }
+ }
+
+ // Put back the existing clients. It doesn't matter which server we
+ // allocate them to, so just do round-robin.
+ for (int i = 0; i < loaded_state.clients_size(); ++i) {
+ servers[i % NUM_SERVERS].add_client_from_serialized(loaded_state.clients(i));
+ }
+
+ // Deserialize the server socket.
+ server_sock = loaded_state.server_sock();
+
+ fprintf(stderr, "done.\n");
+ } else {
+ server_sock = create_server_socket(port);
+
+ // TODO: This should come from the config file.
+ for (int i = 0; i < NUM_SERVERS; ++i) {
+ servers[i].add_stream(STREAM_ID);
+ }