Skip to content

Commit

Permalink
Added move_only_handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
redboltz committed Oct 16, 2022
1 parent c10583d commit 4fdfc6d
Show file tree
Hide file tree
Showing 71 changed files with 2,245 additions and 3,891 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/gha.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up GCC
uses: egor-tensin/setup-gcc@v1
with:
version: 11
platform: x64
- name: Cache boost
id: cache-boost
uses: actions/cache@v1
Expand Down
12 changes: 3 additions & 9 deletions example/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ int main(int argc, char **argv) {
MQTT_NS::v5::properties /*props*/) {
if (pubopts.get_retain() == MQTT_NS::retain::yes) {
locked_cout() << "retained publish received and ignored topic:" << topic_name << std::endl;
return true;
return;
}
BOOST_ASSERT(rest_times > 0);
--rest_times;
Expand Down Expand Up @@ -742,8 +742,6 @@ int main(int argc, char **argv) {
--ci.recv_times;
if (rest_times == 0) finish_proc();
}

return true;
};

// ==== end local lambda expressions
Expand All @@ -764,7 +762,6 @@ int main(int argc, char **argv) {
else {
std::cout << "connack error:" << connack_return_code << std::endl;
}
return true;
}
);
ci.c->set_v5_connack_handler(
Expand All @@ -776,7 +773,6 @@ int main(int argc, char **argv) {
else {
std::cout << "connack error:" << reason_code << std::endl;
}
return true;
}
);

Expand All @@ -796,7 +792,6 @@ int main(int argc, char **argv) {
}
}
}
return true;
}
);
ci.c->set_v5_suback_handler(
Expand All @@ -817,7 +812,6 @@ int main(int argc, char **argv) {
}
}
}
return true;
}
);

Expand All @@ -827,7 +821,7 @@ int main(int argc, char **argv) {
MQTT_NS::publish_options pubopts,
MQTT_NS::buffer topic_name,
MQTT_NS::buffer contents) {
return publish_handler(ci, packet_id, pubopts, topic_name, contents, MQTT_NS::v5::properties{});
publish_handler(ci, packet_id, pubopts, topic_name, contents, MQTT_NS::v5::properties{});
}
);
ci.c->set_v5_publish_handler(
Expand All @@ -837,7 +831,7 @@ int main(int argc, char **argv) {
MQTT_NS::buffer topic_name,
MQTT_NS::buffer contents,
MQTT_NS::v5::properties props) {
return publish_handler(ci, packet_id, pubopts, topic_name, contents, MQTT_NS::force_move(props));
publish_handler(ci, packet_id, pubopts, topic_name, contents, MQTT_NS::force_move(props));
}
);
}
Expand Down
45 changes: 14 additions & 31 deletions example/client_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,6 @@ int main(int argc, char* argv[]) {
std::cout << "< props:" << std::endl;
print_props("< ", props);
print_menu();
return true;
};

