Skip to content

Commit d79a392

Browse files
committed
Use namespace aliases instead of using lslboost::asio.
1 parent 6208017 commit d79a392

File tree

8 files changed

+40
-38
lines changed

8 files changed

+40
-38
lines changed

src/inlet_connection.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
#include <sstream>
55

66
using namespace lsl;
7-
using namespace lslboost::asio;
7+
namespace asio = lslboost::asio;
8+
namespace ip = asio::ip;
89

910
inlet_connection::inlet_connection(const stream_info_impl &info, bool recover)
1011
: type_info_(info), host_info_(info), tcp_protocol_(tcp::v4()), udp_protocol_(udp::v4()),
@@ -110,7 +111,7 @@ ip::address resolve_v6_addr(const std::string &addr) {
110111

111112
// This more complicated procedure is required when the address is an ipv6 link-local address.
112113
// Simplified from https://stackoverflow.com/a/10303761/73299
113-
io_context io;
114+
asio::io_context io;
114115
auto res = ip::tcp::resolver(io).resolve(addr, "");
115116
if (res.empty()) throw lost_error("Unable to resolve tcp stream at address: " + addr);
116117
return res.begin()->endpoint().address();

src/resolve_attempt_udp.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
#include <sstream>
77

88
using namespace lsl;
9-
using namespace lslboost::asio;
9+
namespace asio = lslboost::asio;
1010
using err_t = const lslboost::system::error_code &;
1111

12-
resolve_attempt_udp::resolve_attempt_udp(io_context &io, const udp &protocol,
12+
resolve_attempt_udp::resolve_attempt_udp(asio::io_context &io, const udp &protocol,
1313
const std::vector<udp::endpoint> &targets, const std::string &query, result_container &results,
1414
std::mutex &results_mut, double cancel_after, cancellable_registry *registry)
1515
: io_(io), results_(results), results_mut_(results_mut), cancel_after_(cancel_after),
@@ -28,14 +28,14 @@ resolve_attempt_udp::resolve_attempt_udp(io_context &io, const udp &protocol,
2828
unicast_socket_.open(protocol);
2929
try {
3030
broadcast_socket_.open(protocol);
31-
broadcast_socket_.set_option(socket_base::broadcast(true));
31+
broadcast_socket_.set_option(asio::socket_base::broadcast(true));
3232
} catch (std::exception &e) {
3333
LOG_F(WARNING, "Cannot open UDP broadcast socket for resolves: %s", e.what());
3434
}
3535
try {
3636
multicast_socket_.open(protocol);
3737
multicast_socket_.set_option(
38-
ip::multicast::hops(api_config::get_instance()->multicast_ttl()));
38+
asio::ip::multicast::hops(api_config::get_instance()->multicast_ttl()));
3939
} catch (std::exception &e) {
4040
LOG_F(WARNING, "Cannot open UDP multicast socket for resolves: %s", e.what());
4141
}
@@ -87,14 +87,14 @@ void resolve_attempt_udp::cancel() {
8787
// === receive loop ===
8888

8989
void resolve_attempt_udp::receive_next_result() {
90-
recv_socket_.async_receive_from(buffer(resultbuf_), remote_endpoint_,
90+
recv_socket_.async_receive_from(asio::buffer(resultbuf_), remote_endpoint_,
9191
[shared_this = shared_from_this()](
9292
err_t err, size_t len) { shared_this->handle_receive_outcome(err, len); });
9393
}
9494

9595
void resolve_attempt_udp::handle_receive_outcome(error_code err, std::size_t len) {
96-
if (cancelled_ || err == error::operation_aborted || err == error::not_connected ||
97-
err == error::not_socket)
96+
if (cancelled_ || err == asio::error::operation_aborted || err == asio::error::not_connected ||
97+
err == asio::error::not_socket)
9898
return;
9999

100100
if (!err) {
@@ -150,14 +150,14 @@ void resolve_attempt_udp::send_next_query(endpoint_list::const_iterator next) {
150150
if (ep.protocol() == recv_socket_.local_endpoint().protocol()) {
151151
// select socket to use
152152
udp::socket &sock =
153-
(ep.address() == ip::address_v4::broadcast())
153+
(ep.address() == asio::ip::address_v4::broadcast())
154154
? broadcast_socket_
155155
: (ep.address().is_multicast() ? multicast_socket_ : unicast_socket_);
156156
// and send the query over it
157157
sock.async_send_to(lslboost::asio::buffer(query_msg_), ep,
158158
[shared_this = shared_from_this(), next](err_t err, size_t) {
159-
if (!shared_this->cancelled_ && err != error::operation_aborted &&
160-
err != error::not_connected && err != error::not_socket)
159+
if (!shared_this->cancelled_ && err != asio::error::operation_aborted &&
160+
err != asio::error::not_connected && err != asio::error::not_socket)
161161
shared_this->send_next_query(next);
162162
});
163163
} else

src/resolver_impl.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
// === implementation of the resolver_impl class ===
1111

1212
using namespace lsl;
13-
using namespace lslboost::asio;
13+
namespace asio = lslboost::asio;
14+
namespace ip = asio::ip;
1415
using err_t = const lslboost::system::error_code &;
1516

1617
resolver_impl::resolver_impl()
1718
: cfg_(api_config::get_instance()), cancelled_(false), expired_(false), forget_after_(FOREVER),
18-
fast_mode_(true), io_(std::make_shared<io_context>()), resolve_timeout_expired_(*io_),
19+
fast_mode_(true), io_(std::make_shared<asio::io_context>()), resolve_timeout_expired_(*io_),
1920
wave_timer_(*io_), unicast_timer_(*io_) {
2021
// parse the multicast addresses into endpoints and store them
2122
uint16_t mcast_port = cfg_->multicast_port();
@@ -101,7 +102,7 @@ std::vector<stream_info_impl> resolver_impl::resolve_oneshot(
101102
if (timeout != FOREVER) {
102103
resolve_timeout_expired_.expires_after(timeout_sec(timeout));
103104
resolve_timeout_expired_.async_wait([this](err_t err) {
104-
if (err != error::operation_aborted) cancel_ongoing_resolve();
105+
if (err != asio::error::operation_aborted) cancel_ongoing_resolve();
105106
});
106107
}
107108

@@ -179,7 +180,7 @@ void resolver_impl::next_resolve_wave() {
179180
}
180181
wave_timer_.expires_after(timeout_sec(wave_timer_timeout));
181182
wave_timer_.async_wait([this](err_t err) {
182-
if (err != error::operation_aborted) next_resolve_wave();
183+
if (err != asio::error::operation_aborted) next_resolve_wave();
183184
});
184185
}
185186
}
@@ -203,7 +204,7 @@ void resolver_impl::udp_multicast_burst() {
203204
}
204205

205206
void resolver_impl::udp_unicast_burst(error_code err) {
206-
if (err == error::operation_aborted) return;
207+
if (err == asio::error::operation_aborted) return;
207208

208209
int failures = 0;
209210
// start one per IP stack under consideration

src/socket_utils.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
#include "common.h"
44
#include <boost/endian/conversion.hpp>
55

6-
using namespace lsl;
7-
86
double lsl::measure_endian_performance() {
97
const double measure_duration = 0.01;
108
const double t_end = lsl_clock() + measure_duration;
@@ -17,7 +15,7 @@ double lsl::measure_endian_performance() {
1715

1816
template <typename Socket, typename Protocol>
1917
uint16_t bind_port_in_range_(Socket &sock, Protocol protocol) {
20-
const api_config *cfg = api_config::get_instance();
18+
const auto *cfg = lsl::api_config::get_instance();
2119
lslboost::system::error_code ec;
2220
for (uint16_t port = cfg->base_port(), e = port + cfg->port_range(); port < e; port++) {
2321
sock.bind(typename Protocol::endpoint(protocol, port), ec);
@@ -41,13 +39,14 @@ const std::string all_ports_bound_msg(
4139
"https://labstreaminglayer.readthedocs.io/info/network-connectivity.html"
4240
") or you have a problem with your network configuration.");
4341

44-
uint16_t lsl::bind_port_in_range(udp::socket &acc, udp protocol) {
42+
uint16_t lsl::bind_port_in_range(asio::ip::udp::socket &acc, asio::ip::udp protocol) {
4543
uint16_t port = bind_port_in_range_(acc, protocol);
4644
if (!port) throw std::runtime_error(all_ports_bound_msg);
4745
return port;
4846
}
4947

50-
uint16_t lsl::bind_and_listen_to_port_in_range(tcp::acceptor &sock, tcp protocol, int backlog) {
48+
uint16_t lsl::bind_and_listen_to_port_in_range(
49+
asio::ip::tcp::acceptor &sock, asio::ip::tcp protocol, int backlog) {
5150
uint16_t port = bind_port_in_range_(sock, protocol);
5251
if (!port) throw std::runtime_error(all_ports_bound_msg);
5352
sock.listen(backlog);

src/socket_utils.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@
44
#include <boost/asio/ip/tcp.hpp>
55
#include <boost/asio/ip/udp.hpp>
66

7-
using namespace lslboost::asio::ip;
7+
namespace asio = lslboost::asio;
88

99
namespace lsl {
10-
inline lslboost::asio::chrono::milliseconds timeout_sec(double timeout_seconds) {
11-
return lslboost::asio::chrono::milliseconds(static_cast<unsigned int>(1000 * timeout_seconds));
10+
inline asio::chrono::milliseconds timeout_sec(double timeout_seconds) {
11+
return asio::chrono::milliseconds(static_cast<unsigned int>(1000 * timeout_seconds));
1212
}
1313

1414
/// Bind a socket to a free port in the configured port range or throw an error otherwise.
15-
uint16_t bind_port_in_range(udp::socket &sock, udp protocol);
15+
uint16_t bind_port_in_range(asio::ip::udp::socket &sock, asio::ip::udp protocol);
1616

1717
/// Bind and listen to an acceptor on a free port in the configured port range or throw an error.
18-
uint16_t bind_and_listen_to_port_in_range(tcp::acceptor &acc, tcp protocol, int backlog);
18+
uint16_t bind_and_listen_to_port_in_range(
19+
asio::ip::tcp::acceptor &acc, asio::ip::tcp protocol, int backlog);
1920

2021
/// Measure the endian conversion performance of this machine.
2122
double measure_endian_performance();

src/stream_outlet_impl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <memory>
88
#include <sstream>
99

10-
using namespace lslboost::asio;
10+
namespace asio = lslboost::asio;
1111

1212
namespace lsl {
1313

@@ -69,17 +69,17 @@ void stream_outlet_impl::instantiate_stack(tcp tcp_protocol, udp udp_protocol) {
6969
uint16_t multicast_port = cfg->multicast_port();
7070
LOG_F(2, "%s: Trying to listen at address '%s'", info().name().c_str(), listen_address.c_str());
7171
// create TCP data server
72-
ios_.push_back(std::make_shared<io_context>());
72+
ios_.push_back(std::make_shared<asio::io_context>());
7373
tcp_servers_.push_back(std::make_shared<tcp_server>(
7474
info_, ios_.back(), send_buffer_, sample_factory_, tcp_protocol, chunk_size_));
7575
// create UDP time server
76-
ios_.push_back(std::make_shared<io_context>());
76+
ios_.push_back(std::make_shared<asio::io_context>());
7777
udp_servers_.push_back(std::make_shared<udp_server>(info_, *ios_.back(), udp_protocol));
7878
// create UDP multicast responders
7979
for (const auto &mcastaddr : cfg->multicast_addresses()) {
8080
try {
8181
// use only addresses for the protocol that we're supposed to use here
82-
ip::address address(ip::make_address(mcastaddr));
82+
auto address = asio::ip::make_address(mcastaddr);
8383
if (udp_protocol == udp::v4() ? address.is_v4() : address.is_v6())
8484
responders_.push_back(std::make_shared<udp_server>(
8585
info_, *ios_.back(), mcastaddr, multicast_port, multicast_ttl, listen_address));

src/tcp_server.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#define NO_EXPLICIT_TEMPLATE_INSTANTIATION
2424
#include "portable_archive/portable_oarchive.hpp"
2525

26-
using namespace lslboost::asio;
26+
namespace asio = lslboost::asio;
2727
using err_t = const lslboost::system::error_code &;
2828

2929
namespace lsl {
@@ -158,7 +158,7 @@ tcp_server::tcp_server(const stream_info_impl_p &info, const io_context_p &io,
158158
info_->session_id(api_config::get_instance()->session_id());
159159
info_->uid(lslboost::uuids::to_string(lslboost::uuids::random_generator()()));
160160
info_->created_at(lsl_clock());
161-
info_->hostname(ip::host_name());
161+
info_->hostname(asio::ip::host_name());
162162
if (protocol == tcp::v4())
163163
info_->v4data_port(port);
164164
else
@@ -200,7 +200,7 @@ void tcp_server::accept_next_connection() {
200200
std::make_shared<client_session>(shared_from_this())};
201201
// accept a connection on the session's socket
202202
acceptor_->async_accept(
203-
*newsession->socket(), [shared_this = shared_from_this(), newsession, this](err_t err) {
203+
*newsession->socket(), [shared_this = shared_from_this(), newsession](err_t err) {
204204
shared_this->handle_accept_outcome(newsession, err);
205205
});
206206
} catch (std::exception &e) {
@@ -209,7 +209,7 @@ void tcp_server::accept_next_connection() {
209209
}
210210

211211
void tcp_server::handle_accept_outcome(std::shared_ptr<client_session> newsession, error_code err) {
212-
if (err == error::operation_aborted || err == error::shut_down || shutdown_) return;
212+
if (err == asio::error::operation_aborted || err == asio::error::shut_down || shutdown_) return;
213213

214214
// no error: start processing the new connection
215215
if (!err) newsession->begin_processing();

src/time_receiver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
const double NOT_ASSIGNED = std::numeric_limits<double>::max();
1010

1111
using namespace lsl;
12-
using namespace lslboost::asio;
12+
namespace asio = lslboost::asio;
1313
using err_t = const lslboost::system::error_code &;
1414

1515
time_receiver::time_receiver(inlet_connection &conn)
@@ -113,7 +113,7 @@ void time_receiver::start_time_estimation() {
113113
// schedule the next estimation step
114114
next_estimate_.expires_after(timeout_sec(cfg_->time_update_interval()));
115115
next_estimate_.async_wait([this](err_t err) {
116-
if (err != error::operation_aborted) start_time_estimation();
116+
if (err != asio::error::operation_aborted) start_time_estimation();
117117
});
118118
}
119119

@@ -170,7 +170,7 @@ void time_receiver::handle_receive_outcome(error_code err, std::size_t len) {
170170
} catch (std::exception &e) {
171171
LOG_F(WARNING, "Error while processing a time estimation return packet: %s", e.what());
172172
}
173-
if (err != error::operation_aborted) receive_next_packet();
173+
if (err != asio::error::operation_aborted) receive_next_packet();
174174
}
175175

176176
void time_receiver::result_aggregation_scheduled(error_code err) {

0 commit comments

Comments
 (0)