Skip to content

Commit 6774a76

Browse files
committed
Renaming namespace
1 parent 3751cbf commit 6774a76

File tree

13 files changed

+141
-195
lines changed

13 files changed

+141
-195
lines changed

Release/include/cpprest/web_utilities.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace http { namespace client {
3737
class http_client_config;
3838
}}
3939

40-
namespace experimental { namespace web_sockets { namespace client {
40+
namespace experimental { namespace websockets { namespace client {
4141
class websocket_client_config;
4242
}}}
4343

@@ -75,7 +75,7 @@ class credentials
7575
private:
7676
friend class web::web_proxy;
7777
friend class web::http::client::http_client_config;
78-
friend class web::experimental::web_sockets::client::websocket_client_config;
78+
friend class web::experimental::websockets::client::websocket_client_config;
7979

8080
credentials() : m_is_set(false) {}
8181

Release/include/cpprest/ws_client.h

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace web
5757
/// WebSocket client is currently in beta.
5858
namespace experimental
5959
{
60-
namespace web_sockets
60+
namespace websockets
6161
{
6262
/// WebSocket client side library.
6363
namespace client
@@ -359,29 +359,10 @@ class websocket_client
359359
_ASYNCRTIMP websocket_client(websocket_client_config client_config);
360360

361361
/// <summary>
362+
/// Destructor
362363
/// </summary>
363364
~websocket_client() { }
364365

365-
/// <summary>
366-
/// Move constructor.
367-
/// </summary>
368-
websocket_client(websocket_client &&other)
369-
: m_client(std::move(other.m_client))
370-
{
371-
}
372-
373-
/// <summary>
374-
/// Move assignment operator.
375-
/// </summary>
376-
websocket_client &operator=(websocket_client &&other)
377-
{
378-
if(this != &other)
379-
{
380-
m_client = std::move(other.m_client);
381-
}
382-
return *this;
383-
}
384-
385366
/// <summary>
386367
/// Connects to the remote network destination. The connect method initiates the websocket handshake with the
387368
/// remote network destination, takes care of the protocol upgrade request.

Release/include/cpprest/ws_msg.h

Lines changed: 58 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include <limits>
3434

3535
#include "cpprest/xxpublic.h"
36-
#include "cpprest/containerstream.h"
36+
#include "cpprest/producerconsumerstream.h"
3737

3838
#if _NOT_PHONE8_
3939
#if defined(_MSC_VER) && (_MSC_VER >= 1800)
@@ -51,7 +51,7 @@ namespace web
5151
{
5252
namespace experimental
5353
{
54-
namespace web_sockets
54+
namespace websockets
5555
{
5656
namespace client
5757
{
@@ -62,7 +62,6 @@ namespace details
6262
class ws_desktop_client;
6363
}
6464

65-
6665
/// <summary>
6766
/// The different types of websocket message.
6867
/// Text type contains UTF-8 encoded data.
@@ -83,47 +82,26 @@ namespace details
8382
class _websocket_message
8483
{
8584
public:
86-
_ASYNCRTIMP void set_body(concurrency::streams::istream instream);
8785

88-
/// <summary>
89-
/// Get the streambuf for the message
90-
/// </summary>
91-
concurrency::streams::streambuf<uint8_t>& streambuf() { return m_buf; }
86+
concurrency::streams::streambuf<uint8_t> & body() { return m_buf; }
9287

93-
/// <summary>
94-
/// Set the streambuf for the message
95-
/// </summary>
96-
void set_streambuf(concurrency::streams::streambuf<uint8_t> buf) { m_buf = buf; }
88+
void set_body(const concurrency::streams::streambuf<uint8_t> &buf) { m_buf = buf; }
9789

9890
void set_msg_type(websocket_message_type msg_type) { m_msg_type = msg_type; }
9991

10092
void set_length(size_t len) { m_length = len; }
10193

102-
size_t length() { return m_length; }
94+
size_t length() const { return m_length; }
10395

104-
websocket_message_type message_type() { return m_msg_type; }
96+
websocket_message_type message_type() const { return m_msg_type; }
10597

106-
pplx::task_completion_event<void> _get_data_available() { return m_data_available; }
107-
108-
void _set_data_available() { m_data_available.set(); }
109-
110-
_ASYNCRTIMP std::string _extract_string();
111-
112-
/// <summary>
113-
/// Prepare the message with an output stream to receive network data
114-
/// </summary>
115-
_ASYNCRTIMP void _prepare_to_receive_data();
116-
117-
protected:
98+
private:
11899

119100
concurrency::streams::streambuf<uint8_t> m_buf;
120101

121102
websocket_message_type m_msg_type;
122103

123104
size_t m_length;
124-
125-
/// <summary> The TCE is used to signal the availability of the message body. </summary>
126-
pplx::task_completion_event<void> m_data_available;
127105
};
128106
}
129107

@@ -133,24 +111,36 @@ class _websocket_message
133111
class websocket_outgoing_message
134112
{
135113
public:
136-
websocket_outgoing_message()
137-
: _m_impl(std::make_shared<details::_websocket_message>()) {}
114+
115+
/// <summary>
116+
/// Creates an initially empty message for sending.
117+
/// </summary>
118+
websocket_outgoing_message() : _m_impl(std::make_shared<details::_websocket_message>()) {}
138119

139120
/// <summary>
140121
/// Sets a UTF-8 message as the message body.
141122
/// </summary>
142123
/// <param name="data">UTF-8 String containing body of the message.</param>
143-
void set_utf8_message(std::string data)
124+
void set_utf8_message(std::string &&data)
144125
{
145126
this->_set_message(std::move(data), websocket_message_type::text_message);
146127
}
147128

129+
/// <summary>
130+
/// Sets a UTF-8 message as the message body.
131+
/// </summary>
132+
/// <param name="data">UTF-8 String containing body of the message.</param>
133+
void set_utf8_message(const std::string &data)
134+
{
135+
this->_set_message(data, websocket_message_type::text_message);
136+
}
137+
148138
/// <summary>
149139
/// Sets a UTF-8 message as the message body.
150140
/// </summary>
151141
/// <param name="istream">casablanca input stream representing the body of the message.</param>
152142
/// <remarks>Upon sending, the entire stream may be buffered to determine the length.</remarks>
153-
void set_utf8_message(concurrency::streams::istream istream)
143+
void set_utf8_message(const concurrency::streams::istream &istream)
154144
{
155145
this->_set_message(istream, SIZE_MAX, websocket_message_type::text_message);
156146
}
@@ -160,7 +150,7 @@ class websocket_outgoing_message
160150
/// </summary>
161151
/// <param name="istream">casablanca input stream representing the body of the message.</param>
162152
/// <param name="len">number of bytes to send.</param>
163-
void set_utf8_message(concurrency::streams::istream istream, size_t len)
153+
void set_utf8_message(const concurrency::streams::istream &istream, size_t len)
164154
{
165155
this->_set_message(istream, len, websocket_message_type::text_message);
166156
}
@@ -170,7 +160,7 @@ class websocket_outgoing_message
170160
/// </summary>
171161
/// <param name="istream">casablanca input stream representing the body of the message.</param>
172162
/// <param name="len">number of bytes to send.</param>
173-
void set_binary_message(concurrency::streams::istream istream, size_t len)
163+
void set_binary_message(const concurrency::streams::istream &istream, size_t len)
174164
{
175165
this->_set_message(istream, len, websocket_message_type::binary_message);
176166
}
@@ -180,7 +170,7 @@ class websocket_outgoing_message
180170
/// </summary>
181171
/// <param name="istream">casablanca input stream representing the body of the message.</param>
182172
/// <remarks>Upon sending, the entire stream may be buffered to determine the length.</remarks>
183-
void set_binary_message(concurrency::streams::istream istream)
173+
void set_binary_message(const concurrency::streams::istream &istream)
184174
{
185175
this->_set_message(istream, SIZE_MAX, websocket_message_type::binary_message);
186176
}
@@ -192,22 +182,40 @@ class websocket_outgoing_message
192182

193183
std::shared_ptr<details::_websocket_message> _m_impl;
194184

195-
void _set_message(std::string data, websocket_message_type msg_type)
185+
pplx::task_completion_event<void> m_body_sent;
186+
187+
void signal_body_sent()
188+
{
189+
m_body_sent.set();
190+
}
191+
192+
void signal_body_sent(const std::exception_ptr &e)
193+
{
194+
m_body_sent.set_exception(e);
195+
}
196+
197+
pplx::task_completion_event<void> & body_sent() { return m_body_sent; }
198+
199+
void _set_message(std::string &&data, websocket_message_type msg_type)
196200
{
197201
_m_impl->set_msg_type(msg_type);
198202
_m_impl->set_length(data.length());
199-
auto istream = concurrency::streams::bytestream::open_istream<std::string>(std::move(data));
200-
_m_impl->set_body(istream);
203+
_m_impl->set_body(concurrency::streams::container_buffer<std::string>(std::move(data)));
201204
}
202205

203-
void _set_message(concurrency::streams::istream istream, size_t len, websocket_message_type msg_type)
206+
void _set_message(const std::string &data, websocket_message_type msg_type)
204207
{
205208
_m_impl->set_msg_type(msg_type);
206-
_m_impl->set_body(istream);
207-
_m_impl->set_length(len);
209+
_m_impl->set_length(data.length());
210+
_m_impl->set_body(concurrency::streams::container_buffer<std::string>(data));
208211
}
209212

210-
pplx::task_completion_event<void> m_send_tce;
213+
void _set_message(const concurrency::streams::istream &istream, size_t len, websocket_message_type msg_type)
214+
{
215+
_m_impl->set_msg_type(msg_type);
216+
_m_impl->set_body(istream.streambuf());
217+
_m_impl->set_length(len);
218+
}
211219
};
212220

213221
/// <summary>
@@ -216,7 +224,12 @@ class websocket_outgoing_message
216224
class websocket_incoming_message
217225
{
218226
public:
219-
websocket_incoming_message(): _m_impl(std::make_shared<details::_websocket_message>()) { }
227+
websocket_incoming_message() : _m_impl(std::make_shared<details::_websocket_message>())
228+
{
229+
// Body defaults to producer_consumer_buffer.
230+
// Perhaps in the future options could be exposed to allow the user to set.
231+
_m_impl->set_body(concurrency::streams::producer_consumer_buffer<uint8_t>());
232+
}
220233

221234
/// <summary>
222235
/// Extracts the body of the incoming message as a string value, only if the message type is UTF-8.
@@ -235,7 +248,7 @@ class websocket_incoming_message
235248
/// </remarks>
236249
concurrency::streams::istream body() const
237250
{
238-
return _m_impl->streambuf().create_istream();
251+
return _m_impl->body().create_istream();
239252
}
240253

241254
/// <summary>

0 commit comments

Comments
 (0)