Skip to content

Commit

Permalink
Some minor cleanup of PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
fpagliughi committed Jan 3, 2025
1 parent 461f765 commit bc7a4e9
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Completely reformat the sources and added a .clang-format file (a project master and a slightly-different one for headers).
- Added GitHub CI Action, removing legacy Travis and Appveyor files
- [#503](https://github.com/eclipse-paho/paho.mqtt.cpp/issues/503) Fixed issue that generated docs were empty.
- [#518](https://github.com/eclipse-paho/paho.mqtt.cpp/pull/518) Add function for checking async consumer event queue size
- [#519](https://github.com/eclipse-paho/paho.mqtt.cpp/pull/519) Fix potential deadlock in set_callback


## [Version 1.4.1](https://github.com/eclipse/paho.mqtt.cpp/compare/v1.4.0..v1.4.1) - (2024-07-09)
Expand Down
7 changes: 2 additions & 5 deletions include/mqtt/async_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -822,11 +822,8 @@ class async_client : public virtual iasync_client
* as the event count may change between checking the size and actual retrieval.
* @return the number of events in the queue.
*/
std::size_t consumer_events_available() const override {
if (que_)
return que_->size();
else
return 0;
std::size_t consumer_queue_size() const override {
return (que_) ? que_->size() : 0;
}
/**
* Read the next message from the queue.
Expand Down
2 changes: 1 addition & 1 deletion include/mqtt/iasync_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ class iasync_client
* as the event count may change between checking the size and actual retrieval.
* @return the number of events in the queue.
*/
virtual std::size_t consumer_events_available() const { return 0; }
virtual std::size_t consumer_queue_size() const { return 0; }
/**
* Read the next message from the queue.
* This blocks until a new message arrives.
Expand Down
3 changes: 1 addition & 2 deletions src/async_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,9 @@ void async_client::set_callback(callback& cb)
nullptr /*&async_client::on_delivery_complete*/
);
}
else
else {
MQTTAsync_setConnected(cli_, nullptr, nullptr);

if (rc != MQTTASYNC_SUCCESS) {
guard g(lock_);
userCallback_ = nullptr;
throw exception(rc);
Expand Down
8 changes: 4 additions & 4 deletions test/unit/test_async_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1008,21 +1008,21 @@ TEST_CASE("async_client consumer timeout", "[client]")
cli.try_consume_message_until(std::chrono::steady_clock::now());
}

TEST_CASE("async_client consumer events available", "[client]")
TEST_CASE("async_client consumer queue size", "[client]")
{
async_client cli{GOOD_SERVER_URI, CLIENT_ID};
cli.start_consuming();
REQUIRE(0 == cli.consumer_events_available());
REQUIRE(0 == cli.consumer_queue_size());

token_ptr conn_tok{cli.connect()};
REQUIRE(conn_tok);
conn_tok->wait();
REQUIRE(cli.is_connected());
// expect connected_event to be in the queue now
REQUIRE(1 == cli.consumer_events_available());
REQUIRE(1 == cli.consumer_queue_size());
event e;
REQUIRE(cli.try_consume_event(&e));
REQUIRE(0 == cli.consumer_events_available());
REQUIRE(0 == cli.consumer_queue_size());

cli.stop_consuming();
cli.disconnect()->wait();
Expand Down

0 comments on commit bc7a4e9

Please sign in to comment.