+}
+
+int main(int argc, char **argv)
+{
+ fprintf(stderr, "\nCubemap starting.\n");
+
+ struct timeval serialize_start;
+ bool is_reexec = false;
+
+ string config_filename = (argc == 1) ? "cubemap.config" : argv[1];
+ vector<ConfigLine> config = parse_config(config_filename);
+
+ int port = fetch_config_int(config, "port", 1, 65535, PARAMATER_MANDATORY);
+ int num_servers = fetch_config_int(config, "num_servers", 1, 20000, PARAMATER_MANDATORY); // Insanely high max limit.
+
+ servers = new ServerPool(num_servers);
+
+ CubemapStateProto loaded_state;
+ int server_sock = -1, old_port = -1;
+ set<string> deserialized_stream_ids;
+ map<string, Input *> deserialized_inputs;
+ if (argc == 4 && strcmp(argv[2], "-state") == 0) {
+ is_reexec = true;
+
+ fprintf(stderr, "Deserializing state from previous process... ");
+ int state_fd = atoi(argv[3]);
+ loaded_state = read_tempfile(state_fd);
+
+ serialize_start.tv_sec = loaded_state.serialize_start_sec();
+ serialize_start.tv_usec = loaded_state.serialize_start_usec();
+
+ // Deserialize the streams.
+ for (int i = 0; i < loaded_state.streams_size(); ++i) {
+ servers->add_stream_from_serialized(loaded_state.streams(i));
+ deserialized_stream_ids.insert(loaded_state.streams(i).stream_id());
+ }
+
+ // Deserialize the inputs. Note that we don't actually add them to any state yet.
+ for (int i = 0; i < loaded_state.inputs_size(); ++i) {
+ deserialized_inputs.insert(make_pair(
+ loaded_state.inputs(i).stream_id(),
+ new Input(loaded_state.inputs(i))));
+ }
+
+ // Deserialize the server socket.
+ server_sock = loaded_state.server_sock();
+ old_port = loaded_state.port();
+
+ fprintf(stderr, "done.\n");
+ }
+
+ // Find all streams in the configuration file, and create them.
+ create_streams(config, deserialized_stream_ids, &deserialized_inputs);