mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-09-22 16:15:05 +08:00
Introduce subs_count for client subscriptions
This is the actual number of subscriptions. Signed-off-by: Kai Buschulte <kai.buschulte@cedalo.com>
This commit is contained in:
@@ -362,6 +362,7 @@ struct mosquitto {
|
||||
struct mosquitto__client_sub **subs;
|
||||
char *auth_method;
|
||||
int subs_capacity; /* allocated size of the subs instance */
|
||||
int subs_count; /* number of currently active subscriptions */
|
||||
# ifndef WITH_EPOLL
|
||||
int pollfd_index;
|
||||
# endif
|
||||
|
||||
@@ -165,7 +165,9 @@ int connect__on_authorised(struct mosquitto *context, void *auth_data_out, uint1
|
||||
context->subs = found_context->subs;
|
||||
found_context->subs = NULL;
|
||||
context->subs_capacity = found_context->subs_capacity;
|
||||
context->subs_count = found_context->subs_count;
|
||||
found_context->subs_capacity = 0;
|
||||
found_context->subs_count = 0;
|
||||
context->last_mid = found_context->last_mid;
|
||||
|
||||
for(i=0; i<context->subs_capacity; i++){
|
||||
|
||||
+1
-1
@@ -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)
|
||||
{
|
||||
if(client){
|
||||
return client->subs_capacity;
|
||||
return client->subs_count;
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
|
||||
+7
-1
@@ -238,6 +238,7 @@ static int sub__add_shared(struct mosquitto *context, const char *sub, uint8_t q
|
||||
for(i=0; i<context->subs_capacity; i++){
|
||||
if(!context->subs[i]){
|
||||
context->subs[i] = csub;
|
||||
context->subs_count++;
|
||||
assigned = true;
|
||||
break;
|
||||
}
|
||||
@@ -252,6 +253,7 @@ static int sub__add_shared(struct mosquitto *context, const char *sub, uint8_t q
|
||||
}
|
||||
context->subs = subs;
|
||||
context->subs_capacity++;
|
||||
context->subs_count++;
|
||||
context->subs[context->subs_capacity-1] = csub;
|
||||
}
|
||||
#ifdef WITH_SYS_TREE
|
||||
@@ -295,6 +297,7 @@ static int sub__add_normal(struct mosquitto *context, const char *sub, uint8_t q
|
||||
for(i=0; i<context->subs_capacity; i++){
|
||||
if(!context->subs[i]){
|
||||
context->subs[i] = csub;
|
||||
context->subs_count++;
|
||||
assigned = true;
|
||||
break;
|
||||
}
|
||||
@@ -309,6 +312,7 @@ static int sub__add_normal(struct mosquitto *context, const char *sub, uint8_t q
|
||||
}
|
||||
context->subs = subs;
|
||||
context->subs_capacity++;
|
||||
context->subs_count++;
|
||||
context->subs[context->subs_capacity-1] = csub;
|
||||
}
|
||||
#ifdef WITH_SYS_TREE
|
||||
@@ -381,6 +385,7 @@ static int sub__remove_normal(struct mosquitto *context, struct mosquitto__subhi
|
||||
* each subleaf. Might be worth considering though. */
|
||||
for(i=0; i<context->subs_capacity; i++){
|
||||
if(context->subs[i] && context->subs[i]->hier == subhier){
|
||||
context->subs_count--;
|
||||
mosquitto__FREE(context->subs[i]);
|
||||
break;
|
||||
}
|
||||
@@ -419,7 +424,7 @@ static int sub__remove_shared(struct mosquitto *context, struct mosquitto__subhi
|
||||
if(context->subs[i]
|
||||
&& context->subs[i]->hier == subhier
|
||||
&& context->subs[i]->shared == shared){
|
||||
|
||||
context->subs_count--;
|
||||
mosquitto__FREE(context->subs[i]);
|
||||
break;
|
||||
}
|
||||
@@ -744,6 +749,7 @@ int sub__clean_session(struct mosquitto *context)
|
||||
}
|
||||
mosquitto__FREE(context->subs);
|
||||
context->subs_capacity = 0;
|
||||
context->subs_count = 0;
|
||||
|
||||
return MOSQ_ERR_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user