Skip to content

Commit fde22b1

Browse files
committed
Boost.Asio -> upstream Asio
1 parent cc0e8d3 commit fde22b1

23 files changed

+79
-100
lines changed

CMakeLists.txt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ target_compile_features(lslboost PUBLIC cxx_std_11 cxx_lambda_init_captures)
179179
target_compile_definitions(lslboost
180180
PUBLIC
181181
BOOST_ALL_NO_LIB
182-
BOOST_ASIO_STANDALONE
183182
)
184183
target_include_directories(lslboost SYSTEM PUBLIC
185184
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lslboost>)
@@ -196,10 +195,12 @@ target_include_directories(lslobj
196195
target_include_directories(lslobj
197196
SYSTEM PUBLIC
198197
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/thirdparty/loguru>
198+
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/thirdparty/asio>
199199
)
200200
target_compile_definitions(lslobj PRIVATE
201201
LIBLSL_EXPORTS
202202
LOGURU_DEBUG_LOGGING=$<BOOL:${LSL_DEBUGLOG}>
203+
PUBLIC ASIO_NO_DEPRECATED
203204
)
204205

205206
# platform specific configuration
@@ -214,14 +215,11 @@ if(UNIX AND NOT APPLE)
214215
target_link_libraries(lslobj PRIVATE dl)
215216
endif()
216217
elseif(WIN32)
217-
target_link_libraries(lslobj PRIVATE iphlpapi winmm)
218-
target_link_libraries(lslboost PRIVATE mswsock ws2_32)
218+
target_link_libraries(lslobj PRIVATE iphlpapi winmm mswsock ws2_32)
219219
target_compile_definitions(lslobj
220220
PRIVATE _CRT_SECURE_NO_WARNINGS
221221
PUBLIC LSLNOAUTOLINK # don't use #pragma(lib) in CMake builds
222-
)
223-
target_compile_definitions(lslboost
224-
PUBLIC _WIN32_WINNT=${LSL_WINVER}
222+
_WIN32_WINNT=${LSL_WINVER}
225223
)
226224
endif()
227225

@@ -252,8 +250,8 @@ if(LSL_OPTIMIZATIONS)
252250
else()
253251
# build one object file for Asio instead of once every time an Asio function is called. See
254252
# https://think-async.com/Asio/asio-1.18.2/doc/asio/using.html#asio.using.optional_separate_compilation
255-
target_sources(lslboost PRIVATE lslboost/asio_objects.cpp)
256-
target_compile_definitions(lslboost PUBLIC BOOST_ASIO_SEPARATE_COMPILATION)
253+
target_sources(lslobj PRIVATE thirdparty/asio_objects.cpp)
254+
target_compile_definitions(lslobj PUBLIC ASIO_SEPARATE_COMPILATION)
257255
endif()
258256

259257

src/cancellable_streambuf.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@
1515

1616
#define BOOST_ASIO_NO_DEPRECATED
1717
#include "cancellation.h"
18-
#include <boost/asio/basic_stream_socket.hpp>
19-
#include <boost/asio/io_context.hpp>
20-
#include <boost/asio/ip/tcp.hpp>
18+
#include <asio/basic_stream_socket.hpp>
19+
#include <asio/io_context.hpp>
20+
#include <asio/ip/tcp.hpp>
2121
#include <exception>
2222
#include <streambuf>
2323

24-
namespace asio = lslboost::asio;
25-
using lslboost::system::error_code;
2624
using asio::io_context;
2725

2826
namespace lsl {
@@ -73,7 +71,8 @@ class cancellable_streambuf : public std::streambuf,
7371

7472
init_buffers();
7573
socket().close(ec_);
76-
socket().async_connect(endpoint, [this](const error_code &ec) { this->ec_ = ec; });
74+
socket().async_connect(
75+
endpoint, [this](const asio::error_code &ec) { this->ec_ = ec; });
7776
this->as_context().restart();
7877
}
7978
ec_ = asio::error::would_block;
@@ -98,7 +97,7 @@ class cancellable_streambuf : public std::streambuf,
9897
* @return An \c error_code corresponding to the last error from the stream
9998
* buffer.
10099
*/
101-
const error_code &error() const { return ec_; }
100+
const asio::error_code &error() const { return ec_; }
102101

103102
protected:
104103
/// Close the socket if it's open.
@@ -131,7 +130,7 @@ class cancellable_streambuf : public std::streambuf,
131130
std::size_t bytes_transferred_;
132131
socket().async_receive(asio::buffer(asio::buffer(get_buffer_) + putback_max),
133132
[this, &bytes_transferred_](
134-
const error_code &ec, std::size_t bytes_transferred = 0) {
133+
const asio::error_code &ec, std::size_t bytes_transferred = 0) {
135134
this->ec_ = ec;
136135
bytes_transferred_ = bytes_transferred;
137136
});
@@ -154,8 +153,9 @@ class cancellable_streambuf : public std::streambuf,
154153
asio::const_buffer buffer = asio::buffer(pbase(), pptr() - pbase());
155154
while (asio::buffer_size(buffer) > 0) {
156155
std::size_t bytes_transferred_;
157-
socket().async_send(asio::buffer(buffer),
158-
[this, &bytes_transferred_](const error_code &ec, std::size_t bytes_transferred) {
156+
socket().async_send(
157+
asio::buffer(buffer), [this, &bytes_transferred_](const asio::error_code &ec,
158+
std::size_t bytes_transferred) {
159159
this->ec_ = ec;
160160
bytes_transferred_ = bytes_transferred;
161161
});
@@ -192,7 +192,7 @@ class cancellable_streambuf : public std::streambuf,
192192
enum { putback_max = 8 };
193193
enum { buffer_size = 512 };
194194
char get_buffer_[buffer_size], put_buffer_[buffer_size];
195-
error_code ec_;
195+
asio::error_code ec_;
196196
std::atomic<bool> cancel_issued_{false};
197197
bool cancel_started_{false};
198198
std::recursive_mutex cancel_mut_;

src/data_receiver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ void data_receiver::data_thread() {
324324
// periodically update the last receive time to keep the watchdog happy
325325
if (srate <= 16 || (k & 0xF) == 0) conn_.update_receive_time(lsl_clock());
326326
}
327-
} catch (error_code &) {
327+
} catch (err_t) {
328328
// connection-level error: closed, reset, refused, etc.
329329
conn_.try_recover_from_error();
330330
} catch (lost_error &) {

src/forward.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,19 @@
44
#include <memory>
55
#include <string>
66

7-
namespace lslboost {
8-
class thread;
9-
namespace system {
10-
class error_code;
11-
}
127
namespace asio {
138
namespace ip {
149
class tcp;
1510
class udp;
1611
} // namespace ip
1712
class io_context;
1813
} // namespace asio
19-
} // namespace lslboost
2014

2115
namespace eos {
2216
class portable_oarchive;
2317
class portable_iarchive;
2418
} // namespace eos
2519

26-
namespace asio = lslboost::asio;
27-
2820
namespace lsl {
2921
/// shared pointers to various classes
3022
using factory_p = std::shared_ptr<class factory>;

src/info_receiver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void lsl::info_receiver::info_thread() {
7070
}
7171
fullinfo_upd_.notify_all();
7272
break;
73-
} catch (error_code &) {
73+
} catch (err_t) {
7474
// connection-level error: closed, reset, refused, etc.
7575
conn_.try_recover_from_error();
7676
} catch (std::exception &e) {

src/inlet_connection.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include "inlet_connection.h"
22
#include "api_config.h"
33
#include "resolver_impl.h"
4-
#include <boost/asio/io_context.hpp>
5-
#include <boost/asio/ip/address.hpp>
6-
#include <boost/asio/ip/basic_resolver.hpp>
4+
#include <asio/io_context.hpp>
5+
#include <asio/ip/address.hpp>
6+
#include <asio/ip/basic_resolver.hpp>
77
#include <chrono>
88
#include <exception>
99
#include <functional>
@@ -14,8 +14,6 @@
1414

1515
using namespace lsl;
1616
namespace ip = asio::ip;
17-
using lslboost::system::error_code;
18-
1917
inlet_connection::inlet_connection(const stream_info_impl &info, bool recover)
2018
: type_info_(info), host_info_(info), tcp_protocol_(tcp::v4()), udp_protocol_(udp::v4()),
2119
recovery_enabled_(recover), lost_(false), shutdown_(false), last_receive_time_(lsl_clock()),
@@ -114,7 +112,7 @@ void inlet_connection::disengage() {
114112
/// convert a IPv6 address or hostname into an non-link-local address
115113
ip::address resolve_v6_addr(const std::string &addr) {
116114
// Try to parse the IPv6 address
117-
error_code ec;
115+
asio::error_code ec;
118116
auto v6addr = ip::make_address_v6(addr, ec);
119117
if (!ec && !v6addr.is_link_local()) return v6addr;
120118

src/inlet_connection.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#include "cancellation.h"
55
#include "resolver_impl.h"
66
#include "stream_info_impl.h"
7+
#include <asio/ip/tcp.hpp>
8+
#include <asio/ip/udp.hpp>
79
#include <atomic>
8-
#include <boost/asio/ip/tcp.hpp>
9-
#include <boost/asio/ip/udp.hpp>
1010
#include <condition_variable>
1111
#include <map>
1212
#include <mutex>
@@ -26,7 +26,6 @@ using shared_lock_t = std::unique_lock<std::mutex>;
2626

2727
using unique_lock_t = std::unique_lock<shared_mutex_t>;
2828

29-
namespace asio = lslboost::asio;
3029
using asio::ip::tcp;
3130
using asio::ip::udp;
3231

src/netinterfaces.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#pragma once
2+
#include <asio/ip/address.hpp>
23
#include <cstdint>
34
#include <string>
45
#include <vector>
5-
#include <boost/asio/ip/address.hpp>
6-
7-
namespace asio = lslboost::asio;
86

97
namespace lsl {
108

src/resolve_attempt_udp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
#include "resolver_impl.h"
44
#include "socket_utils.h"
55
#include "util/strfuns.hpp"
6-
#include <boost/asio/io_context.hpp>
7-
#include <boost/asio/ip/address.hpp>
8-
#include <boost/asio/ip/multicast.hpp>
6+
#include <asio/io_context.hpp>
7+
#include <asio/ip/address.hpp>
8+
#include <asio/ip/multicast.hpp>
99
#include <exception>
1010
#include <loguru.hpp>
1111
#include <sstream>

src/resolve_attempt_udp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
#include "cancellation.h"
55
#include "forward.h"
66
#include "stream_info_impl.h"
7-
#include <boost/asio/ip/udp.hpp>
8-
#include <boost/asio/steady_timer.hpp>
7+
#include <asio/ip/udp.hpp>
8+
#include <asio/steady_timer.hpp>
99
#include <map>
1010
#include <memory>
1111
#include <string>
1212
#include <vector>
1313

1414
using asio::ip::udp;
15-
using err_t = const lslboost::system::error_code &;
15+
using err_t = const asio::error_code &;
1616

1717
namespace lsl {
1818

0 commit comments

Comments
 (0)