client.set_connack_handler(
Expand All @@ -615,7 +614,6 @@ int main(int argc, char* argv[]) {
}
);
}
return true;
}
);
client.set_v5_connack_handler(
Expand All @@ -641,7 +639,6 @@ int main(int argc, char* argv[]) {
}
);
}
return true;
}
);
client.set_publish_handler(
Expand All @@ -651,14 +648,13 @@ int main(int argc, char* argv[]) {
MQTT_NS::buffer topic_name,
MQTT_NS::buffer contents) {
std::cout << "< publish (v3.1.1)" << std::endl;
return
publish_handler(
packet_id,
pubopts,
topic_name,
contents,
MQTT_NS::v5::properties{}
);
publish_handler(
packet_id,
pubopts,
topic_name,
contents,
MQTT_NS::v5::properties{}
);
}
);
client.set_v5_publish_handler(
Expand All @@ -669,22 +665,20 @@ int main(int argc, char* argv[]) {
MQTT_NS::buffer contents,
MQTT_NS::v5::properties props) {
std::cout << "< publish (v5)" << std::endl;
return
publish_handler(
packet_id,
pubopts,
topic_name,
contents,
MQTT_NS::force_move(props)
);
publish_handler(
packet_id,
pubopts,
topic_name,
contents,
MQTT_NS::force_move(props)
);
}
);
client.set_puback_handler(
[&]
(packet_id_t packet_id){
std::cout << "< puback (v3.1.1)" << std::endl;
std::cout << "< packet_id:" << packet_id << std::endl;
return true;
}
);
client.set_v5_puback_handler( // use v5 handler
Expand All @@ -695,15 +689,13 @@ int main(int argc, char* argv[]) {
std::cout << "< reason_code:" << reason_code << std::endl;
std::cout << "< props:" << std::endl;
print_props("< ", props);
return true;
}
);
client.set_pubrec_handler(
[]
(packet_id_t packet_id){
std::cout << "< pubrec (v3.1.1)" << std::endl;
std::cout << "< packet_id:" << packet_id << std::endl;
return true;
}
);
client.set_v5_pubrec_handler( // use v5 handler
Expand All @@ -714,15 +706,13 @@ int main(int argc, char* argv[]) {
std::cout << "< reason_code:" << reason_code << std::endl;
std::cout << "< props:" << std::endl;
print_props("< ", props);
return true;
}
);
client.set_pubrel_handler(
[]
(packet_id_t packet_id){
std::cout << "< pubrel (v3.1.1)" << std::endl;
std::cout << "< packet_id:" << packet_id << std::endl;
return true;
}
);
client.set_v5_pubrel_handler( // use v5 handler
Expand All @@ -733,15 +723,13 @@ int main(int argc, char* argv[]) {
std::cout << "< reason_code:" << reason_code << std::endl;
std::cout << "< props:" << std::endl;
print_props("< ", props);
return true;
}
);
client.set_pubcomp_handler(
[&]
(packet_id_t packet_id){
std::cout << "< pubcomp (v3.1.1)" << std::endl;
std::cout << "< packet_id:" << packet_id << std::endl;
return true;
}
);
client.set_v5_pubcomp_handler( // use v5 handler
Expand All @@ -752,7 +740,6 @@ int main(int argc, char* argv[]) {
std::cout << "< reason_code:" << reason_code << std::endl;
std::cout << "< props:" << std::endl;
print_props("< ", props);
return true;
}
);
client.set_suback_handler(
Expand All @@ -765,7 +752,6 @@ int main(int argc, char* argv[]) {
std::cout << "< " << e << std::endl;
}
print_menu();
return true;
}
);
client.set_v5_suback_handler(
Expand All @@ -782,7 +768,6 @@ int main(int argc, char* argv[]) {
std::cout << "< props:" << std::endl;
print_props("< ", props);
print_menu();
return true;
}
);
client.set_unsuback_handler(
Expand All @@ -791,7 +776,6 @@ int main(int argc, char* argv[]) {
std::cout << "< unsuback (v3.1.1)" << std::endl;
std::cout << "< packet_id: " << packet_id << std::endl;
print_menu();
return true;
}
);
client.set_v5_unsuback_handler(
Expand All @@ -808,7 +792,6 @@ int main(int argc, char* argv[]) {
std::cout << "< props:" << std::endl;
print_props("< ", props);
print_menu();
return true;
}
);

Expand Down
14 changes: 0 additions & 14 deletions example/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ void client_proc(
}
);
}
return true;
});
c->set_close_handler(
[]
Expand All @@ -64,20 +63,17 @@ void client_proc(
(packet_id_t packet_id){
locked_cout() << "[client] puback received. packet_id: " << packet_id << std::endl;
disconnect();
return true;
});
c->set_pubrec_handler(
[&]
(packet_id_t packet_id){
locked_cout() << "[client] pubrec received. packet_id: " << packet_id << std::endl;
return true;
});
c->set_pubcomp_handler(
[&]
(packet_id_t packet_id){
locked_cout() << "[client] pubcomp received. packet_id: " << packet_id << std::endl;
disconnect();
return true;
});
c->set_suback_handler(
[&]
Expand All @@ -93,7 +89,6 @@ void client_proc(
c->publish("mqtt_client_cpp/topic2_1", "test2_1", MQTT_NS::qos::at_least_once);
c->publish("mqtt_client_cpp/topic2_2", "test2_2", MQTT_NS::qos::exactly_once);
}
return true;
});
c->set_publish_handler(
[&]
Expand All @@ -110,7 +105,6 @@ void client_proc(
locked_cout() << "[client] topic_name: " << topic_name << std::endl;
locked_cout() << "[client] contents: " << contents << std::endl;
disconnect();
return true;
});

