Server::~Server()
{
- for (Stream *stream : streams) {
- delete stream;
- }
-
safe_close(epoll_fd);
}
// Process each client where its stream has new data,
// even if there was no socket activity.
- for (Stream *stream : streams) {
+ for (unique_ptr<Stream> &stream : streams) {
vector<Client *> to_process;
swap(stream->to_process, to_process);
for (Client *client : to_process) {
for (const auto &fd_and_client : clients) {
serialized.add_clients()->MergeFrom(fd_and_client.second.serialize());
}
- for (Stream *stream : streams) {
+ for (unique_ptr<Stream> &stream : streams) {
serialized.add_streams()->MergeFrom(stream->serialize());
}
return serialized;
assert(client.state() != Client::SENDING_DATA);
stream = NULL;
} else {
- stream = streams[stream_index];
+ stream = streams[stream_index].get();
}
auto inserted = clients.insert(make_pair(client.sock(), Client(client, stream)));
assert(inserted.second == true); // Should not already exist.
{
MutexLock lock(&mutex);
stream_url_map.insert(make_pair(url, streams.size()));
- streams.push_back(new Stream(url, backlog_size, prebuffering_bytes, encoding, src_encoding));
+ streams.emplace_back(new Stream(url, backlog_size, prebuffering_bytes, encoding, src_encoding));
return streams.size() - 1;
}
{
MutexLock lock(&mutex);
stream_url_map.insert(make_pair(stream.url(), streams.size()));
- streams.push_back(new Stream(stream, data_fd));
+ streams.emplace_back(new Stream(stream, data_fd));
return streams.size() - 1;
}
}
}
- Stream *stream = streams[stream_url_map_it->second];
+ Stream *stream = streams[stream_url_map_it->second].get();
if (stream->http_header.empty()) {
return 503; // Service unavailable.
}
queued_add_clients.clear();
}
- for (Stream *stream : streams) {
+ for (unique_ptr<Stream> &stream : streams) {
stream->process_queued_data();
}
}