Skip to content

Commit da16d21

Browse files
Remove pplx::task from product code (#7)
1 parent 2d491f4 commit da16d21

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+644
-905
lines changed

include/signalrclient/http_client.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace signalr
3232
http_response(http_response&& rhs) noexcept : status_code(rhs.status_code), content(std::move(rhs.content)) {}
3333
http_response(int code, const std::string& content) : status_code(code), content(content) {}
3434

35-
http_response& operator=(http_response&& rhs)
35+
http_response& operator=(http_response&& rhs) noexcept
3636
{
3737
status_code = rhs.status_code;
3838
content = std::move(rhs.content);
@@ -47,7 +47,7 @@ namespace signalr
4747
class http_client
4848
{
4949
public:
50-
virtual void send(std::string url, http_request request, std::function<void(http_response, std::exception_ptr)> callback) = 0;
50+
virtual void send(std::string url, const http_request& request, std::function<void(const http_response&, std::exception_ptr)> callback) = 0;
5151

5252
virtual ~http_client() {}
5353
};

include/signalrclient/websocket_client.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ namespace signalr
1313
public:
1414
virtual ~websocket_client() {};
1515

16-
virtual void start(std::string url, transfer_format format, std::function<void(std::exception_ptr)> callback) = 0;
16+
virtual void start(const std::string& url, transfer_format format, std::function<void(std::exception_ptr)> callback) = 0;
1717

1818
virtual void stop(std::function<void(std::exception_ptr)> callback) = 0;
1919

20-
virtual void send(std::string payload, std::function<void(std::exception_ptr)> callback) = 0;
20+
virtual void send(const std::string& payload, std::function<void(std::exception_ptr)> callback) = 0;
2121

22-
virtual void receive(std::function<void(std::string, std::exception_ptr)> callback) = 0;
22+
virtual void receive(std::function<void(const std::string&, std::exception_ptr)> callback) = 0;
2323
};
2424
}

src/signalrclient/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ set (SOURCES
44
connection_impl.cpp
55
default_http_client.cpp
66
default_websocket_client.cpp
7-
http_sender.cpp
87
hub_connection.cpp
98
hub_connection_impl.cpp
109
logger.cpp
@@ -15,8 +14,6 @@ set (SOURCES
1514
transport.cpp
1615
transport_factory.cpp
1716
url_builder.cpp
18-
web_request.cpp
19-
web_request_factory.cpp
2017
websocket_transport.cpp
2118
)
2219

src/signalrclient/event.h renamed to src/signalrclient/cancellation_token.h

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,21 @@
99

1010
namespace signalr
1111
{
12-
class event
12+
class canceled_exception : public std::exception
1313
{
14-
private:
15-
std::mutex m_lock;
16-
std::condition_variable m_condition;
17-
bool m_signaled;
18-
public:
14+
};
1915

16+
class cancellation_token
17+
{
18+
public:
2019
static const unsigned int timeout_infinite = 0xFFFFFFFF;
2120

22-
event() noexcept
21+
cancellation_token() noexcept
2322
: m_signaled(false)
2423
{
2524
}
2625

27-
void set()
26+
void cancel()
2827
{
2928
std::lock_guard<std::mutex> lock(m_lock);
3029
m_signaled = true;
@@ -37,10 +36,15 @@ namespace signalr
3736
m_signaled = false;
3837
}
3938

39+
bool is_canceled() const
40+
{
41+
return m_signaled;
42+
}
43+
4044
unsigned int wait(unsigned int timeout)
4145
{
4246
std::unique_lock<std::mutex> lock(m_lock);
43-
if (timeout == event::timeout_infinite)
47+
if (timeout == cancellation_token::timeout_infinite)
4448
{
4549
m_condition.wait(lock, [this]() noexcept { return m_signaled; });
4650
return 0;
@@ -51,13 +55,25 @@ namespace signalr
5155
const auto status = m_condition.wait_for(lock, period, [this]() noexcept { return m_signaled; });
5256
assert(status == m_signaled);
5357
// Return 0 if the wait completed as a result of signaling the event. Otherwise, return timeout_infinite
54-
return status ? 0 : event::timeout_infinite;
58+
return status ? 0 : cancellation_token::timeout_infinite;
5559
}
5660
}
5761

5862
unsigned int wait()
5963
{
60-
return wait(event::timeout_infinite);
64+
return wait(cancellation_token::timeout_infinite);
65+
}
66+
67+
void throw_if_cancellation_requested() const
68+
{
69+
if (m_signaled)
70+
{
71+
throw canceled_exception();
72+
}
6173
}
74+
private:
75+
std::mutex m_lock;
76+
std::condition_variable m_condition;
77+
bool m_signaled;
6278
};
6379
}

src/signalrclient/case_insensitive_comparison_utils.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include <functional>
77
#include <cctype>
8-
#include "cpprest/details/basic_types.h"
98

109
namespace signalr
1110
{
@@ -21,9 +20,9 @@ namespace signalr
2120
return false;
2221
}
2322

24-
for (auto s1_iterator = s1.begin(), s2_iterator = s2.begin(); s1_iterator != s1.end(); ++s1_iterator, ++s2_iterator)
23+
for (int i = 0; i < s1.size(); ++i)
2524
{
26-
if (std::toupper(*s1_iterator) != std::toupper(*s2_iterator))
25+
if (std::toupper(s1[i]) != std::toupper(s2[i]))
2726
{
2827
return false;
2928
}
@@ -39,7 +38,7 @@ namespace signalr
3938
{
4039
size_t hash = 0;
4140
std::hash<size_t> hasher;
42-
for (const utility::char_t& c : s)
41+
for (const auto& c : s)
4342
{
4443
hash ^= hasher(std::toupper(c)) + (hash << 5) + (hash >> 2);
4544
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
#pragma once
5+
6+
#include <future>
7+
8+
namespace signalr
9+
{
10+
class completion_event_impl : public std::enable_shared_from_this<completion_event_impl>
11+
{
12+
public:
13+
static std::shared_ptr<completion_event_impl> create()
14+
{
15+
return std::shared_ptr<completion_event_impl>(new completion_event_impl());
16+
}
17+
18+
// no op when already set
19+
void set()
20+
{
21+
std::lock_guard<std::mutex> lock(m_mutex);
22+
if (!m_isSet)
23+
{
24+
m_promise.set_value();
25+
m_isSet = true;
26+
}
27+
}
28+
29+
// no op when already set
30+
void set(const std::exception_ptr& exception)
31+
{
32+
std::lock_guard<std::mutex> lock(m_mutex);
33+
if (!m_isSet)
34+
{
35+
m_promise.set_exception(exception);
36+
m_isSet = true;
37+
}
38+
}
39+
40+
// blocks and returns when set or throws when an exception is set
41+
void get() const
42+
{
43+
m_future.get();
44+
}
45+
46+
private:
47+
completion_event_impl() : m_isSet(false)
48+
{
49+
m_future = m_promise.get_future().share();
50+
}
51+
52+
std::promise<void> m_promise;
53+
std::shared_future<void> m_future;
54+
bool m_isSet;
55+
std::mutex m_mutex;
56+
};
57+
58+
class completion_event
59+
{
60+
public:
61+
completion_event() : m_impl(completion_event_impl::create())
62+
{
63+
}
64+
65+
completion_event(const completion_event& rhs)
66+
{
67+
m_impl = rhs.m_impl;
68+
}
69+
70+
// no op when already set
71+
void set()
72+
{
73+
m_impl->set();
74+
}
75+
76+
// no op when already set
77+
void set(const std::exception_ptr& exception)
78+
{
79+
m_impl->set(exception);
80+
}
81+
82+
// blocks and returns when set or throws when an exception is set
83+
void get() const
84+
{
85+
m_impl->get();
86+
}
87+
private:
88+
std::shared_ptr<completion_event_impl> m_impl;
89+
};
90+
}

0 commit comments

Comments
 (0)