File tree Expand file tree Collapse file tree 4 files changed +71
-0
lines changed
tests/functional/http/client Expand file tree Collapse file tree 4 files changed +71
-0
lines changed Original file line number Diff line number Diff line change 16
16
#ifndef _PPLXTASKS_H
17
17
#define _PPLXTASKS_H
18
18
19
+ #include " cpprest/details/cpprest_compat.h"
20
+
19
21
#if (defined(_MSC_VER) && (_MSC_VER >= 1800)) && !CPPREST_FORCE_PPLX
20
22
#include < ppltasks.h>
21
23
namespace pplx = Concurrency;
24
+
25
+ namespace Concurrency
26
+ {
27
+
28
+ // / <summary>
29
+ // / Sets the ambient scheduler to be used by the PPL constructs.
30
+ // / </summary>
31
+ _ASYNCRTIMP void __cdecl set_cpprestsdk_ambient_scheduler (const std::shared_ptr<scheduler_interface>& _Scheduler);
32
+
33
+ // / <summary>
34
+ // / Gets the ambient scheduler to be used by the PPL constructs
35
+ // / </summary>
36
+ _ASYNCRTIMP const std::shared_ptr<scheduler_interface>& __cdecl get_cpprestsdk_ambient_scheduler ();
37
+
38
+ } // namespace Concurrency
39
+
22
40
#if (_MSC_VER >= 1900)
23
41
#include < concrt.h>
24
42
namespace Concurrency {
Original file line number Diff line number Diff line change @@ -103,6 +103,7 @@ elseif(CPPREST_PPLX_IMPL STREQUAL "linux")
103
103
install (FILES ../include/pplx/threadpool.h DESTINATION include /pplx )
104
104
endif ()
105
105
elseif (CPPREST_PPLX_IMPL STREQUAL "win" )
106
+ target_sources (cpprest PRIVATE pplx/pplxwin.cpp )
106
107
if (CPPREST_WEBSOCKETS_IMPL STREQUAL "wspp" )
107
108
target_sources (cpprest PRIVATE pplx/threadpool.cpp ../include/pplx/threadpool.h )
108
109
if (CPPREST_INSTALL_HEADERS )
Original file line number Diff line number Diff line change @@ -275,4 +275,19 @@ namespace details
275
275
276
276
} // namespace pplx
277
277
278
+ #else
279
+ namespace Concurrency
280
+ {
281
+
282
+ void __cdecl set_cpprestsdk_ambient_scheduler (const std::shared_ptr<scheduler_interface>& _Scheduler)
283
+ {
284
+ pplx::set_ambient_scheduler (_Scheduler);
285
+ }
286
+
287
+ const std::shared_ptr<scheduler_interface>& __cdecl get_cpprestsdk_ambient_scheduler ()
288
+ {
289
+ return pplx::get_ambient_scheduler ();
290
+ }
291
+
292
+ } // namespace pplx
278
293
#endif
Original file line number Diff line number Diff line change @@ -111,6 +111,43 @@ TEST_FIXTURE(uri_address, multiple_https_requests)
111
111
});
112
112
}
113
113
114
+ #if (defined(_MSC_VER) && (_MSC_VER >= 1800)) && !CPPREST_FORCE_PPLX
115
+ TEST_FIXTURE (uri_address, multiple_https_requests_sync_scheduler)
116
+ {
117
+ struct sync_scheduler : public scheduler_interface
118
+ {
119
+ public:
120
+ virtual void schedule (TaskProc_t function, PVOID context) override
121
+ {
122
+ function (context);
123
+ }
124
+ };
125
+
126
+ // Save the current ambient scheduler
127
+ const auto scheduler = get_cpprestsdk_ambient_scheduler ();
128
+
129
+ // Change the ambient scheduler to one that schedules synchronously
130
+ static std::shared_ptr<scheduler_interface> syncScheduler = std::make_shared<sync_scheduler>();
131
+ set_cpprestsdk_ambient_scheduler (syncScheduler);
132
+
133
+ handle_timeout ([&] {
134
+ // Use code.google.com instead of www.google.com, which redirects
135
+ http_client client (U (" https://code.google.com" ));
136
+
137
+ http_response response;
138
+ for (int i = 0 ; i < 5 ; ++i)
139
+ {
140
+ response = client.request (methods::GET).get ();
141
+ VERIFY_ARE_EQUAL (status_codes::OK, response.status_code ());
142
+ response.content_ready ().wait ();
143
+ }
144
+ });
145
+
146
+ // Revert to the original scheduler
147
+ set_cpprestsdk_ambient_scheduler (scheduler);
148
+ }
149
+ #endif
150
+
114
151
TEST_FIXTURE (uri_address, reading_google_stream)
115
152
{
116
153
handle_timeout ([&]
You can’t perform that action at this time.
0 commit comments