mirror of https://github.com/axmolengine/axmol.git
Add HttpClient::handleNetworkStatusChanged to clear DNS cache
This commit is contained in:
parent
ab6b36d5f9
commit
71c17cfc9b
|
@ -109,6 +109,8 @@ HttpClient::HttpClient()
|
||||||
|
|
||||||
_service = new yasio::io_service(HttpClient::MAX_CHANNELS);
|
_service = new yasio::io_service(HttpClient::MAX_CHANNELS);
|
||||||
_service->set_option(yasio::YOPT_S_DEFERRED_EVENT, 0);
|
_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()); });
|
_service->start([=](yasio::event_ptr&& e) { handleNetworkEvent(e.get()); });
|
||||||
|
|
||||||
for (int i = 0; i < HttpClient::MAX_CHANNELS; ++i) {
|
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, "#");
|
_scheduler->schedule([=](float) { dispatchResponseCallbacks(); }, this, 0, false, "#");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HttpClient::handleNetworkStatusChanged()
|
||||||
|
{
|
||||||
|
_service->set_option(YOPT_S_DNS_DIRTY, 1);
|
||||||
|
}
|
||||||
|
|
||||||
bool HttpClient::send(HttpRequest* request) {
|
bool HttpClient::send(HttpRequest* request) {
|
||||||
if (!request)
|
if (!request)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -188,6 +188,11 @@ public:
|
||||||
|
|
||||||
void setDispatchOnWorkThread(bool bVal);
|
void setDispatchOnWorkThread(bool bVal);
|
||||||
bool isDispatchOnWorkThread() const { return _dispatchOnWorkThread; }
|
bool isDispatchOnWorkThread() const { return _dispatchOnWorkThread; }
|
||||||
|
|
||||||
|
/*
|
||||||
|
* When the device network status chagned, you should invoke this function
|
||||||
|
*/
|
||||||
|
void handleNetworkStatusChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HttpClient();
|
HttpClient();
|
||||||
|
|
|
@ -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
|
|
@ -48,6 +48,7 @@ SOFTWARE.
|
||||||
#include "yasio/detail/select_interrupter.hpp"
|
#include "yasio/detail/select_interrupter.hpp"
|
||||||
#include "yasio/detail/concurrent_queue.hpp"
|
#include "yasio/detail/concurrent_queue.hpp"
|
||||||
#include "yasio/detail/utils.hpp"
|
#include "yasio/detail/utils.hpp"
|
||||||
|
#include "yasio/detail/errc.hpp"
|
||||||
#include "yasio/cxx17/memory.hpp"
|
#include "yasio/cxx17/memory.hpp"
|
||||||
#include "yasio/cxx17/string_view.hpp"
|
#include "yasio/cxx17/string_view.hpp"
|
||||||
#include "yasio/xxsocket.hpp"
|
#include "yasio/xxsocket.hpp"
|
||||||
|
@ -154,8 +155,8 @@ enum
|
||||||
// see also: YOPT_S_DNS_QUERIES_TIMEOUT
|
// see also: YOPT_S_DNS_QUERIES_TIMEOUT
|
||||||
YOPT_S_DNS_QUERIES_TIMEOUTMS,
|
YOPT_S_DNS_QUERIES_TIMEOUTMS,
|
||||||
|
|
||||||
// Set dns queries tries when timeout reached, default is: 5
|
// Set dns queries tries when timeout reached, default is: 4
|
||||||
// params: dns_queries_tries : int(5)
|
// params: dns_queries_tries : int(4)
|
||||||
// remarks:
|
// remarks:
|
||||||
// a. this option must be set before 'io_service::start'
|
// a. this option must be set before 'io_service::start'
|
||||||
// b. relative option: YOPT_S_DNS_QUERIES_TIMEOUT
|
// b. relative option: YOPT_S_DNS_QUERIES_TIMEOUT
|
||||||
|
@ -300,23 +301,6 @@ enum
|
||||||
YLOG_E,
|
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 fwds
|
||||||
class highp_timer;
|
class highp_timer;
|
||||||
class io_send_op;
|
class io_send_op;
|
||||||
|
|
Loading…
Reference in New Issue