// Connect
Expand Down Expand Up @@ -225,7 +219,6 @@ void server_proc(Server& s, std::set<con_sp_t>& connections, mi_sub_con& subs) {
BOOST_ASSERT(sp);
connections.insert(sp);
sp->connack(false, MQTT_NS::connect_return_code::accepted);
return true;
}
);
ep.set_disconnect_handler(
Expand All @@ -240,25 +233,21 @@ void server_proc(Server& s, std::set<con_sp_t>& connections, mi_sub_con& subs) {
[]
(packet_id_t packet_id){
locked_cout() << "[server] puback received. packet_id: " << packet_id << std::endl;
return true;
});
ep.set_pubrec_handler(
[]
(packet_id_t packet_id){
locked_cout() << "[server] pubrec received. packet_id: " << packet_id << std::endl;
return true;
});
ep.set_pubrel_handler(
[]
(packet_id_t packet_id){
locked_cout() << "[server] pubrel received. packet_id: " << packet_id << std::endl;
return true;
});
ep.set_pubcomp_handler(
[]
(packet_id_t packet_id){
locked_cout() << "[server] pubcomp received. packet_id: " << packet_id << std::endl;
return true;
});
ep.set_publish_handler(
[&subs]
Expand All @@ -283,7 +272,6 @@ void server_proc(Server& s, std::set<con_sp_t>& connections, mi_sub_con& subs) {
std::min(r.first->qos_value, pubopts.get_qos())
);
}
return true;
});
ep.set_subscribe_handler(
[&subs, wp]
Expand All @@ -300,7 +288,6 @@ void server_proc(Server& s, std::set<con_sp_t>& connections, mi_sub_con& subs) {
subs.emplace(std::move(e.topic_filter), sp, e.subopts.get_qos());
}
sp->suback(packet_id, res);
return true;
}
);
ep.set_unsubscribe_handler(
Expand All @@ -314,7 +301,6 @@ void server_proc(Server& s, std::set<con_sp_t>& connections, mi_sub_con& subs) {
auto sp = wp.lock();
BOOST_ASSERT(sp);
sp->unsuback(packet_id);
return true;
}
);
}
Expand Down
6 changes: 0 additions & 6 deletions example/long_lived_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ int main(int argc, char** argv) {
);

publish_message(publish_timer, c, packet_counter);
return true;
});
c->set_close_handler(
[]
Expand All @@ -139,13 +138,11 @@ int main(int argc, char** argv) {
[&]
(packet_id_t packet_id){
std::cout << "puback received. packet_id: " << packet_id << std::endl;
return true;
});
c->set_pubrec_handler(
[]
(packet_id_t packet_id){
std::cout << "pubrec received. packet_id: " << packet_id << std::endl;
return true;
});
c->set_pubcomp_handler(
[&]
Expand All @@ -157,7 +154,6 @@ int main(int argc, char** argv) {
}

packet_counter += 1;
return true;
});
c->set_suback_handler(
[&]
Expand All @@ -166,7 +162,6 @@ int main(int argc, char** argv) {
for (auto const& e : results) {
std::cout << "[client] subscribe result: " << e << std::endl;
}
return true;
});
c->set_publish_handler(
[&]
Expand All @@ -183,7 +178,6 @@ int main(int argc, char** argv) {
std::cout << "topic_name: " << topic_name << std::endl;
std::cout << "contents: " << contents << std::endl;

return true;
});

// Connect
Expand Down
Loading

0 comments on commit 4fdfc6d

Please sign in to comment.