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

About the code implementation of qos0 message cache #2661

Open
jiang4869 opened this issue Oct 20, 2022 · 0 comments
Open

About the code implementation of qos0 message cache #2661

jiang4869 opened this issue Oct 20, 2022 · 0 comments

Comments

@jiang4869
Copy link

Hello, about mosquitto code implementation, have a question want to ask.

As described in the configuration file, qos0 messages are cached only when queue_qos0_message is set to true and max_queued_message is set to 0.

I would like to ask whether the implementation code of this function is in the function db_message_insert in src/databases. When the socket is invalid, check whether the qos0 message is cached.

So when can a socket be invalid? Does the socket become invalid if the subscriber consumes more than the broker can push it?

int db__message_insert(struct mosquitto *context, uint16_t mid, enum mosquitto_msg_direction dir, uint8_t qos, bool retain, struct mosquitto_msg_store *stored, mosquitto_property *properties, bool update) {
	......
	if(context->sock == INVALID_SOCKET){
		/* Client is not connected only queue messages with QoS>0. */
		if(qos == 0 && !db.config->queue_qos0_messages){
			if(!context->bridge){
				mosquitto_property_free_all(&properties);
				return 2;
			}else{
				if(context->bridge->start_type != bst_lazy){
					mosquitto_property_free_all(&properties);
					return 2;
				}
			}
		}
		if(context->bridge && context->bridge->clean_start_local == true){
			mosquitto_property_free_all(&properties);
			return 2;
		}
	}
	......
	if(context->sock != INVALID_SOCKET){
		.......
	}else{
		if (db__ready_for_queue(context, qos, msg_data)){
			state = mosq_ms_queued;
		}else{
			G_MSGS_DROPPED_INC();
			if(context->is_dropping == false){
				context->is_dropping = true;
				log__printf(NULL, MOSQ_LOG_NOTICE,
						"Outgoing messages are being dropped for client %s.",
						context->id);
			}
			mosquitto_property_free_all(&properties);
			return 2;
		}
	}
}

Thank you for answering my question in your busy schedule.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant