mirror of
https://github.com/OpenVPN/openvpn3.git
synced 2024-09-20 12:12:15 +02:00
Obsoleted asiodispatch in favor of C++11 lambdas.
This commit is contained in:
parent
df17015569
commit
1acc33feaf
@ -161,7 +161,10 @@ namespace openvpn {
|
||||
void thread_safe_stop()
|
||||
{
|
||||
if (!halt)
|
||||
io_service.post(asio_dispatch_post(&ClientConnect::graceful_stop, this));
|
||||
io_service.post([self=Ptr(this)]()
|
||||
{
|
||||
self->graceful_stop();
|
||||
});
|
||||
}
|
||||
|
||||
void pause(const std::string& reason)
|
||||
@ -203,26 +206,38 @@ namespace openvpn {
|
||||
OPENVPN_LOG("Client terminated, reconnecting in " << seconds << "...");
|
||||
server_poll_timer.cancel();
|
||||
restart_wait_timer.expires_at(Time::now() + Time::Duration::seconds(seconds));
|
||||
restart_wait_timer.async_wait(asio_dispatch_timer_arg(&ClientConnect::restart_wait_callback, this, generation));
|
||||
restart_wait_timer.async_wait([self=Ptr(this), gen=generation](const asio::error_code& error)
|
||||
{
|
||||
self->restart_wait_callback(gen, error);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void thread_safe_pause(const std::string& reason)
|
||||
{
|
||||
if (!halt)
|
||||
io_service.post(asio_dispatch_post_arg(&ClientConnect::pause, this, reason));
|
||||
io_service.post([self=Ptr(this), reason]()
|
||||
{
|
||||
self->pause(reason);
|
||||
});
|
||||
}
|
||||
|
||||
void thread_safe_resume()
|
||||
{
|
||||
if (!halt)
|
||||
io_service.post(asio_dispatch_post(&ClientConnect::resume, this));
|
||||
io_service.post([self=Ptr(this)]()
|
||||
{
|
||||
self->resume();
|
||||
});
|
||||
}
|
||||
|
||||
void thread_safe_reconnect(int seconds)
|
||||
{
|
||||
if (!halt)
|
||||
io_service.post(asio_dispatch_post_arg(&ClientConnect::reconnect, this, seconds));
|
||||
io_service.post([self=Ptr(this), seconds]()
|
||||
{
|
||||
self->reconnect(seconds);
|
||||
});
|
||||
}
|
||||
|
||||
void dont_restart()
|
||||
@ -307,7 +322,10 @@ namespace openvpn {
|
||||
if (!conn_timer_pending && conn_timeout > 0)
|
||||
{
|
||||
conn_timer.expires_at(Time::now() + Time::Duration::seconds(conn_timeout));
|
||||
conn_timer.async_wait(asio_dispatch_timer_arg(&ClientConnect::conn_timer_callback, this, generation));
|
||||
conn_timer.async_wait([self=Ptr(this), gen=generation](const asio::error_code& error)
|
||||
{
|
||||
self->conn_timer_callback(gen, error);
|
||||
});
|
||||
conn_timer_pending = true;
|
||||
}
|
||||
}
|
||||
@ -351,7 +369,10 @@ namespace openvpn {
|
||||
server_poll_timer.cancel();
|
||||
interim_finalize();
|
||||
restart_wait_timer.expires_at(Time::now() + Time::Duration::seconds(delay));
|
||||
restart_wait_timer.async_wait(asio_dispatch_timer_arg(&ClientConnect::restart_wait_callback, this, generation));
|
||||
restart_wait_timer.async_wait([self=Ptr(this), gen=generation](const asio::error_code& error)
|
||||
{
|
||||
self->restart_wait_callback(gen, error);
|
||||
});
|
||||
}
|
||||
|
||||
virtual void client_proto_terminate()
|
||||
@ -510,7 +531,10 @@ namespace openvpn {
|
||||
if (client_options->server_poll_timeout_enabled())
|
||||
{
|
||||
server_poll_timer.expires_at(Time::now() + client_options->server_poll_timeout());
|
||||
server_poll_timer.async_wait(asio_dispatch_timer_arg(&ClientConnect::server_poll_callback, this, generation));
|
||||
server_poll_timer.async_wait([self=Ptr(this), gen=generation](const asio::error_code& error)
|
||||
{
|
||||
self->server_poll_callback(gen, error);
|
||||
});
|
||||
}
|
||||
conn_timer_start();
|
||||
client->start();
|
||||
|
@ -646,7 +646,10 @@ namespace openvpn {
|
||||
if (!received_options.partial())
|
||||
{
|
||||
push_request_timer.expires_at(now() + dur);
|
||||
push_request_timer.async_wait(asio_dispatch_timer_arg(&Session::send_push_request_callback, this, dur));
|
||||
push_request_timer.async_wait([self=Ptr(this), dur](const asio::error_code& error)
|
||||
{
|
||||
self->send_push_request_callback(dur, error);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -699,7 +702,10 @@ namespace openvpn {
|
||||
next.max(now());
|
||||
housekeeping_schedule.reset(next);
|
||||
housekeeping_timer.expires_at(next);
|
||||
housekeeping_timer.async_wait(asio_dispatch_timer(&Session::housekeeping_callback, this));
|
||||
housekeeping_timer.async_wait([self=Ptr(this)](const asio::error_code& error)
|
||||
{
|
||||
self->housekeeping_callback(error);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -728,7 +734,10 @@ namespace openvpn {
|
||||
void schedule_inactive_timer()
|
||||
{
|
||||
inactive_timer.expires_at(now() + inactive_duration);
|
||||
inactive_timer.async_wait(asio_dispatch_timer(&Session::inactive_callback, this));
|
||||
inactive_timer.async_wait([self=Ptr(this)](const asio::error_code& error)
|
||||
{
|
||||
self->inactive_callback(error);
|
||||
});
|
||||
}
|
||||
|
||||
void inactive_callback(const asio::error_code& e) // fixme for DCO
|
||||
|
@ -37,7 +37,6 @@
|
||||
#include <openvpn/common/options.hpp>
|
||||
#include <openvpn/common/number.hpp>
|
||||
#include <openvpn/common/hostport.hpp>
|
||||
#include <openvpn/common/asiodispatch.hpp>
|
||||
#include <openvpn/addr/ip.hpp>
|
||||
#include <openvpn/addr/addrlist.hpp>
|
||||
#include <openvpn/transport/protocol.hpp>
|
||||
@ -247,11 +246,6 @@ namespace openvpn {
|
||||
// to initial tunnel establishment.
|
||||
class PreResolve : public RC<thread_unsafe_refcount>
|
||||
{
|
||||
typedef AsioDispatchResolve<PreResolve,
|
||||
void (PreResolve::*)(const asio::error_code&,
|
||||
asio::ip::tcp::resolver::iterator),
|
||||
asio::ip::tcp::resolver::iterator> AsioDispatchResolveTCP;
|
||||
|
||||
public:
|
||||
typedef RCPtr<PreResolve> Ptr;
|
||||
|
||||
@ -327,7 +321,10 @@ namespace openvpn {
|
||||
// call into Asio to do the resolve operation
|
||||
OPENVPN_LOG_REMOTELIST("*** PreResolve RESOLVE on " << item.server_host);
|
||||
asio::ip::tcp::resolver::query query(item.server_host, "0");
|
||||
resolver.async_resolve(query, AsioDispatchResolveTCP(&PreResolve::resolve_callback, this));
|
||||
resolver.async_resolve(query, [self=Ptr(this)](const asio::error_code& error, asio::ip::tcp::resolver::iterator endpoint_iterator)
|
||||
{
|
||||
self->resolve_callback(error, endpoint_iterator);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,6 @@
|
||||
|
||||
#include <openvpn/common/rc.hpp>
|
||||
#include <openvpn/common/action.hpp>
|
||||
#include <openvpn/common/asiodispatch.hpp>
|
||||
#include <openvpn/log/logthread.hpp>
|
||||
|
||||
namespace openvpn {
|
||||
@ -96,7 +95,10 @@ namespace openvpn {
|
||||
{
|
||||
OPENVPN_LOG("ActionThread Exception: " << e.what());
|
||||
}
|
||||
io_service.post(asio_dispatch_post_arg(&ActionThread::completion_post, this, status));
|
||||
io_service.post([self=Ptr(this), status]()
|
||||
{
|
||||
self->completion_post(status);
|
||||
});
|
||||
}
|
||||
|
||||
asio::io_service& io_service;
|
||||
|
@ -38,7 +38,6 @@
|
||||
#include <openvpn/common/exception.hpp>
|
||||
#include <openvpn/common/size.hpp>
|
||||
#include <openvpn/common/asiosignal.hpp>
|
||||
#include <openvpn/common/asiodispatch.hpp>
|
||||
#include <openvpn/common/signal.hpp>
|
||||
#include <openvpn/time/time.hpp>
|
||||
#include <openvpn/time/asiotimer.hpp>
|
||||
@ -90,7 +89,10 @@ namespace openvpn {
|
||||
|
||||
#ifdef OPENVPN_EXIT_IN
|
||||
exit_timer.expires_at(Time::now() + Time::Duration::seconds(OPENVPN_EXIT_IN));
|
||||
exit_timer.async_wait(asio_dispatch_timer(&RunContext::exit_timer_callback, this));
|
||||
exit_timer.async_wait([self=Ptr(this)](const asio::error_code& error)
|
||||
{
|
||||
self->exit_timer_callback(error);
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -193,7 +195,10 @@ namespace openvpn {
|
||||
exit_timer.cancel();
|
||||
|
||||
if (signals)
|
||||
io_service.post(asio_dispatch_post(&ASIOSignals::cancel, signals.get()));
|
||||
io_service.post([sig=signals]()
|
||||
{
|
||||
sig->cancel();
|
||||
});
|
||||
|
||||
unsigned int stopped = 0;
|
||||
for (size_t i = 0; i < servlist.size(); ++i)
|
||||
@ -239,7 +244,10 @@ namespace openvpn {
|
||||
|
||||
void signal_rearm()
|
||||
{
|
||||
signals->register_signals_all(asio_dispatch_signal(&RunContext::signal, this));
|
||||
signals->register_signals_all([self=Ptr(this)](const asio::error_code& error, int signal_number)
|
||||
{
|
||||
self->signal(error, signal_number);
|
||||
});
|
||||
}
|
||||
|
||||
// these vars only used by main thread
|
||||
|
@ -32,7 +32,6 @@
|
||||
#include <openvpn/common/unicode.hpp>
|
||||
#include <openvpn/common/abort.hpp>
|
||||
#include <openvpn/common/link.hpp>
|
||||
#include <openvpn/common/asiodispatch.hpp>
|
||||
#include <openvpn/buffer/bufstream.hpp>
|
||||
#include <openvpn/time/asiotimer.hpp>
|
||||
#include <openvpn/time/coarsetime.hpp>
|
||||
@ -507,7 +506,10 @@ namespace openvpn {
|
||||
next.max(now());
|
||||
housekeeping_schedule.reset(next);
|
||||
housekeeping_timer.expires_at(next);
|
||||
housekeeping_timer.async_wait(asio_dispatch_timer(&Session::housekeeping_callback, this));
|
||||
housekeeping_timer.async_wait([self=Ptr(this)](const asio::error_code& error)
|
||||
{
|
||||
self->housekeeping_callback(error);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -220,10 +220,6 @@ namespace openvpn {
|
||||
friend class ClientConfig; // calls constructor
|
||||
friend LinkImpl; // calls tcp_read_handler
|
||||
|
||||
typedef AsioDispatchResolve<Client,
|
||||
void (Client::*)(const asio::error_code&, asio::ip::tcp::resolver::iterator),
|
||||
asio::ip::tcp::resolver::iterator> AsioDispatchResolveTCP;
|
||||
|
||||
public:
|
||||
virtual void transport_start()
|
||||
{
|
||||
@ -253,7 +249,10 @@ namespace openvpn {
|
||||
asio::ip::tcp::resolver::query query(proxy_host,
|
||||
proxy_port);
|
||||
parent.transport_pre_resolve();
|
||||
resolver.async_resolve(query, AsioDispatchResolveTCP(&Client::do_resolve_, this));
|
||||
resolver.async_resolve(query, [self=Ptr(this)](const asio::error_code& error, asio::ip::tcp::resolver::iterator endpoint_iterator)
|
||||
{
|
||||
self->do_resolve_(error, endpoint_iterator);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -898,7 +897,10 @@ namespace openvpn {
|
||||
}
|
||||
#endif
|
||||
socket.set_option(asio::ip::tcp::no_delay(true));
|
||||
socket.async_connect(server_endpoint, asio_dispatch_connect(&Client::start_impl_, this));
|
||||
socket.async_connect(server_endpoint, [self=Ptr(this)](const asio::error_code& error)
|
||||
{
|
||||
self->start_impl_(error);
|
||||
});
|
||||
}
|
||||
|
||||
// start I/O on TCP socket
|
||||
|
@ -74,11 +74,6 @@ namespace openvpn {
|
||||
friend class ClientConfig; // calls constructor
|
||||
friend LinkImpl; // calls tcp_read_handler
|
||||
|
||||
typedef AsioDispatchResolve<Client,
|
||||
void (Client::*)(const asio::error_code&,
|
||||
asio::ip::tcp::resolver::iterator),
|
||||
asio::ip::tcp::resolver::iterator> AsioDispatchResolveTCP;
|
||||
|
||||
public:
|
||||
virtual void transport_start()
|
||||
{
|
||||
@ -94,7 +89,10 @@ namespace openvpn {
|
||||
asio::ip::tcp::resolver::query query(server_host,
|
||||
server_port);
|
||||
parent.transport_pre_resolve();
|
||||
resolver.async_resolve(query, AsioDispatchResolveTCP(&Client::do_resolve_, this));
|
||||
resolver.async_resolve(query, [self=Ptr(this)](const asio::error_code& error, asio::ip::tcp::resolver::iterator endpoint_iterator)
|
||||
{
|
||||
self->do_resolve_(error, endpoint_iterator);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -255,7 +253,10 @@ namespace openvpn {
|
||||
}
|
||||
#endif
|
||||
socket.set_option(asio::ip::tcp::no_delay(true));
|
||||
socket.async_connect(server_endpoint, asio_dispatch_connect(&Client::start_impl_, this));
|
||||
socket.async_connect(server_endpoint, [self=Ptr(this)](const asio::error_code& error)
|
||||
{
|
||||
self->start_impl_(error);
|
||||
});
|
||||
}
|
||||
|
||||
// start I/O on TCP socket
|
||||
|
@ -76,11 +76,6 @@ namespace openvpn {
|
||||
|
||||
typedef Link<Client*> LinkImpl;
|
||||
|
||||
typedef AsioDispatchResolve<Client,
|
||||
void (Client::*)(const asio::error_code&,
|
||||
asio::ip::udp::resolver::iterator),
|
||||
asio::ip::udp::resolver::iterator> AsioDispatchResolveUDP;
|
||||
|
||||
public:
|
||||
virtual void transport_start()
|
||||
{
|
||||
@ -96,7 +91,10 @@ namespace openvpn {
|
||||
asio::ip::udp::resolver::query query(server_host,
|
||||
server_port);
|
||||
parent.transport_pre_resolve();
|
||||
resolver.async_resolve(query, AsioDispatchResolveUDP(&Client::do_resolve_, this));
|
||||
resolver.async_resolve(query, [self=Ptr(this)](const asio::error_code& error, asio::ip::udp::resolver::iterator endpoint_iterator)
|
||||
{
|
||||
self->do_resolve_(error, endpoint_iterator);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -241,7 +239,10 @@ namespace openvpn {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
socket.async_connect(server_endpoint, asio_dispatch_connect(&Client::start_impl_, this));
|
||||
socket.async_connect(server_endpoint, [self=Ptr(this)](const asio::error_code& error)
|
||||
{
|
||||
self->start_impl_(error);
|
||||
});
|
||||
}
|
||||
|
||||
// start I/O on UDP socket
|
||||
|
@ -29,7 +29,6 @@
|
||||
#include <asio.hpp>
|
||||
|
||||
#include <openvpn/common/size.hpp>
|
||||
#include <openvpn/common/asiodispatch.hpp>
|
||||
#include <openvpn/common/rc.hpp>
|
||||
#include <openvpn/frame/frame.hpp>
|
||||
#include <openvpn/log/sessionstats.hpp>
|
||||
@ -142,7 +141,10 @@ namespace openvpn {
|
||||
frame_context.prepare(udpfrom->buf);
|
||||
socket.async_receive_from(frame_context.mutable_buffers_1(udpfrom->buf),
|
||||
udpfrom->sender_endpoint,
|
||||
asio_dispatch_read(&Link::handle_read, this, udpfrom));
|
||||
[self=Ptr(this), udpfrom](const asio::error_code& error, const size_t bytes_recvd)
|
||||
{
|
||||
self->handle_read(udpfrom, error, bytes_recvd);
|
||||
});
|
||||
}
|
||||
|
||||
void handle_read(PacketFrom *udpfrom, const asio::error_code& error, const size_t bytes_recvd)
|
||||
|
@ -28,7 +28,6 @@
|
||||
|
||||
#include <openvpn/common/size.hpp>
|
||||
#include <openvpn/common/rc.hpp>
|
||||
#include <openvpn/common/asiodispatch.hpp>
|
||||
#include <openvpn/frame/frame.hpp>
|
||||
#include <openvpn/ip/ip.hpp>
|
||||
#include <openvpn/common/socktypes.hpp>
|
||||
@ -207,7 +206,10 @@ namespace openvpn {
|
||||
|
||||
// queue read on tun device
|
||||
stream->async_read_some(frame_context.mutable_buffers_1(tunfrom->buf),
|
||||
asio_dispatch_read(&TunIO::handle_read, this, tunfrom));
|
||||
[self=Ptr(this), tunfrom](const asio::error_code& error, const size_t bytes_recvd)
|
||||
{
|
||||
self->handle_read(tunfrom, error, bytes_recvd);
|
||||
});
|
||||
}
|
||||
|
||||
void handle_read(PacketFrom *tunfrom, const asio::error_code& error, const size_t bytes_recvd)
|
||||
|
Loading…
Reference in New Issue
Block a user