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

the difference between "mqtt3_db_message_write" and "loop_handle_reads_writes"? #710

Closed
hizilla opened this issue Mar 3, 2018 · 6 comments
Labels

Comments

@hizilla
Copy link

hizilla commented Mar 3, 2018

Hi, guys, I am reading the mosquito source code recently , but I couldn't figure out the difference between mqtt3_db_message_write and loop_handle_reads_writes. I know mqtt3_db_message_write and loop_handle_reads_writes are both used to send the messages queued of one context. So what's the difference between them? Thanks a lot, :-)

@toast-uz
Copy link
Contributor

toast-uz commented Mar 3, 2018

Could you clarify the issue? I'd like to know it is just a doubt or a critical issue with appropriate background and reason.

@hizilla
Copy link
Author

hizilla commented Mar 3, 2018

In mosquito source code, we traversed all the context in mosquitto_main_loop as follows:

HASH_ITER(hh_sock, db->contexts_by_sock, context, ctxt_tmp)
{
    ...
    /*if the context is valid, we handle the msgs queued in context*/
    if(mqtt3_db_message_write(db, context) == MOSQ_ERR_SUCCESS)
    {
         ....
    }
    ...

    /*poll all the fd in pollfds*/
    fdcount = poll(pollfds, pollfd_index, 100);
    if(fdcount == -1){
        _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error in poll: %s.", strerror(errno));
    }else{

        /*we handle write and read events of pollfds*/
        loop_handle_reads_writes(db, pollfds);
        ...
    }

    ...
}

In mqtt3_db_message_write , we deal with all the msgs with states below: mosq_ms_publish_qos0, mosq_ms_publish_qos1, mosq_ms_publish_qos2, mosq_ms_send_pubrec, mosq_ms_resend_pubrel, mosq_ms_resend_pubcomp. Then we call _mosquitto_packet_queue to put the packet into out_packet list. Finaly we call _mosquitto_packet_write to send all the packets out. For example

/*the call stack when we handle with msgs in 'mosq_ms_publish_qos0' states */
case mosq_ms_publish_qos0 -> _mosquitto_send_publish -> _mosquitto_send_real_publish -> 
_mosquitto_packet_queue -> _mosquitto_packet_write -> _mosquitto_net_write

In loop_handle_reads_writes, we still call the function _mosquitto_packet_write, but we have sent all the msgs in mqtt3_db_message_write as I described above . So I want to know the difference between mqtt3_db_message_write and the write action in loop_handle_reads_writes.

Thanks a lot.

@toast-uz
Copy link
Contributor

toast-uz commented Mar 3, 2018

You don't have a specific trouble, and you have just a doubt on the necessity of some codes, right?

@hizilla
Copy link
Author

hizilla commented Mar 3, 2018

Yes... (⊙o⊙) I plan to write some blogs to explain the architecture and some difficult point of this MQTT broker recently. But I am confused with some codes, and that's why I asked this issue.

@toast-uz
Copy link
Contributor

toast-uz commented Mar 3, 2018

Sounds great work! I am truly looking forward to seeing it.
Sorry I'm not sure about the answer.

But this place is for reporting bugs (issue) or submitting changes (PR) .
(See "Community" of https://mosquitto.org/ .)
Could you post your question at mosquitto-dev ML with the reference of this issue, and close this issue?

@hizilla
Copy link
Author

hizilla commented Mar 3, 2018

:-) You help me a lot.Thank you very much !!!

@hizilla hizilla closed this as completed Mar 3, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Aug 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants