From 0c8adc85f7373a85de8b3edc6cac87d5f7389bb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Fri, 11 Nov 2016 02:54:48 +0100 Subject: Move all the connect() logic from TCPSocketHandler into a subclass MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This way, TCPSocketHandler only deal with the message sending/receiving, not the connect() or anything else. This will be used for implementing servers (because when a client is accepted, we don’t need all the connect() and dns resolution stuff). --- louloulibs/network/dns_socket_handler.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'louloulibs/network/dns_socket_handler.cpp') diff --git a/louloulibs/network/dns_socket_handler.cpp b/louloulibs/network/dns_socket_handler.cpp index 403a5be..af39f49 100644 --- a/louloulibs/network/dns_socket_handler.cpp +++ b/louloulibs/network/dns_socket_handler.cpp @@ -40,6 +40,11 @@ bool DNSSocketHandler::is_connected() const return true; } +bool DNSSocketHandler::is_connecting() const +{ + return false; +} + void DNSSocketHandler::remove_from_poller() { if (this->poller->is_managing_socket(this->socket)) -- cgit v1.2.3 From 42e85d921b0c5e10889d93c24b7ebf355287ee71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Wed, 16 Nov 2016 23:07:27 +0100 Subject: Remove some useless virtual method from SocketHandler --- louloulibs/network/dns_socket_handler.cpp | 9 --------- 1 file changed, 9 deletions(-) (limited to 'louloulibs/network/dns_socket_handler.cpp') diff --git a/louloulibs/network/dns_socket_handler.cpp b/louloulibs/network/dns_socket_handler.cpp index af39f49..a69f59b 100644 --- a/louloulibs/network/dns_socket_handler.cpp +++ b/louloulibs/network/dns_socket_handler.cpp @@ -15,10 +15,6 @@ DNSSocketHandler::DNSSocketHandler(std::shared_ptr poller, { } -void DNSSocketHandler::connect() -{ -} - void DNSSocketHandler::on_recv() { // always stop watching send and read events. We will re-watch them if the @@ -40,11 +36,6 @@ bool DNSSocketHandler::is_connected() const return true; } -bool DNSSocketHandler::is_connecting() const -{ - return false; -} - void DNSSocketHandler::remove_from_poller() { if (this->poller->is_managing_socket(this->socket)) -- cgit v1.2.3 From 5b56007828f20c763df3f36ceed809188880663e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Fri, 6 Jan 2017 22:58:18 +0100 Subject: Use udns instead of c-ares fix #3226 --- louloulibs/network/dns_socket_handler.cpp | 32 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'louloulibs/network/dns_socket_handler.cpp') diff --git a/louloulibs/network/dns_socket_handler.cpp b/louloulibs/network/dns_socket_handler.cpp index a69f59b..ad744a9 100644 --- a/louloulibs/network/dns_socket_handler.cpp +++ b/louloulibs/network/dns_socket_handler.cpp @@ -1,34 +1,27 @@ #include -#ifdef CARES_FOUND +#ifdef UDNS_FOUND #include #include #include -#include +#include DNSSocketHandler::DNSSocketHandler(std::shared_ptr poller, - DNSHandler& handler, const socket_t socket): - SocketHandler(poller, socket), - handler(handler) + SocketHandler(poller, socket) { + poller->add_socket_handler(this); } -void DNSSocketHandler::on_recv() +DNSSocketHandler::~DNSSocketHandler() { - // always stop watching send and read events. We will re-watch them if the - // next call to ares_fds tell us to - this->handler.remove_all_sockets_from_poller(); - ::ares_process_fd(DNSHandler::instance.get_channel(), this->socket, ARES_SOCKET_BAD); + this->unwatch(); } -void DNSSocketHandler::on_send() +void DNSSocketHandler::on_recv() { - // always stop watching send and read events. We will re-watch them if the - // next call to ares_fds tell us to - this->handler.remove_all_sockets_from_poller(); - ::ares_process_fd(DNSHandler::instance.get_channel(), ARES_SOCKET_BAD, this->socket); + dns_ioevent(nullptr, 0); } bool DNSSocketHandler::is_connected() const @@ -36,10 +29,15 @@ bool DNSSocketHandler::is_connected() const return true; } -void DNSSocketHandler::remove_from_poller() +void DNSSocketHandler::unwatch() { if (this->poller->is_managing_socket(this->socket)) this->poller->remove_socket_handler(this->socket); } -#endif /* CARES_FOUND */ +void DNSSocketHandler::watch() +{ + this->poller->add_socket_handler(this); +} + +#endif /* UDNS_FOUND */ -- cgit v1.2.3 From f0bc6c83a8eb548d0a3edbf7c16a6922bfd24ba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Wed, 8 Mar 2017 19:04:15 +0100 Subject: Pass the shared_ptr by reference, to avoid useless copies --- louloulibs/network/dns_socket_handler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'louloulibs/network/dns_socket_handler.cpp') diff --git a/louloulibs/network/dns_socket_handler.cpp b/louloulibs/network/dns_socket_handler.cpp index ad744a9..84e5625 100644 --- a/louloulibs/network/dns_socket_handler.cpp +++ b/louloulibs/network/dns_socket_handler.cpp @@ -7,7 +7,7 @@ #include -DNSSocketHandler::DNSSocketHandler(std::shared_ptr poller, +DNSSocketHandler::DNSSocketHandler(std::shared_ptr& poller, const socket_t socket): SocketHandler(poller, socket) { -- cgit v1.2.3 From 0ab40dc1ab4e689921da54080b135e1d22b1c586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 14 Mar 2017 21:45:23 +0100 Subject: Refactoring louloulibs and cmake Use OBJECT libraries Remove the louloulibs directory Write FOUND variables in the cache --- louloulibs/network/dns_socket_handler.cpp | 43 ------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 louloulibs/network/dns_socket_handler.cpp (limited to 'louloulibs/network/dns_socket_handler.cpp') diff --git a/louloulibs/network/dns_socket_handler.cpp b/louloulibs/network/dns_socket_handler.cpp deleted file mode 100644 index 84e5625..0000000 --- a/louloulibs/network/dns_socket_handler.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -#ifdef UDNS_FOUND - -#include -#include -#include - -#include - -DNSSocketHandler::DNSSocketHandler(std::shared_ptr& poller, - const socket_t socket): - SocketHandler(poller, socket) -{ - poller->add_socket_handler(this); -} - -DNSSocketHandler::~DNSSocketHandler() -{ - this->unwatch(); -} - -void DNSSocketHandler::on_recv() -{ - dns_ioevent(nullptr, 0); -} - -bool DNSSocketHandler::is_connected() const -{ - return true; -} - -void DNSSocketHandler::unwatch() -{ - if (this->poller->is_managing_socket(this->socket)) - this->poller->remove_socket_handler(this->socket); -} - -void DNSSocketHandler::watch() -{ - this->poller->add_socket_handler(this); -} - -#endif /* UDNS_FOUND */ -- cgit v1.2.3