Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed error code. #658

Merged
merged 2 commits into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions include/mqtt/endpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4578,7 +4578,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
std::size_t bytes_transferred,
std::size_t bytes_expected) {
if (bytes_transferred != bytes_expected) {
call_message_size_error_handlers();
call_bad_message_error_handlers();
return false;
}
return true;
Expand All @@ -4593,8 +4593,8 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
return true;
}

void call_message_size_error_handlers() {
clean_sub_unsub_inflight_on_error(boost::system::errc::make_error_code(boost::system::errc::message_size));
void call_bad_message_error_handlers() {
clean_sub_unsub_inflight_on_error(boost::system::errc::make_error_code(boost::system::errc::bad_message));
}

void call_protocol_error_handlers() {
Expand Down Expand Up @@ -4712,7 +4712,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,

void handle_remaining_length(any session_life_keeper, this_type_sp self) {
if (!calc_variable_length(remaining_length_, remaining_length_multiplier_, buf_.front())) {
clean_sub_unsub_inflight_on_error(boost::system::errc::make_error_code(boost::system::errc::message_size));
call_protocol_error_handlers();
return;
}
if (buf_.front() & variable_length_continue_flag) {
Expand All @@ -4726,7 +4726,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
return;
}
if (bytes_transferred != 1) {
clean_sub_unsub_inflight_on_error(boost::system::errc::make_error_code(boost::system::errc::message_size));
call_bad_message_error_handlers();
return;
}
handle_remaining_length(force_move(session_life_keeper), force_move(self));
Expand Down Expand Up @@ -4790,7 +4790,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
}
};
if (!check()) {
clean_sub_unsub_inflight_on_error(boost::system::errc::make_error_code(boost::system::errc::message_size));
call_protocol_error_handlers();
return;
}

Expand Down Expand Up @@ -4915,7 +4915,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
this_type_sp self
) {
if (remaining_length_ < size) {
call_message_size_error_handlers();
call_protocol_error_handlers();
return;
}
remaining_length_ -= size;
Expand Down Expand Up @@ -4947,7 +4947,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
}
else {
if (buf.size() < size) {
call_message_size_error_handlers();
call_protocol_error_handlers();
return;
}
socket_->post(
Expand Down Expand Up @@ -4978,7 +4978,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
this_type_sp self
) {
if (remaining_length_ < Bytes) {
call_message_size_error_handlers();
call_protocol_error_handlers();
return;
}

Expand Down Expand Up @@ -5061,7 +5061,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
this_type_sp self
) {
if (remaining_length_ == 0) {
call_message_size_error_handlers();
call_protocol_error_handlers();
return;
}
--remaining_length_;
Expand All @@ -5080,7 +5080,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
this_type_sp&& self
) mutable {
if (!calc_variable_length(size, multiplier, buf.front())) {
call_message_size_error_handlers();
call_protocol_error_handlers();
return;
}
if (buf.front() & variable_length_continue_flag) {
Expand Down Expand Up @@ -5184,7 +5184,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
this_type_sp self
) {
if (remaining_length_ < 2) {
call_message_size_error_handlers();
call_protocol_error_handlers();
return;
}
process_fixed_length<2>(
Expand All @@ -5199,7 +5199,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
any session_life_keeper,
this_type_sp self) mutable {
if (remaining_length_ < size) {
call_message_size_error_handlers();
call_protocol_error_handlers();
return;
}
process_nbytes(
Expand Down Expand Up @@ -5252,7 +5252,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
]
(std::size_t property_length, buffer buf, any session_life_keeper, this_type_sp self) mutable {
if (property_length > remaining_length_) {
call_message_size_error_handlers();
call_protocol_error_handlers();
return;
}
if (property_length == 0) {
Expand Down Expand Up @@ -5419,15 +5419,15 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
static constexpr std::size_t length_bytes = 2;

if (property_length_rest == 0) {
call_message_size_error_handlers();
call_protocol_error_handlers();
return;
}

switch (id) {
case v5::property::id::payload_format_indicator: {
static constexpr std::size_t len = 1;
if (property_length_rest < len) {
call_message_size_error_handlers();
call_protocol_error_handlers();
return;
}
process_nbytes(
Expand Down Expand Up @@ -5459,7 +5459,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
case v5::property::id::message_expiry_interval: {
static constexpr std::size_t len = 4;
if (property_length_rest < len) {
call_message_size_error_handlers();
call_protocol_error_handlers();
return;
}
process_nbytes(
Expand Down Expand Up @@ -5601,7 +5601,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
case v5::property::id::session_expiry_interval: {
static constexpr std::size_t len = 4;
if (property_length_rest < len) {
call_message_size_error_handlers();
call_protocol_error_handlers();
return;
}
process_nbytes(
Expand Down Expand Up @@ -5661,7 +5661,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
case v5::property::id::server_keep_alive: {
static constexpr std::size_t len = 2;
if (property_length_rest < len) {
call_message_size_error_handlers();
call_protocol_error_handlers();
return;
}
process_nbytes(
Expand Down Expand Up @@ -5747,7 +5747,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
case v5::property::id::request_problem_information: {
static constexpr std::size_t len = 1;
if (property_length_rest < len) {
call_message_size_error_handlers();
call_protocol_error_handlers();
return;
}
process_nbytes(
Expand Down Expand Up @@ -5779,7 +5779,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
case v5::property::id::will_delay_interval: {
static constexpr std::size_t len = 4;
if (property_length_rest < len) {
call_message_size_error_handlers();
call_protocol_error_handlers();
return;
}
process_nbytes(
Expand Down Expand Up @@ -5811,7 +5811,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
case v5::property::id::request_response_information: {
static constexpr std::size_t len = 1;
if (property_length_rest < len) {
call_message_size_error_handlers();
call_protocol_error_handlers();
return;
}
process_nbytes(
Expand Down Expand Up @@ -5924,7 +5924,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
case v5::property::id::receive_maximum: {
static constexpr std::size_t len = 2;
if (property_length_rest < len) {
call_message_size_error_handlers();
call_protocol_error_handlers();
return;
}
process_nbytes(
Expand Down Expand Up @@ -5956,7 +5956,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
case v5::property::id::topic_alias_maximum: {
static constexpr std::size_t len = 2;
if (property_length_rest < len) {
call_message_size_error_handlers();
call_protocol_error_handlers();
return;
}
process_nbytes(
Expand Down Expand Up @@ -5988,7 +5988,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
case v5::property::id::topic_alias: {
static constexpr std::size_t len = 2;
if (property_length_rest < len) {
call_message_size_error_handlers();
call_protocol_error_handlers();
return;
}
process_nbytes(
Expand Down Expand Up @@ -6020,7 +6020,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
case v5::property::id::maximum_qos: {
static constexpr std::size_t len = 1;
if (property_length_rest < len) {
call_message_size_error_handlers();
call_protocol_error_handlers();
return;
}
process_nbytes(
Expand Down Expand Up @@ -6052,7 +6052,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
case v5::property::id::retain_available: {
static constexpr std::size_t len = 1;
if (property_length_rest < len) {
call_message_size_error_handlers();
call_protocol_error_handlers();
return;
}
process_nbytes(
Expand Down Expand Up @@ -6131,7 +6131,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
case v5::property::id::maximum_packet_size: {
static constexpr std::size_t len = 4;
if (property_length_rest < len) {
call_message_size_error_handlers();
call_protocol_error_handlers();
return;
}
process_nbytes(
Expand Down Expand Up @@ -6163,7 +6163,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
case v5::property::id::wildcard_subscription_available: {
static constexpr std::size_t len = 1;
if (property_length_rest < len) {
call_message_size_error_handlers();
call_protocol_error_handlers();
return;
}
process_nbytes(
Expand Down Expand Up @@ -6195,7 +6195,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
case v5::property::id::subscription_identifier_available: {
static constexpr std::size_t len = 1;
if (property_length_rest < len) {
call_message_size_error_handlers();
call_protocol_error_handlers();
return;
}
process_nbytes(
Expand Down Expand Up @@ -6227,7 +6227,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
case v5::property::id::shared_subscription_available: {
static constexpr std::size_t len = 1;
if (property_length_rest < len) {
call_message_size_error_handlers();
call_protocol_error_handlers();
return;
}
process_nbytes(
Expand Down
2 changes: 1 addition & 1 deletion test/length_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) {
[&chk, &c, &finish]
(MQTT_NS::error_code ec) {
MQTT_CHK("h_error");
BOOST_TEST(ec == boost::system::errc::message_size);
BOOST_TEST(ec == boost::system::errc::protocol_error);
finish();
c->force_disconnect();
});
Expand Down
13 changes: 12 additions & 1 deletion test/test_broker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,20 @@ class test_broker {
});
ep.set_error_handler(
[this, wp]
(MQTT_NS::error_code /*ec*/){
(MQTT_NS::error_code ec){
con_sp_t sp = wp.lock();
BOOST_ASSERT(sp);

// https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#S4_13_Errors
if (ec == boost::system::errc::protocol_error) {
if (sp->connected()) {
sp->disconnect(MQTT_NS::v5::disconnect_reason_code::protocol_error);
}
else { // connecting
sp->connack(false, MQTT_NS::v5::connect_reason_code::protocol_error);
}
}

close_proc(MQTT_NS::force_move(sp), true);
});

Expand Down