+int main(int argc, char **argv)
+{
+ fprintf(stderr, "\nCubemap " SERVER_VERSION " 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 num_servers = fetch_config_int(config, "num_servers", 1, 20000, PARAMATER_MANDATORY); // Insanely high max limit.
+
+ servers = new ServerPool(num_servers);
+
+ CubemapStateProto loaded_state;
+ set<string> deserialized_stream_ids;
+ map<string, Input *> deserialized_inputs;
+ map<int, Acceptor *> deserialized_acceptors;
+ 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(),
+ create_input(loaded_state.inputs(i))));
+ }
+
+ // Convert the acceptor from older serialized formats.
+ if (loaded_state.has_server_sock() && loaded_state.has_port()) {
+ AcceptorProto *acceptor = loaded_state.add_acceptors();
+ acceptor->set_server_sock(loaded_state.server_sock());
+ acceptor->set_port(loaded_state.port());
+ }
+
+ // Deserialize the acceptors.
+ for (int i = 0; i < loaded_state.acceptors_size(); ++i) {
+ deserialized_acceptors.insert(make_pair(
+ loaded_state.acceptors(i).port(),
+ new Acceptor(loaded_state.acceptors(i))));
+ }
+
+ fprintf(stderr, "done.\n");