Skip to content

Commit

Permalink
boost::asio::io_service -> boost::asio::io_context
Browse files Browse the repository at this point in the history
I think asio renamed this as part of aligning with the networking TS

This might also help us move to that if it's ever standardised.
  • Loading branch information
adamncasey committed May 27, 2022
1 parent 20f0acd commit fb9c977
Show file tree
Hide file tree
Showing 32 changed files with 207 additions and 207 deletions.
4 changes: 2 additions & 2 deletions amqpprox_ctl/client.m.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ int main(int argc, char *argv[])
return 1;
}

boost::asio::io_service ioService;
boost::asio::io_context ioContext;

stream_protocol::socket clientSocket(ioService);
stream_protocol::socket clientSocket(ioContext);
clientSocket.connect(stream_protocol::endpoint(argv[1]));

std::string allArgs{argv[2]};
Expand Down
4 changes: 2 additions & 2 deletions libamqpprox/amqpprox_authcontrolcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void AuthControlCommand::handleCommand(const std::string & /* command */,
}

serverHandle->setAuthIntercept(std::make_shared<HttpAuthIntercept>(
serverHandle->ioService(),
serverHandle->ioContext(),
hostname,
std::to_string(port),
target,
Expand All @@ -85,7 +85,7 @@ void AuthControlCommand::handleCommand(const std::string & /* command */,
else if (subcommand == "ALWAYS_ALLOW") {
serverHandle->setAuthIntercept(
std::make_shared<DefaultAuthIntercept>(
serverHandle->ioService()));
serverHandle->ioContext()));

serverHandle->getAuthIntercept()->print(output);
}
Expand Down
4 changes: 2 additions & 2 deletions libamqpprox/amqpprox_authinterceptinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ namespace Bloomberg {
namespace amqpprox {

AuthInterceptInterface::AuthInterceptInterface(
boost::asio::io_service &ioService)
: d_ioService(ioService)
boost::asio::io_context &ioContext)
: d_ioContext(ioContext)
{
}

Expand Down
4 changes: 2 additions & 2 deletions libamqpprox/amqpprox_authinterceptinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AuthResponse;
*/
class AuthInterceptInterface {
protected:
boost::asio::io_service &d_ioService;
boost::asio::io_context &d_ioContext;

public:
/**
Expand All @@ -45,7 +45,7 @@ class AuthInterceptInterface {
ReceiveResponseCb;

// CREATORS
explicit AuthInterceptInterface(boost::asio::io_service &ioService);
explicit AuthInterceptInterface(boost::asio::io_context &ioContext);

virtual ~AuthInterceptInterface() = default;

Expand Down
4 changes: 2 additions & 2 deletions libamqpprox/amqpprox_backendcontrolcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ void BackendControlCommand::handleCommand(const std::string & /* command */,
if (!name.empty() && !datacenter.empty() && !host.empty() && port) {
std::string ip;
if (!isDns) {
auto &ioService = controlHandle->ioService();
boost::asio::ip::tcp::resolver resolver(ioService);
auto &ioContext = controlHandle->ioContext();
boost::asio::ip::tcp::resolver resolver(ioContext);
boost::asio::ip::tcp::resolver::query q(host, "");
boost::system::error_code ec;
auto it = resolver.resolve(q, ec);
Expand Down
16 changes: 8 additions & 8 deletions libamqpprox/amqpprox_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ Control::Control(Server *server,
const std::string &udsPath)
: d_server_p(server)
, d_eventSource_p(source)
, d_ioService()
, d_acceptor(d_ioService, stream_protocol::endpoint(udsPath))
, d_socket(d_ioService)
, d_ioContext()
, d_acceptor(d_ioContext, stream_protocol::endpoint(udsPath))
, d_socket(d_ioContext)
{
boost::asio::socket_base::reuse_address option(true);
d_acceptor.set_option(option);
Expand All @@ -174,7 +174,7 @@ Control::Control(Server *server,
void Control::run()
{
try {
d_ioService.run();
d_ioContext.run();
}
catch (std::exception &e) {
LOG_FATAL << "Control Thread Exception: " << e.what();
Expand All @@ -183,7 +183,7 @@ void Control::run()

void Control::stop()
{
d_ioService.stop();
d_ioContext.stop();
}

void Control::scheduleRecurringEvent(
Expand All @@ -192,7 +192,7 @@ void Control::scheduleRecurringEvent(
const std::function<bool(Control *, Server *)> &event)
{
auto duration = boost::posix_time::milliseconds(intervalMs);
auto timer = std::make_shared<boost::asio::deadline_timer>(d_ioService);
auto timer = std::make_shared<boost::asio::deadline_timer>(d_ioContext);
timer->expires_from_now(duration);
timer->async_wait([this, name, intervalMs, event, timer](
const boost::system::error_code &ec) {
Expand Down Expand Up @@ -248,9 +248,9 @@ void Control::doAccept()
});
}

boost::asio::io_service &Control::ioService()
boost::asio::io_context &Control::ioContext()
{
return d_ioService;
return d_ioContext;
}

}
Expand Down
4 changes: 2 additions & 2 deletions libamqpprox/amqpprox_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Server;
class Control {
Server *d_server_p;
EventSource *d_eventSource_p;
boost::asio::io_service d_ioService;
boost::asio::io_context d_ioContext;
boost::asio::local::stream_protocol::acceptor d_acceptor;
boost::asio::local::stream_protocol::socket d_socket;
std::map<std::string, std::unique_ptr<ControlCommand>> d_controlCommands;
Expand Down Expand Up @@ -91,7 +91,7 @@ class Control {
/**
* \return IO service for the control thread
*/
boost::asio::io_service &ioService();
boost::asio::io_context &ioContext();

private:
void doAccept();
Expand Down
6 changes: 3 additions & 3 deletions libamqpprox/amqpprox_defaultauthintercept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
namespace Bloomberg {
namespace amqpprox {

DefaultAuthIntercept::DefaultAuthIntercept(boost::asio::io_service &ioService)
: AuthInterceptInterface(ioService)
DefaultAuthIntercept::DefaultAuthIntercept(boost::asio::io_context &ioContext)
: AuthInterceptInterface(ioContext)
{
}

Expand All @@ -41,7 +41,7 @@ void DefaultAuthIntercept::authenticate(const authproto::AuthRequest,
authResponseData.set_reason("Default route auth used - always allow");
responseCb(authResponseData);
};
boost::asio::post(d_ioService, cb);
boost::asio::post(d_ioContext, cb);
}

void DefaultAuthIntercept::print(std::ostream &os) const
Expand Down
2 changes: 1 addition & 1 deletion libamqpprox/amqpprox_defaultauthintercept.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class AuthRequest;
class DefaultAuthIntercept : public AuthInterceptInterface {
public:
// CREATORS
explicit DefaultAuthIntercept(boost::asio::io_service &ioService);
explicit DefaultAuthIntercept(boost::asio::io_context &ioContext);

virtual ~DefaultAuthIntercept() override = default;

Expand Down
4 changes: 2 additions & 2 deletions libamqpprox/amqpprox_dnshostnamemapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ DNSHostnameMapper::DNSHostnameMapper()
}

void DNSHostnameMapper::prime(
boost::asio::io_service &ioService,
boost::asio::io_context &ioContext,
std::initializer_list<boost::asio::ip::tcp::endpoint> endpoints)
{
boost::asio::ip::tcp::resolver resolver(ioService);
boost::asio::ip::tcp::resolver resolver(ioContext);
for (const auto &endpoint : endpoints) {
auto address = boost::lexical_cast<std::string>(endpoint.address());
boost::upgrade_lock<boost::shared_mutex> lock(d_lg);
Expand Down
4 changes: 2 additions & 2 deletions libamqpprox/amqpprox_dnshostnamemapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ class DNSHostnameMapper : public HostnameMapper {

/**
* \brief prime the cache of hostnames with a list of endpoints
* \param ioService handle to the boost asio service
* \param ioContext handle to the boost asio service
* \param endpoints list of endpoints to prime the cache with
*/
void prime(boost::asio::io_service &ioService,
void prime(boost::asio::io_context &ioContext,
std::initializer_list<boost::asio::ip::tcp::endpoint> endpoints)
override;

Expand Down
8 changes: 4 additions & 4 deletions libamqpprox/amqpprox_dnsresolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ namespace amqpprox {

DNSResolver::OverrideFunction DNSResolver::s_override;

DNSResolver::DNSResolver(boost::asio::io_service &ioService)
: d_ioService(ioService)
, d_resolver(d_ioService)
, d_timer(d_ioService)
DNSResolver::DNSResolver(boost::asio::io_context &ioContext)
: d_ioContext(ioContext)
, d_resolver(d_ioContext)
, d_timer(d_ioContext)
, d_cacheTimeout(1000)
, d_cacheTimerRunning(false)
{
Expand Down
12 changes: 6 additions & 6 deletions libamqpprox/amqpprox_dnsresolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class DNSResolver {
const std::string &)>;

private:
boost::asio::io_service &d_ioService;
boost::asio::io_context &d_ioContext;
boost::asio::ip::tcp::resolver d_resolver;
boost::asio::steady_timer d_timer;
std::atomic<uint32_t> d_cacheTimeout;
Expand All @@ -74,11 +74,11 @@ class DNSResolver {

public:
/**
* \brief Construct a resolver using io_service
* \brief Construct a resolver using io_context
*
* This resolver will then use the passed io_service as its event loop.
* This resolver will then use the passed io_context as its event loop.
*/
explicit DNSResolver(boost::asio::io_service &ioService);
explicit DNSResolver(boost::asio::io_context &ioContext);

~DNSResolver();

Expand Down Expand Up @@ -192,7 +192,7 @@ void DNSResolver::resolve(std::string_view query_host,
boost::system::error_code ec;
std::vector<TcpEndpoint> result = it->second;
auto cb = [callback, ec, result] { callback(ec, result); };
d_ioService.post(cb);
d_ioContext.post(cb);
return;
}
}
Expand All @@ -203,7 +203,7 @@ void DNSResolver::resolve(std::string_view query_host,
LOG_TRACE << "Returning " << vec.size()
<< " overriden values with ec = " << ec;
auto cb = [callback, ec, vec] { callback(ec, vec); };
d_ioService.post(cb);
d_ioContext.post(cb);

if (!ec) {
setCachedResolution(host, service, std::move(vec));
Expand Down
4 changes: 2 additions & 2 deletions libamqpprox/amqpprox_hostnamemapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ class HostnameMapper {

/**
* \brief prime the cache of hostnames with a list of endpoints
* \param ioService handle to the boost asio service
* \param ioContext handle to the boost asio service
* \param endpoints list of endpoints to prime the cache with
*/
virtual void
prime(boost::asio::io_service &ioService,
prime(boost::asio::io_context &ioContext,
std::initializer_list<boost::asio::ip::tcp::endpoint> endpoint) = 0;

/**
Expand Down
8 changes: 4 additions & 4 deletions libamqpprox/amqpprox_httpauthintercept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ const int TIMEOUT_SECONDS = 30;
int HTTP_VERSION = 11; // HTTP/1.1 version
}

HttpAuthIntercept::HttpAuthIntercept(boost::asio::io_service &ioService,
HttpAuthIntercept::HttpAuthIntercept(boost::asio::io_context &ioContext,
const std::string &hostname,
const std::string &port,
const std::string &target,
DNSResolver *dnsResolver)
: AuthInterceptInterface(ioService)
, d_ioService(ioService)
: AuthInterceptInterface(ioContext)
, d_ioContext(ioContext)
, d_hostname(hostname)
, d_port(port)
, d_target(target)
Expand Down Expand Up @@ -116,7 +116,7 @@ void HttpAuthIntercept::onResolve(

std::shared_ptr<beast::tcp_stream> stream =
std::make_shared<beast::tcp_stream>(
boost::asio::make_strand(d_ioService));
boost::asio::make_strand(d_ioContext));
// Set a timeout on the operation
stream->expires_after(std::chrono::seconds(TIMEOUT_SECONDS));

Expand Down
4 changes: 2 additions & 2 deletions libamqpprox/amqpprox_httpauthintercept.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ using tcp = boost::asio::ip::tcp;
class HttpAuthIntercept
: public AuthInterceptInterface,
public std::enable_shared_from_this<HttpAuthIntercept> {
boost::asio::io_service &d_ioService;
boost::asio::io_service &d_ioContext;
std::string d_hostname;
std::string d_port;
std::string d_target;
Expand Down Expand Up @@ -77,7 +77,7 @@ class HttpAuthIntercept

public:
// CREATORS
HttpAuthIntercept(boost::asio::io_service &ioService,
HttpAuthIntercept(boost::asio::io_service &ioContext,
const std::string &hostname,
const std::string &port,
const std::string &target,
Expand Down
2 changes: 1 addition & 1 deletion libamqpprox/amqpprox_maphostnamecontrolcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void MapHostnameControlCommand::handleCommand(
serverHandle->setHostnameMapper(m);
serverHandle->visitSessions(
[&m, controlHandle](const std::shared_ptr<Session> &s) {
s->state().setHostnameMapper(controlHandle->ioService(), m);
s->state().setHostnameMapper(controlHandle->ioContext(), m);
});

outputFunctor("Hostname mapper set for all current sessions.\n", true);
Expand Down
6 changes: 3 additions & 3 deletions libamqpprox/amqpprox_maybesecuresocketadaptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MaybeSecureSocketAdaptor {
using endpoint = boost::asio::ip::tcp::endpoint;
using handshake_type = boost::asio::ssl::stream_base::handshake_type;

boost::asio::io_service &d_ioService;
boost::asio::io_context &d_ioService;
std::optional<std::reference_wrapper<SocketIntercept>> d_intercept;
std::unique_ptr<stream_type> d_socket;
bool d_secured;
Expand All @@ -53,7 +53,7 @@ class MaybeSecureSocketAdaptor {
typedef typename stream_type::executor_type executor_type;

#ifdef SOCKET_TESTING
MaybeSecureSocketAdaptor(boost::asio::io_service &ioService,
MaybeSecureSocketAdaptor(boost::asio::io_context &ioService,
SocketIntercept &intercept,
bool secured)
: d_ioService(ioService)
Expand All @@ -67,7 +67,7 @@ class MaybeSecureSocketAdaptor {
}
#endif

MaybeSecureSocketAdaptor(boost::asio::io_service &ioService,
MaybeSecureSocketAdaptor(boost::asio::io_context &ioService,
boost::asio::ssl::context &context,
bool secured)
: d_ioService(ioService)
Expand Down
Loading

0 comments on commit fb9c977

Please sign in to comment.