mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2026-04-24 00:00:05 +08:00
e9b9b66317
daf575ff50 Merge remote-tracking branch 'origin/qa' e3a2425be4 [UCONNECT-1027] remotelist: create standalone object for resolve thread e487b75860 async-resolve: use native GCD implementation on iOS 346ed043fa Merge remote-tracking branch 'origin/qa' 3f55dcd266 remotelist: add missing includes 073b3993f4 Fix commit 8b22a7b2 (mbed TLS compatibility) 8b22a7b209 Fix compatibility with mbed TLS < 2.7.0 git-subtree-dir: Sources/OpenVPNAdapter/Libraries/Vendors/openvpn git-subtree-split: daf575ff5099eebb10109e52be94253507fd253b
75 lines
2.5 KiB
C++
75 lines
2.5 KiB
C++
// OpenVPN -- An application to securely tunnel IP networks
|
|
// over a single port, with support for SSL/TLS-based
|
|
// session authentication and key exchange,
|
|
// packet encryption, packet authentication, and
|
|
// packet compression.
|
|
//
|
|
// Copyright (C) 2012-2019 OpenVPN Inc.
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Affero General Public License Version 3
|
|
// as published by the Free Software Foundation.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Affero General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
// along with this program in the COPYING file.
|
|
// If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#ifndef OPENVPN_CLIENT_ASYNC_RESOLVE_GENERIC_H
|
|
#define OPENVPN_CLIENT_ASYNC_RESOLVE_GENERIC_H
|
|
|
|
#include <openvpn/common/bigmutex.hpp>
|
|
#include <openvpn/common/rc.hpp>
|
|
#include <openvpn/common/hostport.hpp>
|
|
|
|
|
|
namespace openvpn {
|
|
template<typename RESOLVER_TYPE>
|
|
class AsyncResolvable: public virtual RC<thread_unsafe_refcount>
|
|
{
|
|
private:
|
|
typedef RCPtr<AsyncResolvable> Ptr;
|
|
|
|
openvpn_io::io_context& io_context;
|
|
RESOLVER_TYPE resolver;
|
|
|
|
public:
|
|
AsyncResolvable(openvpn_io::io_context& io_context_arg)
|
|
: io_context(io_context_arg),
|
|
resolver(io_context_arg)
|
|
{
|
|
}
|
|
|
|
virtual void resolve_callback(const openvpn_io::error_code& error,
|
|
typename RESOLVER_TYPE::results_type results) = 0;
|
|
|
|
// This implementation assumes that the i/o reactor provides an asynchronous
|
|
// DNS resolution routine using its own primitives and that doesn't require
|
|
// us to take care of any non-interruptible opration (i.e. getaddrinfo() in
|
|
// case of ASIO).
|
|
//
|
|
// For example, iOS implements aync_resolve using GCD and CFHost. This
|
|
// implementation satisfies the constraints mentioned above
|
|
void async_resolve_name(const std::string& host, const std::string& port)
|
|
{
|
|
resolver.async_resolve(host, port, [self=Ptr(this)](const openvpn_io::error_code& error,
|
|
typename RESOLVER_TYPE::results_type results)
|
|
{
|
|
OPENVPN_ASYNC_HANDLER;
|
|
self->resolve_callback(error, results);
|
|
});
|
|
}
|
|
|
|
void async_resolve_cancel()
|
|
{
|
|
resolver.cancel();
|
|
}
|
|
};
|
|
}
|
|
|
|
#endif /* OPENVPN_CLIENT_ASYNC_RESOLVE_GENERIC_H */
|