@@ -117,7 +117,6 @@ class wspp_client : public _websocket_client_impl, public std::enable_shared_fro
117
117
public:
118
118
wspp_client (websocket_client_config config) :
119
119
_websocket_client_impl (std::move(config)),
120
- m_work (utility::details::make_unique<boost::asio::io_service::work>(m_service)),
121
120
m_state (CREATED),
122
121
m_num_sends (0 )
123
122
#if defined(__APPLE__) || defined(ANDROID) || defined(_MS_WINDOWS)
@@ -130,9 +129,6 @@ class wspp_client : public _websocket_client_impl, public std::enable_shared_fro
130
129
_ASSERTE (m_state < DESTROYED);
131
130
std::unique_lock<std::mutex> lock (m_receive_queue_lock);
132
131
133
- // First, trigger the boost::io_service to spin down
134
- m_work.reset ();
135
-
136
132
// Now, what states could we be in?
137
133
switch (m_state) {
138
134
case DESTROYED:
@@ -164,14 +160,33 @@ class wspp_client : public _websocket_client_impl, public std::enable_shared_fro
164
160
}
165
161
166
162
// We have released the lock on all paths here
167
- m_service.stop ();
168
- if (m_thread.joinable ())
169
- m_thread.join ();
163
+ if (m_client)
164
+ {
165
+ if (m_client->is_tls_client ())
166
+ {
167
+ stop_client_impl<websocketpp::config::asio_tls_client>();
168
+ }
169
+ else
170
+ {
171
+ stop_client_impl<websocketpp::config::asio_client>();
172
+ }
173
+ if (m_thread.joinable ())
174
+ {
175
+ m_thread.join ();
176
+ }
177
+ }
170
178
171
179
// At this point, there should be no more references to me.
172
180
m_state = DESTROYED;
173
181
}
174
182
183
+ template <typename WebsocketConfigType>
184
+ void stop_client_impl ()
185
+ {
186
+ auto &client = m_client->client <WebsocketConfigType>();
187
+ client.stop_perpetual ();
188
+ }
189
+
175
190
pplx::task<void > connect ()
176
191
{
177
192
if (m_uri.scheme () == U (" wss" ))
@@ -227,7 +242,8 @@ class wspp_client : public _websocket_client_impl, public std::enable_shared_fro
227
242
228
243
client.clear_access_channels (websocketpp::log::alevel::all);
229
244
client.clear_error_channels (websocketpp::log::alevel::all);
230
- client.init_asio (&m_service);
245
+ client.init_asio ();
246
+ client.start_perpetual ();
231
247
232
248
_ASSERTE (m_state == CREATED);
233
249
client.set_open_handler ([this ](websocketpp::connection_hdl)
@@ -343,13 +359,7 @@ class wspp_client : public _websocket_client_impl, public std::enable_shared_fro
343
359
344
360
m_state = CONNECTING;
345
361
client.connect (con);
346
-
347
- m_thread = std::thread ([this ]()
348
- {
349
- m_service.run ();
350
- _ASSERTE (m_state == CLOSED);
351
- });
352
-
362
+ m_thread = std::thread (&websocketpp::client<WebsocketConfigType>::run, &client);
353
363
return pplx::create_task (m_connect_tce);
354
364
}
355
365
@@ -638,9 +648,6 @@ class wspp_client : public _websocket_client_impl, public std::enable_shared_fro
638
648
}
639
649
640
650
private:
641
- // The m_service should be the first member (and therefore the last to be destroyed)
642
- boost::asio::io_service m_service;
643
- std::unique_ptr<boost::asio::io_service::work> m_work;
644
651
std::thread m_thread;
645
652
646
653
// Perform type erasure to set the websocketpp client in use at runtime
0 commit comments