diff --git a/cocos/network/HttpClient.cpp b/cocos/network/HttpClient.cpp index 1765c470de..0ffa082df7 100644 --- a/cocos/network/HttpClient.cpp +++ b/cocos/network/HttpClient.cpp @@ -109,6 +109,8 @@ HttpClient::HttpClient() _service = new yasio::io_service(HttpClient::MAX_CHANNELS); _service->set_option(yasio::YOPT_S_DEFERRED_EVENT, 0); + _service->set_option(yasio::YOPT_S_DNS_QUERIES_TIMEOUT, 3); + _service->set_option(yasio::YOPT_S_DNS_QUERIES_TRIES, 1); _service->start([=](yasio::event_ptr&& e) { handleNetworkEvent(e.get()); }); for (int i = 0; i < HttpClient::MAX_CHANNELS; ++i) { @@ -141,6 +143,11 @@ void HttpClient::setDispatchOnWorkThread(bool bVal) _scheduler->schedule([=](float) { dispatchResponseCallbacks(); }, this, 0, false, "#"); } +void HttpClient::handleNetworkStatusChanged() +{ + _service->set_option(YOPT_S_DNS_DIRTY, 1); +} + bool HttpClient::send(HttpRequest* request) { if (!request) return false; diff --git a/cocos/network/HttpClient.h b/cocos/network/HttpClient.h index 572563675e..087c5ad655 100644 --- a/cocos/network/HttpClient.h +++ b/cocos/network/HttpClient.h @@ -188,6 +188,11 @@ public: void setDispatchOnWorkThread(bool bVal); bool isDispatchOnWorkThread() const { return _dispatchOnWorkThread; } + + /* + * When the device network status chagned, you should invoke this function + */ + void handleNetworkStatusChanged(); private: HttpClient(); diff --git a/thirdparty/yasio/detail/errc.hpp b/thirdparty/yasio/detail/errc.hpp new file mode 100644 index 0000000000..8cd526e1a1 --- /dev/null +++ b/thirdparty/yasio/detail/errc.hpp @@ -0,0 +1,47 @@ +////////////////////////////////////////////////////////////////////////////////////////// +// A multi-platform support c++11 library with focus on asynchronous socket I/O for any +// client application. +////////////////////////////////////////////////////////////////////////////////////////// +/* +The MIT License (MIT) +Copyright (c) 2012-2021 HALX99 +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ +#ifndef YAISO__ERRC_HPP +#define YAISO__ERRC_HPP + +namespace yasio +{ +namespace errc +{ +enum +{ + no_error = 0, // No error. + read_timeout = -28, // The remote host did not respond after a period of time. + invalid_packet = -27, // Invalid packet. + resolve_host_failed = -26, // Resolve host failed. + no_available_address = -25, // No available address to connect. + shutdown_by_localhost = -24, // Local shutdown the connection. + ssl_handshake_failed = -23, // SSL handshake failed. + ssl_write_failed = -22, // SSL write failed. + ssl_read_failed = -21, // SSL read failed. + eof = -20, // end of file. +}; +} +} // namespace yasio + +#endif diff --git a/thirdparty/yasio/yasio.hpp b/thirdparty/yasio/yasio.hpp index 810bc89f95..63ad9eb24c 100644 --- a/thirdparty/yasio/yasio.hpp +++ b/thirdparty/yasio/yasio.hpp @@ -48,6 +48,7 @@ SOFTWARE. #include "yasio/detail/select_interrupter.hpp" #include "yasio/detail/concurrent_queue.hpp" #include "yasio/detail/utils.hpp" +#include "yasio/detail/errc.hpp" #include "yasio/cxx17/memory.hpp" #include "yasio/cxx17/string_view.hpp" #include "yasio/xxsocket.hpp" @@ -154,8 +155,8 @@ enum // see also: YOPT_S_DNS_QUERIES_TIMEOUT YOPT_S_DNS_QUERIES_TIMEOUTMS, - // Set dns queries tries when timeout reached, default is: 5 - // params: dns_queries_tries : int(5) + // Set dns queries tries when timeout reached, default is: 4 + // params: dns_queries_tries : int(4) // remarks: // a. this option must be set before 'io_service::start' // b. relative option: YOPT_S_DNS_QUERIES_TIMEOUT @@ -300,23 +301,6 @@ enum YLOG_E, }; -namespace errc -{ -enum -{ - no_error = 0, // No error. - read_timeout = -28, // The remote host did not respond after a period of time. - invalid_packet = -27, // Invalid packet. - resolve_host_failed = -26, // Resolve host failed. - no_available_address = -25, // No available address to connect. - shutdown_by_localhost = -24, // Local shutdown the connection. - ssl_handshake_failed = -23, // SSL handshake failed. - ssl_write_failed = -22, // SSL write failed. - ssl_read_failed = -21, // SSL read failed. - eof = -20, // end of file. -}; -} - // class fwds class highp_timer; class io_send_op;