{
for (unsigned i = 0; i < config.streams.size(); ++i) {
const StreamConfig &stream_config = config.streams[i];
- create_config_input(stream_config.src, inputs);
+ if (stream_config.src != "delete") {
+ create_config_input(stream_config.src, inputs);
+ }
}
for (unsigned i = 0; i < config.udpstreams.size(); ++i) {
const UDPStreamConfig &udpstream_config = config.udpstreams[i];
for (unsigned i = 0; i < config.streams.size(); ++i) {
const StreamConfig &stream_config = config.streams[i];
int stream_index;
+
+ expecting_urls.erase(stream_config.url);
+
+ // Special-case deleted streams; they were never deserialized in the first place,
+ // so just ignore them.
+ if (stream_config.src == "delete") {
+ continue;
+ }
+
if (deserialized_urls.count(stream_config.url) == 0) {
stream_index = servers->add_stream(stream_config.url,
stream_config.backlog_size,
servers->set_encoding(stream_index,
Stream::Encoding(stream_config.encoding));
}
- expecting_urls.erase(stream_config.url);
if (stream_config.mark_pool != -1) {
servers->set_mark_pool(stream_index, mark_pools[stream_config.mark_pool]);
}
}
- // Warn about any HTTP servers we've lost.
- // TODO: Make an option (delete=yes?) to actually shut down streams.
+ // Warn about any streams servers we've lost.
for (set<string>::const_iterator stream_it = expecting_urls.begin();
stream_it != expecting_urls.end();
++stream_it) {
string url = *stream_it;
log(WARNING, "stream '%s' disappeared from the configuration file. "
- "It will not be deleted, but clients will not get any new inputs.",
+ "It will not be deleted, but clients will not get any new inputs. "
+ "If you really meant to delete it, set src=delete and reload.",
url.c_str());
}
return (WIFEXITED(status) && WEXITSTATUS(status) == 0);
}
+void find_deleted_streams(const Config &config, set<string> *deleted_urls)
+{
+ for (unsigned i = 0; i < config.streams.size(); ++i) {
+ const StreamConfig &stream_config = config.streams[i];
+ if (stream_config.src == "delete") {
+ log(INFO, "Deleting stream '%s'.", stream_config.url.c_str());
+ deleted_urls->insert(stream_config.url);
+ }
+ }
+}
+
int main(int argc, char **argv)
{
signal(SIGHUP, hup);
servers = new ServerPool(config.num_servers);
+ // Find all the streams that are to be deleted.
+ set<string> deleted_urls;
+ find_deleted_streams(config, &deleted_urls);
+
CubemapStateProto loaded_state;
struct timeval serialize_start;
set<string> deserialized_urls;
for (int i = 0; i < loaded_state.streams_size(); ++i) {
const StreamProto &stream = loaded_state.streams(i);
- vector<int> data_fds;
- for (int j = 0; j < stream.data_fds_size(); ++j) {
- data_fds.push_back(stream.data_fds(j));
+ if (deleted_urls.count(stream.url()) != 0) {
+ // Delete the stream backlogs.
+ for (int j = 0; j < stream.data_fds_size(); ++j) {
+ safe_close(stream.data_fds(j));
+ }
+ } else {
+ vector<int> data_fds;
+ for (int j = 0; j < stream.data_fds_size(); ++j) {
+ data_fds.push_back(stream.data_fds(j));
+ }
+
+ // Older versions stored the data once in the protobuf instead of
+ // sending around file descriptors.
+ if (data_fds.empty() && stream.has_data()) {
+ data_fds.push_back(make_tempfile(stream.data()));
+ }
+
+ servers->add_stream_from_serialized(stream, data_fds);
+ deserialized_urls.insert(stream.url());
}
-
- // Older versions stored the data once in the protobuf instead of
- // sending around file descriptors.
- if (data_fds.empty() && stream.has_data()) {
- data_fds.push_back(make_tempfile(stream.data()));
- }
-
- servers->add_stream_from_serialized(stream, data_fds);
- deserialized_urls.insert(stream.url());
}
// Deserialize the inputs. Note that we don't actually add them to any stream yet.
// allocate them to, so just do round-robin. However, we need to add
// them after the mark pools have been set up.
for (int i = 0; i < loaded_state.clients_size(); ++i) {
- servers->add_client_from_serialized(loaded_state.clients(i));
+ if (deleted_urls.count(loaded_state.clients(i).url()) != 0) {
+ safe_close(loaded_state.clients(i).sock());
+ } else {
+ servers->add_client_from_serialized(loaded_state.clients(i));
+ }
}
servers->run();