Skip to content

Commit 04d43e1

Browse files
committed
Merge branch 'development' of https://git01.codeplex.com/casablanca into save_space
2 parents 62468b5 + f53b390 commit 04d43e1

File tree

5 files changed

+49
-34
lines changed

5 files changed

+49
-34
lines changed

Release/include/cpprest/ws_msg.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,21 @@ class websocket_incoming_message
220220
/// <summary>
221221
/// Returns the type of the received message.
222222
/// </summary>
223+
CASABLANCA_DEPRECATED("Incorrectly spelled API, use message_type() instead.")
223224
websocket_message_type messge_type() const
224225
{
225226
return m_msg_type;
226227
}
227228

229+
/// <summary>
230+
/// Returns the type of the received message, either string or binary.
231+
/// </summary>
232+
/// <returns>websocket_message_type</returns>
233+
websocket_message_type message_type() const
234+
{
235+
return _m_impl->message_type();
236+
}
237+
228238
private:
229239
friend class details::winrt_client;
230240
friend class details::wspp_client;

Release/src/websockets/client/ws_winrt.cpp

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -233,18 +233,16 @@ class winrt_client : public _websocket_client_impl, public std::enable_shared_fr
233233
return pplx::task_from_exception<void>(websocket_exception("Message size too large. Ensure message length is less than UINT_MAX."));
234234
}
235235

236+
if (++m_num_sends == 1) // No sends in progress
236237
{
237-
if (++m_num_sends == 1) // No sends in progress
238-
{
239-
// Start sending the message
240-
send_msg(msg);
241-
}
242-
else
243-
{
244-
// Only actually have to take the lock if touching the queue.
245-
std::lock_guard<std::mutex> lock(m_send_lock);
246-
m_outgoing_msg_queue.push(msg);
247-
}
238+
// Start sending the message
239+
send_msg(msg);
240+
}
241+
else
242+
{
243+
// Only actually have to take the lock if touching the queue.
244+
std::lock_guard<std::mutex> lock(m_send_lock);
245+
m_outgoing_msg_queue.push(msg);
248246
}
249247
return pplx::create_task(msg.body_sent());
250248
}
@@ -347,13 +345,19 @@ class winrt_client : public _websocket_client_impl, public std::enable_shared_fr
347345
eptr = std::make_exception_ptr(websocket_exception("Failed to send all the bytes."));
348346
}
349347
}
350-
catch (const websocket_exception& ex)
348+
catch (Platform::Exception^ e)
351349
{
352-
eptr = std::make_exception_ptr(ex);
350+
// Convert to websocket_exception.
351+
eptr = std::make_exception_ptr(websocket_exception(e->HResult));
352+
}
353+
catch (const websocket_exception &e)
354+
{
355+
// Catch to avoid slicing and losing the type if falling through to catch (...).
356+
eptr = std::make_exception_ptr(e);
353357
}
354358
catch (...)
355359
{
356-
eptr = std::make_exception_ptr(websocket_exception("Failed to send data over the websocket connection."));
360+
eptr = std::make_exception_ptr(std::current_exception());
357361
}
358362

359363
if (acquired)
@@ -366,21 +370,22 @@ class winrt_client : public _websocket_client_impl, public std::enable_shared_fr
366370
{
367371
msg.signal_body_sent(eptr);
368372
}
373+
else
374+
{
375+
msg.signal_body_sent();
376+
}
369377

378+
if (--this_client->m_num_sends > 0)
370379
{
371-
if (--this_client->m_num_sends > 0)
380+
// Only hold the lock when actually touching the queue.
381+
websocket_outgoing_message next_msg;
372382
{
373-
// Only hold the lock when actually touching the queue.
374-
websocket_outgoing_message next_msg;
375-
{
376-
std::lock_guard<std::mutex> lock(this_client->m_send_lock);
377-
next_msg = this_client->m_outgoing_msg_queue.front();
378-
this_client->m_outgoing_msg_queue.pop();
379-
}
380-
this_client->send_msg(next_msg);
383+
std::lock_guard<std::mutex> lock(this_client->m_send_lock);
384+
next_msg = this_client->m_outgoing_msg_queue.front();
385+
this_client->m_outgoing_msg_queue.pop();
381386
}
387+
this_client->send_msg(next_msg);
382388
}
383-
msg.signal_body_sent();
384389
});
385390
}
386391

@@ -488,7 +493,7 @@ void ReceiveContext::OnReceive(MessageWebSocket^ sender, MessageWebSocketMessage
488493
}
489494
m_receive_handler(incoming_msg);
490495
}
491-
catch(...)
496+
catch (...)
492497
{
493498
// Swallow the exception for now. Following up on this with the WinRT team.
494499
// We can handle this more gracefully once we know the scenarios where DataReader operations can throw an exception:

Release/tests/functional/websockets/client/authentication_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ TEST(ssl_test)
9898
auto ret_str = ret_msg.extract_string().get();
9999

100100
VERIFY_ARE_EQUAL(body_str.compare(ret_str), 0);
101-
VERIFY_ARE_EQUAL(ret_msg.messge_type(), websocket_message_type::text_message);
101+
VERIFY_ARE_EQUAL(ret_msg.message_type(), websocket_message_type::text_message);
102102
});
103103

