Skip to content

Commit bcc3dd5

Browse files
committed
Added test.
1 parent bb6ebdf commit bcc3dd5

File tree

2 files changed

+529
-116
lines changed

2 files changed

+529
-116
lines changed

include/mqtt/client.hpp

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ class client : public endpoint<std::mutex, std::lock_guard, PacketIdBytes> {
12081208
>* = nullptr
12091209
>
12101210
auto async_connect(CompletionToken&& token) {
1211-
return async_connect(any(), token);
1211+
return async_connect(any(), std::forward<CompletionToken>(token));
12121212
}
12131213

12141214
/**
@@ -1228,7 +1228,7 @@ class client : public endpoint<std::mutex, std::lock_guard, PacketIdBytes> {
12281228
async_connect(
12291229
v5::properties{},
12301230
force_move(session_life_keeper),
1231-
token
1231+
std::forward<CompletionToken>(token)
12321232
);
12331233
}
12341234

@@ -1265,7 +1265,7 @@ class client : public endpoint<std::mutex, std::lock_guard, PacketIdBytes> {
12651265
>* = nullptr
12661266
>
12671267
auto async_connect(v5::properties props, CompletionToken&& token) {
1268-
return async_connect(force_move(props), any(), token);
1268+
return async_connect(force_move(props), any(), std::forward<CompletionToken>(token));
12691269
}
12701270

12711271
/**
@@ -1344,7 +1344,7 @@ class client : public endpoint<std::mutex, std::lock_guard, PacketIdBytes> {
13441344
async_connect(
13451345
force_move(socket),
13461346
v5::properties{}, any(),
1347-
token
1347+
std::forward<CompletionToken>(token)
13481348
);
13491349
}
13501350

@@ -1368,7 +1368,7 @@ class client : public endpoint<std::mutex, std::lock_guard, PacketIdBytes> {
13681368
force_move(socket),
13691369
v5::properties{},
13701370
force_move(session_life_keeper),
1371-
token
1371+
std::forward<CompletionToken>(token)
13721372
);
13731373
}
13741374

@@ -1427,7 +1427,7 @@ class client : public endpoint<std::mutex, std::lock_guard, PacketIdBytes> {
14271427
force_move(socket),
14281428
force_move(props),
14291429
any(),
1430-
token
1430+
std::forward<CompletionToken>(token)
14311431
);
14321432
}
14331433

@@ -1586,7 +1586,7 @@ class client : public endpoint<std::mutex, std::lock_guard, PacketIdBytes> {
15861586
base::async_disconnect(
15871587
reason_code,
15881588
force_move(props),
1589-
token
1589+
std::forward<CompletionToken>(token)
15901590
);
15911591
}
15921592

@@ -1622,7 +1622,7 @@ class client : public endpoint<std::mutex, std::lock_guard, PacketIdBytes> {
16221622
base::async_disconnect(
16231623
reason_code,
16241624
force_move(props),
1625-
token
1625+
std::forward<CompletionToken>(token)
16261626
);
16271627
}
16281628

@@ -1663,7 +1663,7 @@ class client : public endpoint<std::mutex, std::lock_guard, PacketIdBytes> {
16631663
);
16641664
return
16651665
base::async_disconnect(
1666-
token
1666+
std::forward<CompletionToken>(token)
16671667
);
16681668
}
16691669

@@ -1962,9 +1962,11 @@ class client : public endpoint<std::mutex, std::lock_guard, PacketIdBytes> {
19621962
) {
19631963
BOOST_ASSERT(state == initiate);
19641964
state = resolve;
1965-
resolver.async_resolve(
1966-
cl.host_,
1967-
cl.port_,
1965+
auto& a_cl{cl};
1966+
auto& a_resolver{resolver};
1967+
a_resolver.async_resolve(
1968+
a_cl.host_,
1969+
a_cl.port_,
19681970
force_move(self)
19691971
);
19701972
}
@@ -1989,13 +1991,14 @@ class client : public endpoint<std::mutex, std::lock_guard, PacketIdBytes> {
19891991
async_start_session(force_move(self));
19901992
break;
19911993
#if defined(MQTT_USE_WS)
1992-
case tls_ws_handshake_tls:
1994+
case tls_ws_handshake_tls: {
19931995
state = tls_ws_handshake_ws;
1996+
auto& socket = *cl.socket_;
19941997
async_ws_handshake_socket(
1995-
*cl.socket_,
1998+
socket,
19961999
force_move(self)
19972000
);
1998-
break;
2001+
} break;
19992002
case tls_ws_handshake_ws:
20002003
async_start_session(force_move(self));
20012004
break;
@@ -2025,8 +2028,9 @@ class client : public endpoint<std::mutex, std::lock_guard, PacketIdBytes> {
20252028
}
20262029
else {
20272030
state = connect;
2031+
auto& a_cl{cl};
20282032
as::async_connect(
2029-
cl.socket_->lowest_layer(), eps.begin(), eps.end(), force_move(self)
2033+
a_cl.socket_->lowest_layer(), eps.begin(), eps.end(), force_move(self)
20302034
);
20312035
}
20322036
}
@@ -2046,8 +2050,9 @@ class client : public endpoint<std::mutex, std::lock_guard, PacketIdBytes> {
20462050
if (cl.ping_duration_ != std::chrono::steady_clock::duration::zero()) {
20472051
cl.set_timer();
20482052
}
2053+
auto& socket = *cl.socket_;
20492054
async_handshake_socket(
2050-
*cl.socket_,
2055+
socket,
20512056
force_move(self)
20522057
);
20532058
}
@@ -2067,9 +2072,10 @@ class client : public endpoint<std::mutex, std::lock_guard, PacketIdBytes> {
20672072
ws_endpoint<as::ip::tcp::socket, Strand>& socket,
20682073
Self&& self) {
20692074
state = ws_handshake;
2075+
auto& a_cl{cl};
20702076
socket.async_handshake(
2071-
cl.host_,
2072-
cl.path_,
2077+
a_cl.host_,
2078+
a_cl.path_,
20732079
force_move(self)
20742080
);
20752081
}
@@ -2107,9 +2113,10 @@ class client : public endpoint<std::mutex, std::lock_guard, PacketIdBytes> {
21072113
ws_endpoint<tls::stream<as::ip::tcp::socket>, Strand>& socket,
21082114
Self&& self) {
21092115
state = tls_ws_handshake_ws;
2116+
auto& a_cl{cl};
21102117
socket.async_handshake(
2111-
cl.host_,
2112-
cl.path_,
2118+
a_cl.host_,
2119+
a_cl.path_,
21132120
force_move(self)
21142121
);
21152122
}
@@ -2127,18 +2134,20 @@ class client : public endpoint<std::mutex, std::lock_guard, PacketIdBytes> {
21272134
template <typename Self>
21282135
void async_start_session(Self&& self) {
21292136
state = complete;
2130-
cl.async_read_control_packet_type(force_move(session_life_keeper));
2137+
auto& a_cl{cl};
2138+
auto a_props = force_move(props);
2139+
a_cl.async_read_control_packet_type(force_move(session_life_keeper));
21312140
// sync base::connect() refer to parameters only in the function.
21322141
// So they can be passed as view.
2133-
cl.base_async_connect(
2134-
buffer(string_view(static_cast<base const&>(cl).get_client_id())),
2135-
(cl.user_name_ ? buffer(string_view(cl.user_name_.value()))
2136-
: optional<buffer>() ),
2137-
( cl.password_ ? buffer(string_view(cl.password_.value()))
2138-
: optional<buffer>() ),
2139-
cl.will_,
2140-
cl.keep_alive_sec_,
2141-
force_move(props),
2142+
a_cl.base_async_connect(
2143+
buffer(string_view(static_cast<base const&>(a_cl).get_client_id())),
2144+
(a_cl.user_name_ ? buffer(string_view(a_cl.user_name_.value()))
2145+
: optional<buffer>() ),
2146+
(a_cl.password_ ? buffer(string_view(a_cl.password_.value()))
2147+
: optional<buffer>() ),
2148+
a_cl.will_,
2149+
a_cl.keep_alive_sec_,
2150+
force_move(a_props),
21422151
force_move(self)
21432152
);
21442153
}

0 commit comments

Comments
 (0)