Skip to content

Commit a7f9140

Browse files
committed
Boost.Asio -> upstream Asio
1 parent 7ed2573 commit a7f9140

23 files changed

+75
-98
lines changed

CMakeLists.txt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ target_compile_features(lslboost PUBLIC cxx_std_11 cxx_lambda_init_captures)
177177
target_compile_definitions(lslboost
178178
PUBLIC
179179
BOOST_ALL_NO_LIB
180-
BOOST_ASIO_STANDALONE
181180
)
182181
target_include_directories(lslboost SYSTEM PUBLIC
183182
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lslboost>)
@@ -194,10 +193,12 @@ target_include_directories(lslobj
194193
target_include_directories(lslobj
195194
SYSTEM PUBLIC
196195
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/thirdparty/loguru>
196+
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/thirdparty/asio>
197197
)
198198
target_compile_definitions(lslobj PRIVATE
199199
LIBLSL_EXPORTS
200200
LOGURU_DEBUG_LOGGING=$<BOOL:${LSL_DEBUGLOG}>
201+
PUBLIC ASIO_NO_DEPRECATED
201202
)
202203

203204
# platform specific configuration
@@ -212,14 +213,11 @@ if(UNIX AND NOT APPLE)
212213
target_link_libraries(lslobj PRIVATE dl)
213214
endif()
214215
elseif(WIN32)
215-
target_link_libraries(lslobj PRIVATE iphlpapi winmm)
216-
target_link_libraries(lslboost PRIVATE mswsock ws2_32)
216+
target_link_libraries(lslobj PRIVATE iphlpapi winmm mswsock ws2_32)
217217
target_compile_definitions(lslobj
218218
PRIVATE _CRT_SECURE_NO_WARNINGS
219219
PUBLIC LSLNOAUTOLINK # don't use #pragma(lib) in CMake builds
220-
)
221-
target_compile_definitions(lslboost
222-
PUBLIC _WIN32_WINNT=${LSL_WINVER}
220+
_WIN32_WINNT=${LSL_WINVER}
223221
)
224222
endif()
225223

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

257255

src/cancellable_streambuf.h

Lines changed: 8 additions & 10 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,7 @@ 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(endpoint, [this](const asio::error_code &ec) { this->ec_ = ec; });
7775
this->as_context().restart();
7876
}
7977
ec_ = asio::error::would_block;
@@ -98,7 +96,7 @@ class cancellable_streambuf : public std::streambuf,
9896
* @return An \c error_code corresponding to the last error from the stream
9997
* buffer.
10098
*/
101-
const error_code &error() const { return ec_; }
99+
const asio::error_code &error() const { return ec_; }
102100

103101
protected:
104102
/// Close the socket if it's open.
@@ -131,7 +129,7 @@ class cancellable_streambuf : public std::streambuf,
131129
std::size_t bytes_transferred_;
132130
socket().async_receive(asio::buffer(asio::buffer(get_buffer_) + putback_max),
133131
[this, &bytes_transferred_](
134-
const error_code &ec, std::size_t bytes_transferred = 0) {
132+
const asio::error_code &ec, std::size_t bytes_transferred = 0) {
135133
this->ec_ = ec;
136134
bytes_transferred_ = bytes_transferred;
137135
});
@@ -155,7 +153,7 @@ class cancellable_streambuf : public std::streambuf,
155153
while (asio::buffer_size(buffer) > 0) {
156154
std::size_t bytes_transferred_;
157155
socket().async_send(asio::buffer(buffer),
158-
[this, &bytes_transferred_](const error_code &ec, std::size_t bytes_transferred) {
156+
[this, &bytes_transferred_](const asio::error_code &ec, std::size_t bytes_transferred) {
159157
this->ec_ = ec;
160158
bytes_transferred_ = bytes_transferred;
161159
});
@@ -192,7 +190,7 @@ class cancellable_streambuf : public std::streambuf,
192190
enum { putback_max = 8 };
193191
enum { buffer_size = 512 };
194192
char get_buffer_[buffer_size], put_buffer_[buffer_size];
195-
error_code ec_;
193+
asio::error_code ec_;
196194
std::atomic<bool> cancel_issued_{false};
197195
bool cancel_started_{false};
198196
std::recursive_mutex cancel_mut_;

src/data_receiver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ void data_receiver::data_thread() {
323323
// periodically update the last receive time to keep the watchdog happy
324324
if (srate <= 16 || (k & 0xF) == 0) conn_.update_receive_time(lsl_clock());
325325
}
326-
} catch (error_code &) {
326+
} catch (err_t) {
327327
// connection-level error: closed, reset, refused, etc.
328328
conn_.try_recover_from_error();
329329
} 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
@@ -5,8 +5,8 @@
55
#include "resolver_impl.h"
66
#include "stream_info_impl.h"
77
#include <atomic>
8-
#include <boost/asio/ip/tcp.hpp>
9-
#include <boost/asio/ip/udp.hpp>
8+
#include <asio/ip/tcp.hpp>
9+
#include <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
@@ -2,9 +2,7 @@
22
#include <cstdint>
33
#include <string>
44
#include <vector>
5-
#include <boost/asio/ip/address.hpp>
6-
7-
namespace asio = lslboost::asio;
5+
#include <asio/ip/address.hpp>
86

97
namespace lsl {
108

src/resolve_attempt_udp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#include "api_config.h"
33
#include "resolver_impl.h"
44
#include "socket_utils.h"
5-
#include <boost/asio/io_context.hpp>
6-
#include <boost/asio/ip/address.hpp>
7-
#include <boost/asio/ip/multicast.hpp>
5+
#include <asio/io_context.hpp>
6+
#include <asio/ip/address.hpp>
7+
#include <asio/ip/multicast.hpp>
88
#include <exception>
99
#include <loguru.hpp>
1010
#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)