Rename sub_count to subs_capacity

sub_count is not the actual number of subscriptions.
Renamed it to subs_capacity, as it keeps the value of allocated
mosquitto__client_sub elements stored in the subs member of the
mosquitto struct.

Signed-off-by: Kai Buschulte <kai.buschulte@cedalo.com>
pull/2676/head
Kai Buschulte 3 years ago
parent c535efdfa9
commit 31cdd26230

@ -361,7 +361,7 @@ struct mosquitto {
struct mosquitto__packet *out_packet_last; struct mosquitto__packet *out_packet_last;
struct mosquitto__client_sub **subs; struct mosquitto__client_sub **subs;
char *auth_method; char *auth_method;
int sub_count; int subs_capacity; /* allocated size of the subs instance */
# ifndef WITH_EPOLL # ifndef WITH_EPOLL
int pollfd_index; int pollfd_index;
# endif # endif
@ -447,4 +447,3 @@ struct mosquitto {
void do_client_disconnect(struct mosquitto *mosq, int reason_code, const mosquitto_property *properties); void do_client_disconnect(struct mosquitto *mosq, int reason_code, const mosquitto_property *properties);
#endif #endif

@ -164,11 +164,11 @@ int connect__on_authorised(struct mosquitto *context, void *auth_data_out, uint1
} }
context->subs = found_context->subs; context->subs = found_context->subs;
found_context->subs = NULL; found_context->subs = NULL;
context->sub_count = found_context->sub_count; context->subs_capacity = found_context->subs_capacity;
found_context->sub_count = 0; found_context->subs_capacity = 0;
context->last_mid = found_context->last_mid; context->last_mid = found_context->last_mid;
for(i=0; i<context->sub_count; i++){ for(i=0; i<context->subs_capacity; i++){
if(context->subs[i]){ if(context->subs[i]){
leaf = context->subs[i]->hier->subs; leaf = context->subs[i]->hier->subs;
while(leaf){ while(leaf){

@ -172,7 +172,7 @@ BROKER_EXPORT int mosquitto_client_protocol_version(const struct mosquitto *clie
BROKER_EXPORT int mosquitto_client_sub_count(const struct mosquitto *client) BROKER_EXPORT int mosquitto_client_sub_count(const struct mosquitto *client)
{ {
if(client){ if(client){
return client->sub_count; return client->subs_capacity;
}else{ }else{
return 0; return 0;
} }
@ -371,7 +371,7 @@ static void check_subscription_acls(struct mosquitto *context)
int rc; int rc;
uint8_t reason; uint8_t reason;
for(i=0; i<context->sub_count; i++){ for(i=0; i<context->subs_capacity; i++){
if(context->subs[i] == NULL){ if(context->subs[i] == NULL){
continue; continue;
} }

@ -235,7 +235,7 @@ static int sub__add_shared(struct mosquitto *context, const char *sub, uint8_t q
csub->shared = shared; csub->shared = shared;
bool assigned = false; bool assigned = false;
for(i=0; i<context->sub_count; i++){ for(i=0; i<context->subs_capacity; i++){
if(!context->subs[i]){ if(!context->subs[i]){
context->subs[i] = csub; context->subs[i] = csub;
assigned = true; assigned = true;
@ -243,7 +243,7 @@ static int sub__add_shared(struct mosquitto *context, const char *sub, uint8_t q
} }
} }
if(assigned == false){ if(assigned == false){
subs = mosquitto__realloc(context->subs, sizeof(struct mosquitto__client_sub *)*(size_t)(context->sub_count + 1)); subs = mosquitto__realloc(context->subs, sizeof(struct mosquitto__client_sub *)*(size_t)(context->subs_capacity + 1));
if(!subs){ if(!subs){
sub__remove_shared_leaf(subhier, shared, newleaf); sub__remove_shared_leaf(subhier, shared, newleaf);
mosquitto__FREE(newleaf); mosquitto__FREE(newleaf);
@ -251,8 +251,8 @@ static int sub__add_shared(struct mosquitto *context, const char *sub, uint8_t q
return MOSQ_ERR_NOMEM; return MOSQ_ERR_NOMEM;
} }
context->subs = subs; context->subs = subs;
context->sub_count++; context->subs_capacity++;
context->subs[context->sub_count-1] = csub; context->subs[context->subs_capacity-1] = csub;
} }
#ifdef WITH_SYS_TREE #ifdef WITH_SYS_TREE
db.shared_subscription_count++; db.shared_subscription_count++;
@ -292,7 +292,7 @@ static int sub__add_normal(struct mosquitto *context, const char *sub, uint8_t q
csub->shared = NULL; csub->shared = NULL;
bool assigned = false; bool assigned = false;
for(i=0; i<context->sub_count; i++){ for(i=0; i<context->subs_capacity; i++){
if(!context->subs[i]){ if(!context->subs[i]){
context->subs[i] = csub; context->subs[i] = csub;
assigned = true; assigned = true;
@ -300,7 +300,7 @@ static int sub__add_normal(struct mosquitto *context, const char *sub, uint8_t q
} }
} }
if(assigned == false){ if(assigned == false){
subs = mosquitto__realloc(context->subs, sizeof(struct mosquitto__client_sub *)*(size_t)(context->sub_count + 1)); subs = mosquitto__realloc(context->subs, sizeof(struct mosquitto__client_sub *)*(size_t)(context->subs_capacity + 1));
if(!subs){ if(!subs){
DL_DELETE(subhier->subs, newleaf); DL_DELETE(subhier->subs, newleaf);
mosquitto__FREE(newleaf); mosquitto__FREE(newleaf);
@ -308,8 +308,8 @@ static int sub__add_normal(struct mosquitto *context, const char *sub, uint8_t q
return MOSQ_ERR_NOMEM; return MOSQ_ERR_NOMEM;
} }
context->subs = subs; context->subs = subs;
context->sub_count++; context->subs_capacity++;
context->subs[context->sub_count-1] = csub; context->subs[context->subs_capacity-1] = csub;
} }
#ifdef WITH_SYS_TREE #ifdef WITH_SYS_TREE
db.subscription_count++; db.subscription_count++;
@ -379,7 +379,7 @@ static int sub__remove_normal(struct mosquitto *context, struct mosquitto__subhi
* It would be nice to be able to use the reference directly, * It would be nice to be able to use the reference directly,
* but that would involve keeping a copy of the topic string in * but that would involve keeping a copy of the topic string in
* each subleaf. Might be worth considering though. */ * each subleaf. Might be worth considering though. */
for(i=0; i<context->sub_count; i++){ for(i=0; i<context->subs_capacity; i++){
if(context->subs[i] && context->subs[i]->hier == subhier){ if(context->subs[i] && context->subs[i]->hier == subhier){
mosquitto__FREE(context->subs[i]); mosquitto__FREE(context->subs[i]);
break; break;
@ -415,7 +415,7 @@ static int sub__remove_shared(struct mosquitto *context, struct mosquitto__subhi
* It would be nice to be able to use the reference directly, * It would be nice to be able to use the reference directly,
* but that would involve keeping a copy of the topic string in * but that would involve keeping a copy of the topic string in
* each subleaf. Might be worth considering though. */ * each subleaf. Might be worth considering though. */
for(i=0; i<context->sub_count; i++){ for(i=0; i<context->subs_capacity; i++){
if(context->subs[i] if(context->subs[i]
&& context->subs[i]->hier == subhier && context->subs[i]->hier == subhier
&& context->subs[i]->shared == shared){ && context->subs[i]->shared == shared){
@ -696,7 +696,7 @@ int sub__clean_session(struct mosquitto *context)
struct mosquitto__subleaf *leaf; struct mosquitto__subleaf *leaf;
struct mosquitto__subhier *hier; struct mosquitto__subhier *hier;
for(i=0; i<context->sub_count; i++){ for(i=0; i<context->subs_capacity; i++){
if(context->subs[i] == NULL){ if(context->subs[i] == NULL){
continue; continue;
} }
@ -743,7 +743,7 @@ int sub__clean_session(struct mosquitto *context)
} }
} }
mosquitto__FREE(context->subs); mosquitto__FREE(context->subs);
context->sub_count = 0; context->subs_capacity = 0;
return MOSQ_ERR_SUCCESS; return MOSQ_ERR_SUCCESS;
} }

Loading…
Cancel
Save