104104
websocket_outgoing_message msg;

Release/tests/functional/websockets/client/client_construction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ TEST_FIXTURE(uri_address, move_operations)
128128
auto ret_str = ret_msg.extract_string().get();
129129

130130
VERIFY_ARE_EQUAL(body.compare(ret_str), 0);
131-
VERIFY_ARE_EQUAL(ret_msg.messge_type(), websocket_message_type::text_message);
131+
VERIFY_ARE_EQUAL(ret_msg.message_type(), websocket_message_type::text_message);
132132
});
133133

134134
test_websocket_msg rmsg;
@@ -158,7 +158,7 @@ TEST_FIXTURE(uri_address, move_operations)
158158
auto ret_str = ret_msg.extract_string().get();
159159

160160
VERIFY_ARE_EQUAL(body.compare(ret_str), 0);
161-
VERIFY_ARE_EQUAL(ret_msg.messge_type(), websocket_message_type::text_message);
161+
VERIFY_ARE_EQUAL(ret_msg.message_type(), websocket_message_type::text_message);
162162
});
163163
t1.wait();
164164
client.close().wait();

Release/tests/functional/websockets/client/receive_msg_tests.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pplx::task<void> receive_text_msg_helper(websocket_client& client,
5757
auto ret_str = ret_msg.extract_string().get();
5858

5959
VERIFY_ARE_EQUAL(body_str.compare(ret_str), 0);
60-
VERIFY_ARE_EQUAL(ret_msg.messge_type(), websocket_message_type::text_message);
60+
VERIFY_ARE_EQUAL(ret_msg.message_type(), websocket_message_type::text_message);
6161
});
6262

6363
test_websocket_msg msg;
@@ -87,9 +87,9 @@ pplx::task<void> receive_msg_stream_helper(websocket_client& client,
8787
VERIFY_ARE_EQUAL(ret_msg.length(), body.size());
8888
VERIFY_ARE_EQUAL(body, ret_data.collection());
8989
if (type == test_websocket_message_type::WEB_SOCKET_BINARY_MESSAGE_TYPE)
90-
VERIFY_ARE_EQUAL(ret_msg.messge_type(), websocket_message_type::binary_message);
90+
VERIFY_ARE_EQUAL(ret_msg.message_type(), websocket_message_type::binary_message);
9191
else if (type == test_websocket_message_type::WEB_SOCKET_UTF8_MESSAGE_TYPE)
92-
VERIFY_ARE_EQUAL(ret_msg.messge_type(), websocket_message_type::text_message);
92+
VERIFY_ARE_EQUAL(ret_msg.message_type(), websocket_message_type::text_message);
9393
});
9494

9595
test_websocket_msg msg;
@@ -154,7 +154,7 @@ TEST_FIXTURE(uri_address, receive_text_msg_fragments, "Ignore", "898451")
154154
auto ret_str = ret_msg.extract_string().get();
155155

156156
VERIFY_ARE_EQUAL(body_str.compare(ret_str), 0);
157-
VERIFY_ARE_EQUAL(ret_msg.messge_type(), websocket_message_type::text_message);
157+
VERIFY_ARE_EQUAL(ret_msg.message_type(), websocket_message_type::text_message);
158158
});
159159

160160
test_websocket_msg msg1;
@@ -235,7 +235,7 @@ TEST_FIXTURE(uri_address, receive_after_server_send)
235235
{
236236
auto ret_str = ret_msg.extract_string().get();
237237
VERIFY_ARE_EQUAL(body_str.compare(ret_str), 0);
238-
VERIFY_ARE_EQUAL(ret_msg.messge_type(), websocket_message_type::text_message);
238+
VERIFY_ARE_EQUAL(ret_msg.message_type(), websocket_message_type::text_message);
239239
}).wait();
240240

241241
client.close().wait();
@@ -256,7 +256,7 @@ TEST_FIXTURE(uri_address, receive_before_connect)
256256
auto ret_str = ret_msg.extract_string().get();
257257

258258
VERIFY_ARE_EQUAL(body_str.compare(ret_str), 0);
259-
VERIFY_ARE_EQUAL(ret_msg.messge_type(), websocket_message_type::text_message);
259+
VERIFY_ARE_EQUAL(ret_msg.message_type(), websocket_message_type::text_message);
260260
});
261261

262262
// Connect after the client is waiting on a receive task.

0 commit comments

Comments
 (0)