Skip to content

Commit cd148a0

Browse files
committed
Fix me
1 parent 4b0d6dd commit cd148a0

File tree

4 files changed

+54
-10
lines changed

4 files changed

+54
-10
lines changed

src/asio_prefix.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#pragma once
2+
3+
#if SIO_TLS
4+
#include <boost/asio/ssl/context.hpp>
5+
#endif
6+
7+
#include <boost/asio/steady_timer.hpp>
8+
#include <boost/system/error_code.hpp>
9+
#include <boost/asio/io_service.hpp>
10+
11+
namespace asio {
12+
using namespace boost::asio;
13+
14+
// See note above about boost <1.49 compatibility
15+
#if (BOOST_VERSION/100000) == 1 && ((BOOST_VERSION/100)%1000) > 48
16+
// Using boost::asio >=1.49 so we use chrono and steady_timer
17+
template <typename T>
18+
bool is_neg(T duration) {
19+
return duration.count() < 0;
20+
}
21+
22+
// If boost believes it has std::chrono available it will use it
23+
// so we should also use it for things that relate to boost, even
24+
// if the library would otherwise use boost::chrono.
25+
#if defined(BOOST_ASIO_HAS_STD_CHRONO)
26+
inline std::chrono::milliseconds milliseconds(long duration) {
27+
return std::chrono::milliseconds(duration);
28+
}
29+
#else
30+
inline lib::chrono::milliseconds milliseconds(long duration) {
31+
return lib::chrono::milliseconds(duration);
32+
}
33+
#endif
34+
#else
35+
// Using boost::asio <1.49 we pretend a deadline timer is a steady
36+
// timer and wrap the negative detection and duration conversion
37+
// appropriately.
38+
typedef boost::asio::deadline_timer steady_timer;
39+
40+
template <typename T>
41+
bool is_neg(T duration) {
42+
return duration.is_negative();
43+
}
44+
inline boost::posix_time::time_duration milliseconds(long duration) {
45+
return boost::posix_time::milliseconds(duration);
46+
}
47+
#endif
48+
49+
using boost::system::error_code;
50+
namespace errc = boost::system::errc;
51+
} // namespace asio

src/internal/sio_client_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ namespace sio
319319
if(!m_ping_timeout_timer)
320320
{
321321
m_ping_timeout_timer.reset(new asio::steady_timer(m_client.get_io_service()));
322-
std::error_code timeout_ec;
322+
asio::error_code timeout_ec;
323323
m_ping_timeout_timer->expires_from_now(milliseconds(m_ping_timeout), timeout_ec);
324324
m_ping_timeout_timer->async_wait(std::bind(&client_impl::timeout_pong, this, std::placeholders::_1));
325325
}

src/internal/sio_client_impl.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,7 @@ typedef websocketpp::config::asio_client client_config;
3131
#endif //SIO_TLS
3232
#endif //DEBUG
3333

34-
#if SIO_TLS
35-
#include <asio/ssl/context.hpp>
36-
#endif
37-
38-
#include <asio/steady_timer.hpp>
39-
#include <asio/error_code.hpp>
40-
#include <asio/io_service.hpp>
34+
#include "../asio_prefix.h"
4135

4236
#include <memory>
4337
#include <map>

src/sio_socket.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#include "sio_socket.h"
22
#include "internal/sio_packet.h"
33
#include "internal/sio_client_impl.h"
4-
#include <asio/steady_timer.hpp>
5-
#include <asio/error_code.hpp>
4+
#include "asio_prefix.h"
65
#include <queue>
76
#include <chrono>
87
#include <cstdarg>

0 commit comments

Comments
 (0)