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 @@ ...@@ -12,6 +12,7 @@
* *
* Contributors: * Contributors:
* Ian Craggs - initial contribution * Ian Craggs - initial contribution
* Guilherme Maciel Ferreira - add keep alive option
*******************************************************************************/ *******************************************************************************/
/* /*
...@@ -29,6 +30,7 @@ ...@@ -29,6 +30,7 @@
--delimiters \n --delimiters \n
--clientid stdin_publisher --clientid stdin_publisher
--maxdatalen 100 --maxdatalen 100
--keepalive 10
--userid none --userid none
--password none --password none
...@@ -68,6 +70,7 @@ void usage() ...@@ -68,6 +70,7 @@ void usage()
printf(" --maxdatalen 100\n"); printf(" --maxdatalen 100\n");
printf(" --username none\n"); printf(" --username none\n");
printf(" --password none\n"); printf(" --password none\n");
printf(" --keepalive <seconds> (default is 10 seconds)\n");
exit(-1); exit(-1);
} }
...@@ -102,9 +105,10 @@ struct ...@@ -102,9 +105,10 @@ struct
char* host; char* host;
char* port; char* port;
int verbose; int verbose;
int keepalive;
} opts = } 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); void getopts(int argc, char** argv);
...@@ -143,7 +147,7 @@ int main(int argc, char** argv) ...@@ -143,7 +147,7 @@ int main(int argc, char** argv)
rc = MQTTClient_setCallbacks(client, NULL, NULL, messageArrived, NULL); rc = MQTTClient_setCallbacks(client, NULL, NULL, messageArrived, NULL);
conn_opts.keepAliveInterval = 10; conn_opts.keepAliveInterval = opts.keepalive;
conn_opts.reliable = 0; conn_opts.reliable = 0;
conn_opts.cleansession = 1; conn_opts.cleansession = 1;
conn_opts.username = opts.username; conn_opts.username = opts.username;
...@@ -268,6 +272,13 @@ void getopts(int argc, char** argv) ...@@ -268,6 +272,13 @@ void getopts(int argc, char** argv)
else else
usage(); usage();
} }
else if (strcmp(argv[count], "--keepalive") == 0)
{
if (++count < argc)
opts.keepalive = atoi(argv[count]);
else
usage();
}
count++; count++;
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
* *
* Contributors: * Contributors:
* Ian Craggs - initial contribution * Ian Craggs - initial contribution
* Guilherme Maciel Ferreira - add keep alive option
*******************************************************************************/ *******************************************************************************/
/* /*
...@@ -29,6 +30,7 @@ ...@@ -29,6 +30,7 @@
--delimiters \n --delimiters \n
--clientid stdin_publisher --clientid stdin_publisher
--maxdatalen 100 --maxdatalen 100
--keepalive 10
--userid none --userid none
--password none --password none
...@@ -67,6 +69,7 @@ void usage() ...@@ -67,6 +69,7 @@ void usage()
printf(" --maxdatalen 100\n"); printf(" --maxdatalen 100\n");
printf(" --username none\n"); printf(" --username none\n");
printf(" --password none\n"); printf(" --password none\n");
printf(" --keepalive <seconds> (default is 10 seconds)\n");
exit(-1); exit(-1);
} }
...@@ -91,9 +94,10 @@ struct ...@@ -91,9 +94,10 @@ struct
char* host; char* host;
char* port; char* port;
int verbose; int verbose;
int keepalive;
} opts = } 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); void getopts(int argc, char** argv);
...@@ -139,7 +143,7 @@ void myconnect(MQTTAsync* client) ...@@ -139,7 +143,7 @@ void myconnect(MQTTAsync* client)
int rc = 0; int rc = 0;
printf("Connecting\n"); printf("Connecting\n");
conn_opts.keepAliveInterval = 10; conn_opts.keepAliveInterval = opts.keepalive;
conn_opts.cleansession = 1; conn_opts.cleansession = 1;
conn_opts.username = opts.username; conn_opts.username = opts.username;
conn_opts.password = opts.password; conn_opts.password = opts.password;
...@@ -484,6 +488,13 @@ void getopts(int argc, char** argv) ...@@ -484,6 +488,13 @@ void getopts(int argc, char** argv)
else else
usage(); usage();
} }
else if (strcmp(argv[count], "--keepalive") == 0)
{
if (++count < argc)
opts.keepalive = atoi(argv[count]);
else
usage();
}
count++; count++;
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* Contributors: * Contributors:
* Ian Craggs - initial contribution * Ian Craggs - initial contribution
* Ian Craggs - change delimiter option from char to string * Ian Craggs - change delimiter option from char to string
* Guilherme Maciel Ferreira - add keep alive option
*******************************************************************************/ *******************************************************************************/
/* /*
...@@ -31,6 +32,7 @@ ...@@ -31,6 +32,7 @@
--delimiter \n --delimiter \n
--clientid stdout_subscriber --clientid stdout_subscriber
--showtopics off --showtopics off
--keepalive 10
--userid none --userid none
--password none --password none
...@@ -68,6 +70,7 @@ void usage() ...@@ -68,6 +70,7 @@ void usage()
printf(" --username none\n"); printf(" --username none\n");
printf(" --password none\n"); printf(" --password none\n");
printf(" --showtopics <on or off> (default is on if the topic has a wildcard, else off)\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); exit(-1);
} }
...@@ -101,9 +104,10 @@ struct opts_struct ...@@ -101,9 +104,10 @@ struct opts_struct
char* host; char* host;
char* port; char* port;
int showtopics; int showtopics;
int keepalive;
} opts = } 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); void getopts(int argc, char** argv);
...@@ -134,7 +138,7 @@ int main(int argc, char** argv) ...@@ -134,7 +138,7 @@ int main(int argc, char** argv)
signal(SIGINT, cfinish); signal(SIGINT, cfinish);
signal(SIGTERM, cfinish); signal(SIGTERM, cfinish);
conn_opts.keepAliveInterval = 10; conn_opts.keepAliveInterval = opts.keepalive;
conn_opts.reliable = 0; conn_opts.reliable = 0;
conn_opts.cleansession = 1; conn_opts.cleansession = 1;
conn_opts.username = opts.username; conn_opts.username = opts.username;
...@@ -254,6 +258,13 @@ void getopts(int argc, char** argv) ...@@ -254,6 +258,13 @@ void getopts(int argc, char** argv)
else else
usage(); usage();
} }
else if (strcmp(argv[count], "--keepalive") == 0)
{
if (++count < argc)
opts.keepalive = atoi(argv[count]);
else
usage();
}
count++; count++;
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* Contributors: * Contributors:
* Ian Craggs - initial contribution * Ian Craggs - initial contribution
* Ian Craggs - fix for bug 413429 - connectionLost not called * Ian Craggs - fix for bug 413429 - connectionLost not called
* Guilherme Maciel Ferreira - add keep alive option
*******************************************************************************/ *******************************************************************************/
/* /*
...@@ -31,6 +32,7 @@ ...@@ -31,6 +32,7 @@
--delimiter \n --delimiter \n
--clientid stdout_subscriber --clientid stdout_subscriber
--showtopics off --showtopics off
--keepalive 10
--userid none --userid none
--password none --password none
...@@ -79,9 +81,10 @@ struct ...@@ -79,9 +81,10 @@ struct
char* host; char* host;
char* port; char* port;
int showtopics; int showtopics;
int keepalive;
} opts = } 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() ...@@ -97,6 +100,7 @@ void usage()
printf(" --username none\n"); printf(" --username none\n");
printf(" --password none\n"); printf(" --password none\n");
printf(" --showtopics <on or off> (default is on if the topic has a wildcard, else off)\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); exit(-1);
} }
...@@ -185,6 +189,13 @@ void getopts(int argc, char** argv) ...@@ -185,6 +189,13 @@ void getopts(int argc, char** argv)
else else
usage(); usage();
} }
else if (strcmp(argv[count], "--keepalive") == 0)
{
if (++count < argc)
opts.keepalive = atoi(argv[count]);
else
usage();
}
count++; count++;
} }
...@@ -297,7 +308,7 @@ int main(int argc, char** argv) ...@@ -297,7 +308,7 @@ int main(int argc, char** argv)
signal(SIGINT, cfinish); signal(SIGINT, cfinish);
signal(SIGTERM, cfinish); signal(SIGTERM, cfinish);
conn_opts.keepAliveInterval = 10; conn_opts.keepAliveInterval = opts.keepalive;
conn_opts.cleansession = 1; conn_opts.cleansession = 1;
conn_opts.username = opts.username; conn_opts.username = opts.username;
conn_opts.password = opts.password; 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