Skip to content

Commit b3a30ce

Browse files
committed
Deprecating misspelled API websocket_incoming_message::messge_type(), replaced with websocket_incoming_message::message_type().e Please enter the commit message for your changes. Lines starting
1 parent 3cf0400 commit b3a30ce

File tree

5 files changed

+41
-36
lines changed

5 files changed

+41
-36
lines changed

Release/include/cpprest/ws_msg.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,21 @@ class websocket_incoming_message
256256
/// <summary>
257257
/// Returns the type of the received message.
258258
/// </summary>
259+
CASABLANCA_DEPRECATED("Incorrectly spelled API, use message_type() instead.")
259260
websocket_message_type messge_type() const
260261
{
261262
return _m_impl->message_type();
262263
}
263264

265+
/// <summary>
266+
/// Returns the type of the received message, either string or binary.
267+
/// </summary>
268+
/// <returns>websocket_message_type</returns>
269+
websocket_message_type message_type() const
270+
{
271+
return _m_impl->message_type();
272+
}
273+
264274
private:
265275
friend class details::winrt_client;
266276
friend class details::wspp_client;

Release/src/websockets/client/ws_winrt.cpp

Lines changed: 22 additions & 27 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,9 @@ 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)
351-
{
352-
eptr = std::make_exception_ptr(ex);
353-
}
354348
catch (...)
355349
{
356-
eptr = std::make_exception_ptr(websocket_exception("Failed to send data over the websocket connection."));
350+
eptr = std::make_exception_ptr(std::current_exception());
357351
}
358352

359353
if (acquired)
@@ -366,21 +360,22 @@ class winrt_client : public _websocket_client_impl, public std::enable_shared_fr
366360
{
367361
msg.signal_body_sent(eptr);
368362
}
363+
else
364+
{
365+
msg.signal_body_sent();
366+
}
369367

368+
if (--this_client->m_num_sends > 0)
370369
{
371-
if (--this_client->m_num_sends > 0)
370+
// Only hold the lock when actually touching the queue.
371+
websocket_outgoing_message next_msg;
372372
{
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);
373+
std::lock_guard<std::mutex> lock(this_client->m_send_lock);
374+
next_msg = this_client->m_outgoing_msg_queue.front();
375+
this_client->m_outgoing_msg_queue.pop();
381376
}
377+
this_client->send_msg(next_msg);
382378
}
383-
msg.signal_body_sent();
384379
});
385380
}
386381

@@ -490,7 +485,7 @@ void ReceiveContext::OnReceive(MessageWebSocket^ sender, MessageWebSocketMessage
490485
msg->set_length(len);
491486
m_receive_handler(ws_incoming_message);
492487
}
493-
catch(...)
488+
catch (...)
494489
{
495490
// Swallow the exception for now. Following up on this with the WinRT team.
496491
// 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

9999
VERIFY_ARE_EQUAL(ret_msg.length(), body_str.length());
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

129129
VERIFY_ARE_EQUAL(ret_msg.length(), body.length());
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

159159
VERIFY_ARE_EQUAL(ret_msg.length(), body.length());
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

5858
VERIFY_ARE_EQUAL(ret_msg.length(), body_str.length());
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

257257
VERIFY_ARE_EQUAL(ret_msg.length(), body_str.length());
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)