Skip to content

Commit cb25d0b

Browse files
committed
Merge branch 'development' of https://git01.codeplex.com/casablanca into ws_winrt_connection
2 parents 9857cb9 + b0944e0 commit cb25d0b

File tree

9 files changed

+90
-146
lines changed

9 files changed

+90
-146
lines changed

Release/include/cpprest/containerstream.h

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ namespace Concurrency { namespace streams {
120120
/// </summary>
121121
virtual utility::size64_t size() const
122122
{
123-
return utility::size64_t(m_size);
123+
return utility::size64_t(m_data.size());
124124
}
125125

126126
/// <summary>
@@ -153,10 +153,10 @@ namespace Concurrency { namespace streams {
153153
{
154154
// See the comment in seek around the restriction that we do not allow read head to
155155
// seek beyond the current write_end.
156-
_ASSERTE(m_current_position <= m_size);
156+
_ASSERTE(m_current_position <= m_data.size());
157157

158158
SafeSize readhead(m_current_position);
159-
SafeSize writeend(m_size);
159+
SafeSize writeend(m_data.size());
160160
return (size_t)(writeend - readhead);
161161
}
162162

@@ -330,7 +330,7 @@ namespace Concurrency { namespace streams {
330330
// For now, we assume that the current write_end is the end of the buffer. We use this artificial
331331
// end to restrict the read head from seeking beyond what is available.
332332

333-
pos_type end(m_size);
333+
pos_type end(m_data.size());
334334

335335
if (position >= beg)
336336
{
@@ -378,7 +378,7 @@ namespace Concurrency { namespace streams {
378378
{
379379
pos_type beg = 0;
380380
pos_type cur = static_cast<pos_type>(m_current_position);
381-
pos_type end = static_cast<pos_type>(m_size);
381+
pos_type end = static_cast<pos_type>(m_data.size());
382382

383383
switch ( way )
384384
{
@@ -404,8 +404,7 @@ namespace Concurrency { namespace streams {
404404
/// </summary>
405405
basic_container_buffer(std::ios_base::openmode mode)
406406
: streambuf_state_manager<typename _CollectionType::value_type>(mode),
407-
m_current_position(0),
408-
m_size(0)
407+
m_current_position(0)
409408
{
410409
validate_mode(mode);
411410
}
@@ -416,8 +415,7 @@ namespace Concurrency { namespace streams {
416415
basic_container_buffer(_CollectionType data, std::ios_base::openmode mode)
417416
: streambuf_state_manager<typename _CollectionType::value_type>(mode),
418417
m_data(std::move(data)),
419-
m_current_position((mode & std::ios_base::in) ? 0 : m_data.size()),
420-
m_size(m_data.size())
418+
m_current_position((mode & std::ios_base::in) ? 0 : m_data.size())
421419
{
422420
validate_mode(mode);
423421
}
@@ -509,10 +507,8 @@ namespace Concurrency { namespace streams {
509507
/// </summary>
510508
void resize_for_write(size_t newPos)
511509
{
512-
_ASSERTE(m_size <= m_data.size());
513-
514510
// Resize the container if required
515-
if (newPos > m_size)
511+
if (newPos > m_data.size())
516512
{
517513
m_data.resize(newPos);
518514
}
@@ -525,23 +521,14 @@ namespace Concurrency { namespace streams {
525521
{
526522
// The new write head
527523
m_current_position = newPos;
528-
529-
if ( this->can_write() && m_size < m_current_position)
530-
{
531-
// Update the size of the buffer with valid data if required
532-
m_size = m_current_position;
533-
}
534-
535-
_ASSERTE(m_current_position <= m_size);
536-
_ASSERTE(m_size <= m_data.size());
524+
_ASSERTE(m_current_position <= m_data.size());
537525
}
538526

539527
// The actual data store
540528
_CollectionType m_data;
541529

542530
// Read/write head
543531
size_t m_current_position;
544-
size_t m_size;
545532
};
546533

547534
} // namespace details

Release/include/cpprest/ws_msg.h

Lines changed: 19 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -77,46 +77,20 @@ enum class websocket_message_type
7777
pong
7878
};
7979

80-
namespace details
81-
{
82-
class _websocket_message
83-
{
84-
public:
85-
86-
void set_msg_type(websocket_message_type msg_type) { m_msg_type = msg_type; }
87-
88-
void set_length(size_t len) { m_length = len; }
89-
90-
size_t length() const { return m_length; }
91-
92-
websocket_message_type message_type() const { return m_msg_type; }
93-
94-
private:
95-
96-
websocket_message_type m_msg_type;
97-
size_t m_length;
98-
};
99-
}
100-
10180
/// <summary>
10281
/// Represents an outgoing websocket message
10382
/// </summary>
10483
class websocket_outgoing_message
10584
{
10685
public:
10786

108-
/// <summary>
109-
/// Creates an initially empty message for sending.
110-
/// </summary>
111-
websocket_outgoing_message() : _m_impl(std::make_shared<details::_websocket_message>()) {}
112-
11387
/// <summary>
11488
/// Sets a UTF-8 message as the message body.
11589
/// </summary>
11690
/// <param name="data">UTF-8 String containing body of the message.</param>
11791
void set_utf8_message(std::string &&data)
11892
{
119-
this->_set_message(std::move(data), websocket_message_type::text_message);
93+
this->set_message(concurrency::streams::container_buffer<std::string>(std::move(data)));
12094
}
12195

12296
/// <summary>
@@ -125,7 +99,7 @@ class websocket_outgoing_message
12599
/// <param name="data">UTF-8 String containing body of the message.</param>
126100
void set_utf8_message(const std::string &data)
127101
{
128-
this->_set_message(data, websocket_message_type::text_message);
102+
this->set_message(concurrency::streams::container_buffer<std::string>(data));
129103
}
130104

131105
/// <summary>
@@ -135,7 +109,7 @@ class websocket_outgoing_message
135109
/// <remarks>Upon sending, the entire stream may be buffered to determine the length.</remarks>
136110
void set_utf8_message(const concurrency::streams::istream &istream)
137111
{
138-
this->_set_message(istream, SIZE_MAX, websocket_message_type::text_message);
112+
this->set_message(istream, SIZE_MAX, websocket_message_type::text_message);
139113
}
140114

141115
/// <summary>
@@ -145,7 +119,7 @@ class websocket_outgoing_message
145119
/// <param name="len">number of bytes to send.</param>
146120
void set_utf8_message(const concurrency::streams::istream &istream, size_t len)
147121
{
148-
this->_set_message(istream, len, websocket_message_type::text_message);
122+
this->set_message(istream, len, websocket_message_type::text_message);
149123
}
150124

151125
/// <summary>
@@ -155,7 +129,7 @@ class websocket_outgoing_message
155129
/// <param name="len">number of bytes to send.</param>
156130
void set_binary_message(const concurrency::streams::istream &istream, size_t len)
157131
{
158-
this->_set_message(istream, len, websocket_message_type::binary_message);
132+
this->set_message(istream, len, websocket_message_type::binary_message);
159133
}
160134

161135
/// <summary>
@@ -165,17 +139,17 @@ class websocket_outgoing_message
165139
/// <remarks>Upon sending, the entire stream may be buffered to determine the length.</remarks>
166140
void set_binary_message(const concurrency::streams::istream &istream)
167141
{
168-
this->_set_message(istream, SIZE_MAX, websocket_message_type::binary_message);
142+
this->set_message(istream, SIZE_MAX, websocket_message_type::binary_message);
169143
}
170144

171145
private:
172146
friend class details::winrt_client;
173147
friend class details::wspp_client;
174148

175-
std::shared_ptr<details::_websocket_message> _m_impl;
176-
177149
pplx::task_completion_event<void> m_body_sent;
178150
concurrency::streams::streambuf<uint8_t> m_body;
151+
websocket_message_type m_msg_type;
152+
size_t m_length;
179153

180154
void signal_body_sent() const
181155
{
@@ -189,24 +163,17 @@ class websocket_outgoing_message
189163

190164
const pplx::task_completion_event<void> & body_sent() const { return m_body_sent; }
191165

192-
void _set_message(std::string &&data, websocket_message_type msg_type)
166+
void set_message(const concurrency::streams::container_buffer<std::string> &buffer)
193167
{
194-
_m_impl->set_msg_type(msg_type);
195-
_m_impl->set_length(data.length());
196-
m_body = concurrency::streams::container_buffer<std::string>(std::move(data));
168+
m_msg_type = websocket_message_type::text_message;
169+
m_length = static_cast<size_t>(buffer.size());
170+
m_body = buffer;
197171
}
198172

199-
void _set_message(const std::string &data, websocket_message_type msg_type)
173+
void set_message(const concurrency::streams::istream &istream, size_t len, websocket_message_type msg_type)
200174
{
201-
_m_impl->set_msg_type(msg_type);
202-
_m_impl->set_length(data.length());
203-
m_body = concurrency::streams::container_buffer<std::string>(data);
204-
}
205-
206-
void _set_message(const concurrency::streams::istream &istream, size_t len, websocket_message_type msg_type)
207-
{
208-
_m_impl->set_msg_type(msg_type);
209-
_m_impl->set_length(len);
175+
m_msg_type = msg_type;
176+
m_length = len;
210177
m_body = istream.streambuf();
211178
}
212179
};
@@ -217,9 +184,6 @@ class websocket_outgoing_message
217184
class websocket_incoming_message
218185
{
219186
public:
220-
websocket_incoming_message() : _m_impl(std::make_shared<details::_websocket_message>())
221-
{
222-
}
223187

224188
/// <summary>
225189
/// Extracts the body of the incoming message as a string value, only if the message type is UTF-8.
@@ -250,7 +214,7 @@ class websocket_incoming_message
250214
/// </summary>
251215
size_t length() const
252216
{
253-
return _m_impl->length();
217+
return static_cast<size_t>(m_body.size());
254218
}
255219

256220
/// <summary>
@@ -259,7 +223,7 @@ class websocket_incoming_message
259223
CASABLANCA_DEPRECATED("Incorrectly spelled API, use message_type() instead.")
260224
websocket_message_type messge_type() const
261225
{
262-
return _m_impl->message_type();
226+
return m_msg_type;
263227
}
264228

265229
/// <summary>
@@ -268,7 +232,7 @@ class websocket_incoming_message
268232
/// <returns>websocket_message_type</returns>
269233
websocket_message_type message_type() const
270234
{
271-
return _m_impl->message_type();
235+
return m_msg_type;
272236
}
273237

274238
private:
@@ -281,8 +245,7 @@ class websocket_incoming_message
281245
// Store message body in a container buffer backed by a string.
282246
// Allows for optimization in the string message cases.
283247
concurrency::streams::container_buffer<std::string> m_body;
284-
285-
std::shared_ptr<details::_websocket_message> _m_impl;
248+
websocket_message_type m_msg_type;
286249
};
287250

288251
}}}

0 commit comments

Comments
 (0)