Skip to content

Commit

Permalink
Don't use deprecated asio features.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesyonan committed Jun 30, 2015
1 parent c4ea9e9 commit 16bde17
Show file tree
Hide file tree
Showing 26 changed files with 191 additions and 204 deletions.
16 changes: 8 additions & 8 deletions client/ovpncli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ namespace openvpn {
default_key_direction(-1), force_aes_cbc_ciphersuites(false),
alt_proxy(false),
dco(false),
io_service(nullptr) {}
io_context(nullptr) {}

OptionList options;
EvalConfig eval;
Expand Down Expand Up @@ -334,7 +334,7 @@ namespace openvpn {
bool alt_proxy;
bool dco;

asio::io_service* io_service;
asio::io_context* io_context;

template <typename SESSION_STATS, typename CLIENT_EVENTS>
void attach(OpenVPNClient* parent)
Expand Down Expand Up @@ -692,7 +692,7 @@ namespace openvpn {
client_options->submit_creds(state->creds);

// instantiate top-level client session
state->session.reset(new ClientConnect(*state->io_service, client_options));
state->session.reset(new ClientConnect(*state->io_context, client_options));

// raise an exception if app has expired
check_app_expired();
Expand Down Expand Up @@ -728,15 +728,15 @@ namespace openvpn {

OPENVPN_CLIENT_EXPORT void OpenVPNClient::connect_attach()
{
state->io_service = new asio::io_service(1); // concurrency hint=1
state->io_context = new asio::io_context(1); // concurrency hint=1
state->attach<MySessionStats, MyClientEvents>(this);
}

OPENVPN_CLIENT_EXPORT void OpenVPNClient::connect_detach()
{
state->detach();
delete state->io_service;
state->io_service = nullptr;
delete state->io_context;
state->io_context = nullptr;
}

OPENVPN_CLIENT_EXPORT void OpenVPNClient::connect_pre_run()
Expand All @@ -745,13 +745,13 @@ namespace openvpn {

OPENVPN_CLIENT_EXPORT void OpenVPNClient::connect_run()
{
state->io_service->run();
state->io_context->run();
}

OPENVPN_CLIENT_EXPORT void OpenVPNClient::connect_session_stop()
{
state->session->stop(); // On exception, stop client...
state->io_service->poll(); // and execute completion handlers.
state->io_context->poll(); // and execute completion handlers.
}

OPENVPN_CLIENT_EXPORT ConnectionInfo OpenVPNClient::connection_info()
Expand Down
9 changes: 3 additions & 6 deletions openvpn/addr/ip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ namespace openvpn {
// slow path
{
asio::error_code ec;
asio::ip::address::from_string(ipstr, ec);
asio::ip::make_address(ipstr, ec);
return !ec;
}
}

static Addr from_string(const std::string& ipstr, const char *title = nullptr, Version required_version = UNSPEC)
{
asio::error_code ec;
asio::ip::address a = asio::ip::address::from_string(ipstr, ec);
asio::ip::address a = asio::ip::make_address(ipstr, ec);
if (ec)
throw ip_exception(internal::format_error(ipstr, title, "", ec));
const Addr ret = from_asio(a);
Expand Down Expand Up @@ -323,10 +323,7 @@ namespace openvpn {
if (ver != UNSPEC)
{
const asio::ip::address a = to_asio();
asio::error_code ec;
std::string ret = a.to_string(ec);
if (ec)
throw ip_exception("to_string");
std::string ret = a.to_string();
return ret;
}
else
Expand Down
9 changes: 3 additions & 6 deletions openvpn/addr/ipv4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ namespace openvpn {
static Addr from_string(const std::string& ipstr, const char *title = nullptr)
{
asio::error_code ec;
asio::ip::address_v4 a = asio::ip::address_v4::from_string(ipstr, ec);
asio::ip::address_v4 a = asio::ip::make_address_v4(ipstr, ec);
if (ec)
throw ipv4_exception(IP::internal::format_error(ipstr, title, "v4", ec));
return from_asio(a);
Expand All @@ -200,10 +200,7 @@ namespace openvpn {
std::string to_string() const
{
const asio::ip::address_v4 a = to_asio();
asio::error_code ec;
std::string ret = a.to_string(ec);
if (ec)
throw ipv4_exception("to_string");
std::string ret = a.to_string();
return ret;
}

Expand Down Expand Up @@ -268,7 +265,7 @@ namespace openvpn {
static Addr from_asio(const asio::ip::address_v4& asio_addr)
{
Addr ret;
ret.u.addr = (std::uint32_t)asio_addr.to_ulong();
ret.u.addr = (std::uint32_t)asio_addr.to_uint();
return ret;
}

Expand Down
7 changes: 2 additions & 5 deletions openvpn/addr/ipv6.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ namespace openvpn {
static Addr from_string(const std::string& ipstr, const char *title = nullptr)
{
asio::error_code ec;
asio::ip::address_v6 a = asio::ip::address_v6::from_string(ipstr, ec);
asio::ip::address_v6 a = asio::ip::make_address_v6(ipstr, ec);
if (ec)
throw ipv6_exception(IP::internal::format_error(ipstr, title, "v6", ec));
return from_asio(a);
Expand All @@ -107,10 +107,7 @@ namespace openvpn {
std::string to_string() const
{
const asio::ip::address_v6 a = to_asio();
asio::error_code ec;
std::string ret = a.to_string(ec);
if (ec)
throw ipv6_exception("to_string");
std::string ret = a.to_string();
return ret;
}

Expand Down
52 changes: 26 additions & 26 deletions openvpn/client/cliconnect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace openvpn {

OPENVPN_SIMPLE_EXCEPTION(client_connect_unhandled_exception);

ClientConnect(asio::io_service& io_service_arg,
ClientConnect(asio::io_context& io_context_arg,
const ClientOptions::Ptr& client_options_arg)
: generation(0),
halt(false),
Expand All @@ -83,11 +83,11 @@ namespace openvpn {
dont_restart_(false),
lifecycle_started(false),
conn_timeout(client_options_arg->conn_timeout()),
io_service(io_service_arg),
io_context(io_context_arg),
client_options(client_options_arg),
server_poll_timer(io_service_arg),
restart_wait_timer(io_service_arg),
conn_timer(io_service_arg),
server_poll_timer(io_context_arg),
restart_wait_timer(io_context_arg),
conn_timer(io_context_arg),
conn_timer_pending(false)
{
}
Expand All @@ -100,7 +100,7 @@ namespace openvpn {
throw ErrorCode(Error::NETWORK_UNAVAILABLE, true, "Network Unavailable");

RemoteList::Ptr remote_list = client_options->remote_list_precache();
RemoteList::PreResolve::Ptr preres(new RemoteList::PreResolve(io_service,
RemoteList::PreResolve::Ptr preres(new RemoteList::PreResolve(io_context,
remote_list,
client_options->stats_ptr()));
if (preres->work_available())
Expand Down Expand Up @@ -161,10 +161,10 @@ namespace openvpn {
void thread_safe_stop()
{
if (!halt)
io_service.post([self=Ptr(this)]()
{
self->graceful_stop();
});
asio::post(io_context, [self=Ptr(this)]()
{
self->graceful_stop();
});
}

void pause(const std::string& reason)
Expand All @@ -179,7 +179,7 @@ namespace openvpn {
interim_finalize();
}
cancel_timers();
asio_work.reset(new asio::io_service::work(io_service));
asio_work.reset(new asio::io_context::work(io_context));
ClientEvent::Base::Ptr ev = new ClientEvent::Pause(reason);
client_options->events().add_event(ev);
client_options->stats().error(Error::N_PAUSE);
Expand Down Expand Up @@ -216,28 +216,28 @@ namespace openvpn {
void thread_safe_pause(const std::string& reason)
{
if (!halt)
io_service.post([self=Ptr(this), reason]()
{
self->pause(reason);
});
asio::post(io_context, [self=Ptr(this), reason]()
{
self->pause(reason);
});
}

void thread_safe_resume()
{
if (!halt)
io_service.post([self=Ptr(this)]()
{
self->resume();
});
asio::post(io_context, [self=Ptr(this)]()
{
self->resume();
});
}

void thread_safe_reconnect(int seconds)
{
if (!halt)
io_service.post([self=Ptr(this), seconds]()
{
self->reconnect(seconds);
});
asio::post(io_context, [self=Ptr(this), seconds]()
{
self->reconnect(seconds);
});
}

void dont_restart()
Expand Down Expand Up @@ -524,7 +524,7 @@ namespace openvpn {
client_options->next();
}
Client::Config::Ptr cli_config = client_options->client_config(); // client_config in cliopt.hpp
client.reset(new Client(io_service, *cli_config, this)); // build ClientProto::Session from cliproto.hpp
client.reset(new Client(io_context, *cli_config, this)); // build ClientProto::Session from cliproto.hpp
client_finalized = false;

restart_wait_timer.cancel();
Expand Down Expand Up @@ -569,14 +569,14 @@ namespace openvpn {
bool dont_restart_;
bool lifecycle_started;
int conn_timeout;
asio::io_service& io_service;
asio::io_context& io_context;
ClientOptions::Ptr client_options;
Client::Ptr client;
AsioTimer server_poll_timer;
AsioTimer restart_wait_timer;
AsioTimer conn_timer;
bool conn_timer_pending;
std::unique_ptr<asio::io_service::work> asio_work;
std::unique_ptr<asio::io_context::work> asio_work;
RemoteList::PreResolve::Ptr pre_resolve;
};

Expand Down
16 changes: 8 additions & 8 deletions openvpn/client/cliproto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,16 @@ namespace openvpn {
OptionList::FilterBase::Ptr pushed_options_filter;
};

Session(asio::io_service& io_service_arg,
Session(asio::io_context& io_context_arg,
const Config& config,
NotifyCallback* notify_callback_arg)
: Base(config.proto_context_config, config.cli_stats),
io_service(io_service_arg),
io_context(io_context_arg),
transport_factory(config.transport_factory),
tun_factory(config.tun_factory),
notify_callback(notify_callback_arg),
housekeeping_timer(io_service_arg),
push_request_timer(io_service_arg),
housekeeping_timer(io_context_arg),
push_request_timer(io_context_arg),
halt(false),
received_options(config.push_base),
creds(config.creds),
Expand All @@ -149,7 +149,7 @@ namespace openvpn {
fatal_(Error::UNDEF),
pushed_options_limit(config.pushed_options_limit),
pushed_options_filter(config.pushed_options_filter),
inactive_timer(io_service_arg),
inactive_timer(io_context_arg),
inactive_bytes(0),
inactive_last_sample(0)
{
Expand All @@ -175,7 +175,7 @@ namespace openvpn {
housekeeping_schedule.init(Time::Duration::binary_ms(512), Time::Duration::binary_ms(1024));

// initialize transport-layer packet handler
transport = transport_factory->new_transport_client_obj(io_service, *this);
transport = transport_factory->new_transport_client_obj(io_context, *this);
transport->transport_start();
}
}
Expand Down Expand Up @@ -486,7 +486,7 @@ namespace openvpn {
Base::process_push(received_options, *proto_context_options);

// initialize tun/routing
tun = tun_factory->new_tun_client_obj(io_service, *this, transport.get());
tun = tun_factory->new_tun_client_obj(io_context, *this, transport.get());
tun->tun_start(received_options, *transport, Base::dc_settings());

// initialize data channel after pushed options have been processed
Expand Down Expand Up @@ -818,7 +818,7 @@ namespace openvpn {
}
#endif

asio::io_service& io_service;
asio::io_context& io_context;

TransportClientFactory::Ptr transport_factory;
TransportClient::Ptr transport;
Expand Down
Loading

0 comments on commit 16bde17

Please sign in to comment.