Skip to content

Commit 3eaa50c

Browse files
committed
Make hub_connection always a shared_ptr
1 parent 2fc3982 commit 3eaa50c

File tree

6 files changed

+103
-117
lines changed

6 files changed

+103
-117
lines changed

include/signalrclient/hub_connection.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,10 @@ namespace signalr
2828

2929
SIGNALRCLIENT_API ~hub_connection();
3030

31-
hub_connection(const hub_connection&) = delete;
32-
31+
hub_connection(const hub_connection& rhs) = delete;
3332
hub_connection& operator=(const hub_connection&) = delete;
34-
35-
SIGNALRCLIENT_API hub_connection(hub_connection&&) noexcept;
36-
37-
SIGNALRCLIENT_API hub_connection& operator=(hub_connection&&) noexcept;
33+
hub_connection(hub_connection&&) = delete;
34+
hub_connection& operator=(hub_connection&&) = delete;
3835

3936
SIGNALRCLIENT_API void __cdecl start(std::function<void(std::exception_ptr)> callback) noexcept;
4037
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
@@ -39,7 +39,7 @@ namespace signalr
3939
SIGNALRCLIENT_API hub_connection_builder& with_messagepack_hub_protocol();
4040
#endif
4141

42-
SIGNALRCLIENT_API hub_connection build();
42+
SIGNALRCLIENT_API std::shared_ptr<hub_connection> build();
4343
private:
4444
hub_connection_builder(const std::string& url);
4545

samples/HubConnectionSample/HubConnectionSample.cpp

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

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

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

6262
std::promise<void> task;
63-
connection.start([&connection, &task](std::exception_ptr exception)
63+
connection->start([&connection, &task](std::exception_ptr exception)
6464
{
6565
if (exception)
6666
{
@@ -77,20 +77,20 @@ void chat()
7777
}
7878

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

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

90-
send_message(connection, message);
90+
//send_message(connection, message);
9191
}
9292

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

src/signalrclient/hub_connection.cpp

-11
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,6 @@ namespace signalr
1818
: m_pImpl(hub_connection_impl::create(url, std::move(hub_protocol), trace_level, log_writer, http_client_factory, websocket_factory, skip_negotiation))
1919
{}
2020

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

src/signalrclient/hub_connection_builder.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ namespace signalr
8888
}
8989
#endif
9090

91-
hub_connection hub_connection_builder::build()
91+
std::shared_ptr<hub_connection> hub_connection_builder::build()
9292
{
9393
#ifndef USE_CPPRESTSDK
9494
if (m_http_client_factory == nullptr)
@@ -115,6 +115,6 @@ namespace signalr
115115
hub_protocol = std::unique_ptr<json_hub_protocol>(new json_hub_protocol());
116116
}
117117

118-
return hub_connection(m_url, std::move(hub_protocol), m_log_level, m_logger, m_http_client_factory, m_websocket_factory, m_skip_negotiation);
118+
return std::shared_ptr<hub_connection>(new hub_connection(m_url, std::move(hub_protocol), m_log_level, m_logger, m_http_client_factory, m_websocket_factory, m_skip_negotiation));
119119
}
120120
}

0 commit comments

Comments
 (0)