Commit f0bc6c83 authored by louiz’'s avatar louiz’

Pass the shared_ptr by reference, to avoid useless copies

parent cd92baae
......@@ -17,7 +17,7 @@ using namespace std::string_literals;
std::unique_ptr<DNSSocketHandler> DNSHandler::socket_handler{};
DNSHandler::DNSHandler(std::shared_ptr<Poller> poller)
DNSHandler::DNSHandler(std::shared_ptr<Poller>& poller)
{
dns_init(nullptr, 0);
const auto socket = dns_open(nullptr);
......
......@@ -14,7 +14,7 @@ class Poller;
class DNSHandler
{
public:
explicit DNSHandler(std::shared_ptr<Poller> poller);
explicit DNSHandler(std::shared_ptr<Poller>& poller);
~DNSHandler() = default;
DNSHandler(const DNSHandler&) = delete;
......
......@@ -7,7 +7,7 @@
#include <udns.h>
DNSSocketHandler::DNSSocketHandler(std::shared_ptr<Poller> poller,
DNSSocketHandler::DNSSocketHandler(std::shared_ptr<Poller>& poller,
const socket_t socket):
SocketHandler(poller, socket)
{
......
......@@ -12,7 +12,7 @@
class DNSSocketHandler: public SocketHandler
{
public:
explicit DNSSocketHandler(std::shared_ptr<Poller> poller, const socket_t socket);
explicit DNSSocketHandler(std::shared_ptr<Poller>& poller, const socket_t socket);
~DNSSocketHandler();
DNSSocketHandler(const DNSSocketHandler&) = delete;
DNSSocketHandler(DNSSocketHandler&&) = delete;
......
......@@ -10,7 +10,7 @@ using socket_t = int;
class SocketHandler
{
public:
explicit SocketHandler(std::shared_ptr<Poller> poller, const socket_t socket):
explicit SocketHandler(std::shared_ptr<Poller>& poller, const socket_t socket):
poller(poller),
socket(socket)
{}
......
......@@ -11,7 +11,7 @@
using namespace std::string_literals;
TCPClientSocketHandler::TCPClientSocketHandler(std::shared_ptr<Poller> poller):
TCPClientSocketHandler::TCPClientSocketHandler(std::shared_ptr<Poller>& poller):
TCPSocketHandler(poller),
hostname_resolution_failed(false),
connected(false),
......
......@@ -5,7 +5,7 @@
class TCPClientSocketHandler: public TCPSocketHandler
{
public:
TCPClientSocketHandler(std::shared_ptr<Poller> poller);
TCPClientSocketHandler(std::shared_ptr<Poller>& poller);
~TCPClientSocketHandler();
/**
* Connect to the remote server, and call on_connected() if this
......
......@@ -18,7 +18,7 @@ template <typename RemoteSocketType>
class TcpSocketServer: public SocketHandler
{
public:
TcpSocketServer(std::shared_ptr<Poller> poller, const uint16_t port):
TcpSocketServer(std::shared_ptr<Poller>& poller, const uint16_t port):
SocketHandler(poller, -1)
{
if ((this->socket = ::socket(AF_INET6, SOCK_STREAM, 0)) == -1)
......
......@@ -44,7 +44,7 @@ using namespace std::chrono_literals;
namespace ph = std::placeholders;
TCPSocketHandler::TCPSocketHandler(std::shared_ptr<Poller> poller):
TCPSocketHandler::TCPSocketHandler(std::shared_ptr<Poller>& poller):
SocketHandler(poller, -1),
use_tls(false)
#ifdef BOTAN_FOUND
......
......@@ -60,7 +60,7 @@ class TCPSocketHandler: public SocketHandler
protected:
~TCPSocketHandler();
public:
explicit TCPSocketHandler(std::shared_ptr<Poller> poller);
explicit TCPSocketHandler(std::shared_ptr<Poller>& poller);
TCPSocketHandler(const TCPSocketHandler&) = delete;
TCPSocketHandler(TCPSocketHandler&&) = delete;
TCPSocketHandler& operator=(const TCPSocketHandler&) = delete;
......
......@@ -39,7 +39,7 @@ static std::set<std::string> kickable_errors{
"malformed-error"
};
XmppComponent::XmppComponent(std::shared_ptr<Poller> poller, const std::string& hostname, const std::string& secret):
XmppComponent::XmppComponent(std::shared_ptr<Poller>& poller, const std::string& hostname, const std::string& secret):
TCPClientSocketHandler(poller),
ever_auth(false),
first_connection_try(true),
......
......@@ -43,7 +43,7 @@
class XmppComponent: public TCPClientSocketHandler
{
public:
explicit XmppComponent(std::shared_ptr<Poller> poller, const std::string& hostname, const std::string& secret);
explicit XmppComponent(std::shared_ptr<Poller>& poller, const std::string& hostname, const std::string& secret);
virtual ~XmppComponent() = default;
XmppComponent(const XmppComponent&) = delete;
......
......@@ -29,7 +29,7 @@ static std::string in_encoding_for(const Bridge& bridge, const Iid& iid)
#endif
}
Bridge::Bridge(const std::string& user_jid, BiboumiComponent& xmpp, std::shared_ptr<Poller> poller):
Bridge::Bridge(const std::string& user_jid, BiboumiComponent& xmpp, std::shared_ptr<Poller>& poller):
user_jid(user_jid),
xmpp(xmpp),
poller(poller)
......
......@@ -38,7 +38,7 @@ using irc_responder_callback_t = std::function<bool(const std::string& irc_hostn
class Bridge
{
public:
explicit Bridge(const std::string& user_jid, BiboumiComponent& xmpp, std::shared_ptr<Poller> poller);
explicit Bridge(const std::string& user_jid, BiboumiComponent& xmpp, std::shared_ptr<Poller>& poller);
~Bridge() = default;
Bridge(const Bridge&) = delete;
......
......@@ -10,7 +10,7 @@ class BiboumiComponent;
class IdentdServer: public TcpSocketServer<IdentdSocket>
{
public:
IdentdServer(const BiboumiComponent& biboumi_component, std::shared_ptr<Poller> poller, const uint16_t port):
IdentdServer(const BiboumiComponent& biboumi_component, std::shared_ptr<Poller>& poller, const uint16_t port):
TcpSocketServer<IdentdSocket>(poller, port),
biboumi_component(biboumi_component)
{}
......
......@@ -8,7 +8,7 @@
#include <logger/logger.hpp>
IdentdSocket::IdentdSocket(std::shared_ptr<Poller> poller, const socket_t socket, TcpSocketServer<IdentdSocket>& server):
IdentdSocket::IdentdSocket(std::shared_ptr<Poller>& poller, const socket_t socket, TcpSocketServer<IdentdSocket>& server):
TCPSocketHandler(poller),
server(dynamic_cast<IdentdServer&>(server))
{
......
......@@ -17,7 +17,7 @@ class TcpSocketServer;
class IdentdSocket: public TCPSocketHandler
{
public:
IdentdSocket(std::shared_ptr<Poller> poller, const socket_t socket, TcpSocketServer<IdentdSocket>& server);
IdentdSocket(std::shared_ptr<Poller>& poller, const socket_t socket, TcpSocketServer<IdentdSocket>& server);
~IdentdSocket() = default;
std::string generate_answer(const BiboumiComponent& biboumi, uint16_t local, uint16_t remote);
......
......@@ -128,7 +128,7 @@ static const std::unordered_map<std::string,
{"502", {&IrcClient::on_generic_error, {2, 0}}},
};
IrcClient::IrcClient(std::shared_ptr<Poller> poller, const std::string& hostname,
IrcClient::IrcClient(std::shared_ptr<Poller>& poller, const std::string& hostname,
const std::string& nickname, const std::string& username,
const std::string& realname, const std::string& user_hostname,
Bridge& bridge):
......
......@@ -26,7 +26,7 @@ class Bridge;
class IrcClient: public TCPClientSocketHandler
{
public:
explicit IrcClient(std::shared_ptr<Poller> poller, const std::string& hostname,
explicit IrcClient(std::shared_ptr<Poller>& poller, const std::string& hostname,
const std::string& nickname, const std::string& username,
const std::string& realname, const std::string& user_hostname,
Bridge& bridge);
......
......@@ -44,7 +44,7 @@ static std::set<std::string> kickable_errors{
};
BiboumiComponent::BiboumiComponent(std::shared_ptr<Poller> poller, const std::string& hostname, const std::string& secret):
BiboumiComponent::BiboumiComponent(std::shared_ptr<Poller>& poller, const std::string& hostname, const std::string& secret):
XmppComponent(poller, hostname, secret),
irc_server_adhoc_commands_handler(*this),
irc_channel_adhoc_commands_handler(*this)
......
......@@ -27,7 +27,7 @@ using iq_responder_callback_t = std::function<void(Bridge* bridge, const Stanza&
class BiboumiComponent: public XmppComponent
{
public:
explicit BiboumiComponent(std::shared_ptr<Poller> poller, const std::string& hostname, const std::string& secret);
explicit BiboumiComponent(std::shared_ptr<Poller>& poller, const std::string& hostname, const std::string& secret);
~BiboumiComponent() = default;
BiboumiComponent(const BiboumiComponent&) = delete;
......
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