Commit de0eff6e authored by louiz’'s avatar louiz’

Revert "Don’t use unique_ptr to store dns socket handlers"

This reverts commit 5328d080.
parent c7e4fc13
......@@ -68,7 +68,7 @@ void DNSHandler::watch_dns_sockets(std::shared_ptr<Poller>& poller)
std::remove_if(this->socket_handlers.begin(), this->socket_handlers.end(),
[&readers](const auto& dns_socket)
{
return !FD_ISSET(dns_socket.get_socket(), &readers);
return !FD_ISSET(dns_socket->get_socket(), &readers);
}),
this->socket_handlers.end());
......@@ -81,8 +81,8 @@ void DNSHandler::watch_dns_sockets(std::shared_ptr<Poller>& poller)
this->socket_handlers.end(),
[i](const auto& socket_handler)
{
return i == socket_handler.get_socket();
});
return i == socket_handler->get_socket();
});
if (!read && !write) // No need to read or write to it
{ // If found, erase it and stop watching it because it is not
// needed anymore
......@@ -95,12 +95,12 @@ void DNSHandler::watch_dns_sockets(std::shared_ptr<Poller>& poller)
if (it == this->socket_handlers.end())
{
this->socket_handlers.emplace(this->socket_handlers.begin(),
poller, i);
std::make_unique<DNSSocketHandler>(poller, i));
it = this->socket_handlers.begin();
}
poller->add_socket_handler(&*it);
poller->add_socket_handler(it->get());
if (write)
poller->watch_send_events(&*it);
poller->watch_send_events(it->get());
}
}
// Cancel previous timer, if any.
......@@ -116,7 +116,7 @@ void DNSHandler::watch_dns_sockets(std::shared_ptr<Poller>& poller)
[this]()
{
for (auto& dns_socket_handler: this->socket_handlers)
dns_socket_handler.on_recv();
dns_socket_handler->on_recv();
},
"DNS timeout"));
}
......
......@@ -50,7 +50,7 @@ private:
* call to ares_fds. DNSSocketHandlers are added to it or removed from it
* in the watch_dns_sockets() method
*/
std::vector<DNSSocketHandler> socket_handlers;
std::vector<std::unique_ptr<DNSSocketHandler>> socket_handlers;
ares_channel channel;
};
......
......@@ -18,10 +18,10 @@ class DNSSocketHandler: public SocketHandler
public:
explicit DNSSocketHandler(std::shared_ptr<Poller> poller, const socket_t socket);
~DNSSocketHandler() = default;
DNSSocketHandler(DNSSocketHandler&&) = default;
DNSSocketHandler& operator=(DNSSocketHandler&&) = default;
DNSSocketHandler(const DNSSocketHandler&) = delete;
DNSSocketHandler(DNSSocketHandler&&) = delete;
DNSSocketHandler& operator=(const DNSSocketHandler&) = delete;
DNSSocketHandler& operator=(DNSSocketHandler&&) = delete;
/**
* Just call dns_process_fd, c-ares will do its work of send()ing or
......
......@@ -15,10 +15,10 @@ public:
socket(socket)
{}
virtual ~SocketHandler() {}
SocketHandler& operator=(SocketHandler&&) = default;
SocketHandler(SocketHandler&&) = default;
SocketHandler& operator=(const SocketHandler&) = delete;
SocketHandler(const SocketHandler&) = delete;
SocketHandler(SocketHandler&&) = delete;
SocketHandler& operator=(const SocketHandler&) = delete;
SocketHandler& operator=(SocketHandler&&) = delete;
virtual void on_recv() = 0;
virtual void on_send() = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment