Add keepalive option

This option provides a configurable Keep Alive interval. This
configuration allows a better analysis of PINGREQ and PINGRESP
packages on tools like Wireshark.
Signed-off-by: 's avatarGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
parent 0a1aa7d6
......@@ -12,6 +12,7 @@
*
* Contributors:
* Ian Craggs - initial contribution
* Guilherme Maciel Ferreira - add keep alive option
*******************************************************************************/
/*
......@@ -29,6 +30,7 @@
--delimiters \n
--clientid stdin_publisher
--maxdatalen 100
--keepalive 10
--userid none
--password none
......@@ -68,6 +70,7 @@ void usage()
printf(" --maxdatalen 100\n");
printf(" --username none\n");
printf(" --password none\n");
printf(" --keepalive <seconds> (default is 10 seconds)\n");
exit(-1);
}
......@@ -102,9 +105,10 @@ struct
char* host;
char* port;
int verbose;
int keepalive;
} opts =
{
"publisher", "\n", 100, 0, 0, NULL, NULL, "localhost", "1883", 0
"publisher", "\n", 100, 0, 0, NULL, NULL, "localhost", "1883", 0, 10
};
void getopts(int argc, char** argv);
......@@ -143,7 +147,7 @@ int main(int argc, char** argv)
rc = MQTTClient_setCallbacks(client, NULL, NULL, messageArrived, NULL);
conn_opts.keepAliveInterval = 10;
conn_opts.keepAliveInterval = opts.keepalive;
conn_opts.reliable = 0;
conn_opts.cleansession = 1;
conn_opts.username = opts.username;
......@@ -268,6 +272,13 @@ void getopts(int argc, char** argv)
else
usage();
}
else if (strcmp(argv[count], "--keepalive") == 0)
{
if (++count < argc)
opts.keepalive = atoi(argv[count]);
else
usage();
}
count++;
}
......
......@@ -12,6 +12,7 @@
*
* Contributors:
* Ian Craggs - initial contribution
* Guilherme Maciel Ferreira - add keep alive option
*******************************************************************************/
/*
......@@ -29,6 +30,7 @@
--delimiters \n
--clientid stdin_publisher
--maxdatalen 100
--keepalive 10
--userid none
--password none
......@@ -67,6 +69,7 @@ void usage()
printf(" --maxdatalen 100\n");
printf(" --username none\n");
printf(" --password none\n");
printf(" --keepalive <seconds> (default is 10 seconds)\n");
exit(-1);
}
......@@ -91,9 +94,10 @@ struct
char* host;
char* port;
int verbose;
int keepalive;
} opts =
{
"publisher", "\n", 100, 0, 0, NULL, NULL, "localhost", "1883", 0
"publisher", "\n", 100, 0, 0, NULL, NULL, "localhost", "1883", 0, 10
};
void getopts(int argc, char** argv);
......@@ -139,7 +143,7 @@ void myconnect(MQTTAsync* client)
int rc = 0;
printf("Connecting\n");
conn_opts.keepAliveInterval = 10;
conn_opts.keepAliveInterval = opts.keepalive;
conn_opts.cleansession = 1;
conn_opts.username = opts.username;
conn_opts.password = opts.password;
......@@ -484,6 +488,13 @@ void getopts(int argc, char** argv)
else
usage();
}
else if (strcmp(argv[count], "--keepalive") == 0)
{
if (++count < argc)
opts.keepalive = atoi(argv[count]);
else
usage();
}
count++;
}
......
......@@ -13,6 +13,7 @@
* Contributors:
* Ian Craggs - initial contribution
* Ian Craggs - change delimiter option from char to string
* Guilherme Maciel Ferreira - add keep alive option
*******************************************************************************/
/*
......@@ -31,6 +32,7 @@
--delimiter \n
--clientid stdout_subscriber
--showtopics off
--keepalive 10
--userid none
--password none
......@@ -68,6 +70,7 @@ void usage()
printf(" --username none\n");
printf(" --password none\n");
printf(" --showtopics <on or off> (default is on if the topic has a wildcard, else off)\n");
printf(" --keepalive <seconds> (default is 10 seconds)\n");
exit(-1);
}
......@@ -101,9 +104,10 @@ struct opts_struct
char* host;
char* port;
int showtopics;
int keepalive;
} opts =
{
"stdout-subscriber", 0, "\n", 2, NULL, NULL, "localhost", "1883", 0
"stdout-subscriber", 0, "\n", 2, NULL, NULL, "localhost", "1883", 0, 10
};
void getopts(int argc, char** argv);
......@@ -134,7 +138,7 @@ int main(int argc, char** argv)
signal(SIGINT, cfinish);
signal(SIGTERM, cfinish);
conn_opts.keepAliveInterval = 10;
conn_opts.keepAliveInterval = opts.keepalive;
conn_opts.reliable = 0;
conn_opts.cleansession = 1;
conn_opts.username = opts.username;
......@@ -254,6 +258,13 @@ void getopts(int argc, char** argv)
else
usage();
}
else if (strcmp(argv[count], "--keepalive") == 0)
{
if (++count < argc)
opts.keepalive = atoi(argv[count]);
else
usage();
}
count++;
}
......
......@@ -13,6 +13,7 @@
* Contributors:
* Ian Craggs - initial contribution
* Ian Craggs - fix for bug 413429 - connectionLost not called
* Guilherme Maciel Ferreira - add keep alive option
*******************************************************************************/
/*
......@@ -31,6 +32,7 @@
--delimiter \n
--clientid stdout_subscriber
--showtopics off
--keepalive 10
--userid none
--password none
......@@ -79,9 +81,10 @@ struct
char* host;
char* port;
int showtopics;
int keepalive;
} opts =
{
"stdout-subscriber", 1, '\n', 2, NULL, NULL, "localhost", "1883", 0
"stdout-subscriber", 1, '\n', 2, NULL, NULL, "localhost", "1883", 0, 10
};
......@@ -97,6 +100,7 @@ void usage()
printf(" --username none\n");
printf(" --password none\n");
printf(" --showtopics <on or off> (default is on if the topic has a wildcard, else off)\n");
printf(" --keepalive <seconds> (default is 10 seconds)\n");
exit(-1);
}
......@@ -185,6 +189,13 @@ void getopts(int argc, char** argv)
else
usage();
}
else if (strcmp(argv[count], "--keepalive") == 0)
{
if (++count < argc)
opts.keepalive = atoi(argv[count]);
else
usage();
}
count++;
}
......@@ -297,7 +308,7 @@ int main(int argc, char** argv)
signal(SIGINT, cfinish);
signal(SIGTERM, cfinish);
conn_opts.keepAliveInterval = 10;
conn_opts.keepAliveInterval = opts.keepalive;
conn_opts.cleansession = 1;
conn_opts.username = opts.username;
conn_opts.password = opts.password;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment