[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [mosquitto-dev] Possible Bug in in ping handling
|
Hi Graham,
Thanks, I'd got the wrong end of the stick, this makes much more sense
now. I can see what needs fixing, I just need to think about the best
way of doing it. I'll try and have a look at it tonight.
Cheers,
Roger
On Wed, Feb 24, 2016 at 5:16 PM, <mosquitto-dev.gpbenton@xxxxxxxx> wrote:
> Hi Roger,
>
> The line
>
> system("mosquitto_pub -t /test -m Off");
>
> is simulating what is happening to my client. A completely separate
> client is sending a publish, which my client accepts, but then causes my
> client to re-connect some time later.
>
> I cannot control when this other client publishes , so my client
> re-connects randomly throughout the day. My client does not normally
> publish messages.
>
> The example code publishes (from a completely separate client, as you
> say) about 3 seconds before the receiving client is due to generate a
> ping, which seems to reproduce the symptoms every time.
>
> I hope that makes the situation clearer.
>
> Regards
>
> Graham
>
>
>
> On 22/02/2016 14:48, Roger Light - roger@xxxxxxxxxx wrote:
>> Hi Graham,
>>
>> I'm not quite sure how your code can produce the behaviour you are
>> seeing. The line:
>>
>> system("mosquitto_pub -t /test -m Off");
>>
>> produces a completely new client that is unrelated to the one you are
>> running in your code - and hence wouldn't modify the keepalive timer
>> for your client. If you call mosquitto_publish() at that point instead
>> you should hopefully not have any further problems.
>>
>> Cheers,
>>
>> Roger
>>
>>
>>
>> On Sun, Feb 21, 2016 at 3:31 PM, <mosquitto-dev.gpbenton@xxxxxxxx> wrote:
>>> Hi,
>>>
>>> I believe the program below demonstrates a bug in the ping handling of a
>>> client. It appears that receiving a message just
>>> before a ping is expected results in the client sending another
>>> connection request. The result is
>>>
>>> graham@graham-VirtualBox-k14:~/engMQTTClientTest$ ./clientText
>>> Client clientText sending CONNECT
>>> Client clientText received CONNACK
>>> Client clientText sending SUBSCRIBE (Mid: 1, Topic: /test, QoS: 2)
>>> Client clientText received SUBACK
>>>
>>>
>>> Client clientText received PUBLISH (d0, q0, r0, m0, '/test', ... (3 bytes))
>>> /test:Off
>>> Client clientText sending CONNECT
>>> Client clientText received CONNACK
>>> Client clientText sending SUBSCRIBE (Mid: 2, Topic: /test, QoS: 2)
>>> Client clientText received SUBACK
>>> Client clientText received PUBLISH (d0, q0, r0, m0, '/test', ... (3 bytes))
>>> /test:Off
>>> ^C
>>>
>>>
>>> Of course, I may have misinterpreted something.
>>>
>>> Regards
>>>
>>> Graham Benton
>>>
>>>
>>> #include <stdio.h>
>>> #include <string.h>
>>> #include <time.h>
>>> #include <mosquitto.h>
>>>
>>> enum fail_codes {
>>> ERROR_LOG4C_INIT=1,
>>> ERROR_MOSQ_NEW,
>>> ERROR_MOSQ_CONNECT,
>>> ERROR_MOSQ_LOOP_START,
>>> ERROR_ENER_INIT_FAIL
>>> };
>>>
>>> int countdown = 0;
>>>
>>> void my_message_callback(struct mosquitto *mosq, void *userdata,
>>> const struct mosquitto_message *message)
>>> {
>>> char tempString[message->payloadlen+1];
>>> strncpy(tempString, message->payload, message->payloadlen);
>>> tempString[message->payloadlen] = '\0';
>>>
>>> printf("%s:%s\n", message->topic, tempString);
>>> }
>>>
>>>
>>> void my_connect_callback(struct mosquitto *mosq, void *userdata, int result)
>>> {
>>>
>>> if(!result){
>>> /* Subscribe to broker information topics on successful connect. */
>>> mosquitto_subscribe(mosq, NULL, "/test", 2);
>>>
>>> }else{
>>> printf("Not Connected");
>>> }
>>> }
>>>
>>> void my_log_callback(struct mosquitto *mosq, void *userdata, int level,
>>> const char *str)
>>> {
>>> printf("%s\n", str);
>>>
>>> countdown = 17;
>>>
>>> }
>>>
>>> int main(int argc, char **argv){
>>> struct mosquitto *mosq = NULL;
>>> int err = 0;
>>>
>>>
>>>
>>> mosquitto_lib_init();
>>> mosq = mosquitto_new("clientText", true, NULL);
>>> if(!mosq){
>>> return ERROR_MOSQ_NEW;
>>> }
>>>
>>> mosquitto_log_callback_set(mosq, my_log_callback);
>>> mosquitto_connect_callback_set(mosq, my_connect_callback);
>>> mosquitto_message_callback_set(mosq, my_message_callback);
>>>
>>> if((err = mosquitto_connect_async(mosq, "localhost", 1883, 20))
>>> != MOSQ_ERR_SUCCESS){
>>> return ERROR_MOSQ_CONNECT;
>>> }
>>>
>>> if ((err = mosquitto_loop_start(mosq)) != MOSQ_ERR_SUCCESS) {
>>> mosquitto_disconnect(mosq);
>>> mosquitto_destroy(mosq);
>>> mosquitto_lib_cleanup();
>>> return ERROR_MOSQ_LOOP_START;
>>> }
>>>
>>> while (1) {
>>> sleep(1);
>>> /* Send a message just before the ping is due */
>>> if (--countdown == 0) {
>>> system("mosquitto_pub -t /test -m Off");
>>> }
>>> }
>>>
>>> }
>>>
>>>
>>>
>>> _______________________________________________
>>> mosquitto-dev mailing list
>>> mosquitto-dev@xxxxxxxxxxx
>>> To change your delivery options, retrieve your password, or unsubscribe from this list, visit
>>> https://dev.eclipse.org/mailman/listinfo/mosquitto-dev
>> _______________________________________________
>> mosquitto-dev mailing list
>> mosquitto-dev@xxxxxxxxxxx
>> To change your delivery options, retrieve your password, or unsubscribe from this list, visit
>> https://dev.eclipse.org/mailman/listinfo/mosquitto-dev
>>
>
>
> _______________________________________________
> mosquitto-dev mailing list
> mosquitto-dev@xxxxxxxxxxx
> To change your delivery options, retrieve your password, or unsubscribe from this list, visit
> https://dev.eclipse.org/mailman/listinfo/mosquitto-dev