Skip to content

Commit 8dd2c45

Browse files
committed
Make hub_connection always a shared_ptr
1 parent bcea094 commit 8dd2c45

File tree

6 files changed

+109
-123
lines changed

6 files changed

+109
-123
lines changed

include/signalrclient/hub_connection.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,10 @@ namespace signalr
2727

2828
SIGNALRCLIENT_API ~hub_connection();
2929

30-
hub_connection(const hub_connection&) = delete;
31-
30+
hub_connection(const hub_connection& rhs) = delete;
3231
hub_connection& operator=(const hub_connection&) = delete;
33-
34-
SIGNALRCLIENT_API hub_connection(hub_connection&&) noexcept;
35-
36-
SIGNALRCLIENT_API hub_connection& operator=(hub_connection&&) noexcept;
32+
hub_connection(hub_connection&&) = delete;
33+
hub_connection& operator=(hub_connection&&) = delete;
3734

3835
SIGNALRCLIENT_API void __cdecl start(std::function<void(std::exception_ptr)> callback) noexcept;
3936
SIGNALRCLIENT_API void __cdecl stop(std::function<void(std::exception_ptr)> callback) noexcept;

include/signalrclient/hub_connection_builder.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace signalr
3333

3434
SIGNALRCLIENT_API hub_connection_builder& with_http_client(std::shared_ptr<http_client> http_client);
3535

36-
SIGNALRCLIENT_API hub_connection build();
36+
SIGNALRCLIENT_API std::shared_ptr<hub_connection> build();
3737
private:
3838
hub_connection_builder(const std::string& url);
3939

samples/HubConnectionSample/HubConnectionSample.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,17 @@ void send_message(signalr::hub_connection& connection, const std::string& messag
5151

5252
void chat()
5353
{
54-
signalr::hub_connection connection = signalr::hub_connection_builder::create("http://localhost:5000/default")
55-
.with_logging(std::make_shared <logger>(), signalr::trace_level::all)
54+
std::shared_ptr<signalr::hub_connection> connection = signalr::hub_connection_builder::create("http://localhost:5000/default")
55+
.with_logging(std::make_shared<logger>(), signalr::trace_level::all)
5656
.build();
5757

58-
connection.on("Send", [](const signalr::value & m)
58+
connection->on("Send", [](const signalr::value & m)
5959
{
6060
std::cout << std::endl << m.as_array()[0].as_string() << std::endl << "Enter your message: ";
6161
});
6262

6363
std::promise<void> task;
64-
connection.start([&connection, &task](std::exception_ptr exception)
64+
connection->start([&connection, &task](std::exception_ptr exception)
6565
{
6666
if (exception)
6767
{
@@ -78,20 +78,20 @@ void chat()
7878
}
7979

8080
std::cout << "Enter your message:";
81-
while (connection.get_connection_state() == signalr::connection_state::connected)
81+
while (connection->get_connection_state() == signalr::connection_state::connected)
8282
{
8383
std::string message;
8484
std::getline(std::cin, message);
8585

86-
if (message == ":q" || connection.get_connection_state() != signalr::connection_state::connected)
86+
if (message == ":q" || connection->get_connection_state() != signalr::connection_state::connected)
8787
{
8888
break;
8989
}
9090

91-
send_message(connection, message);
91+
//send_message(connection, message);
9292
}
9393

94-
connection.stop([&task](std::exception_ptr exception)
94+
connection->stop([&task](std::exception_ptr exception)
9595
{
9696
try
9797
{

src/signalrclient/hub_connection.cpp

-11
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,6 @@ namespace signalr
1717
: m_pImpl(hub_connection_impl::create(url, trace_level, log_writer, http_client, websocket_factory))
1818
{}
1919

20-
hub_connection::hub_connection(hub_connection&& rhs) noexcept
21-
: m_pImpl(std::move(rhs.m_pImpl))
22-
{}
23-
24-
hub_connection& hub_connection::operator=(hub_connection&& rhs) noexcept
25-
{
26-
m_pImpl = std::move(rhs.m_pImpl);
27-
28-
return *this;
29-
}
30-
3120
// Do NOT remove this destructor. Letting the compiler generate and inline the default dtor may lead to
3221
// undefined behavior since we are using an incomplete type. More details here: http://herbsutter.com/gotw/_100/
3322
hub_connection::~hub_connection() = default;

src/signalrclient/hub_connection_builder.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ namespace signalr
7171
return *this;
7272
}
7373

74-
hub_connection hub_connection_builder::build()
74+
std::shared_ptr<hub_connection> hub_connection_builder::build()
7575
{
7676
#ifndef USE_CPPRESTSDK
7777
if (m_http_client == nullptr)
@@ -85,6 +85,6 @@ namespace signalr
8585
}
8686
#endif
8787

88-
return hub_connection(m_url, m_log_level, m_logger, m_http_client, m_websocket_factory);
88+
return std::shared_ptr<hub_connection>(new hub_connection(m_url, m_log_level, m_logger, m_http_client, m_websocket_factory));
8989
}
9090
}

0 commit comments

Comments
 (0)