[dpdk-dev] [PATCH 3/8] examples/packet_ordering: enhance getopt_long usage

Ibtisam Tariq ibtisam.tariq at emumba.com
Thu Oct 29 13:53:34 CET 2020


Instead of using getopt_long return value, strcmp was used to
compare the input parameters with the struct option array. This
patch get rid of all those strcmp by directly binding each longopt
with an int enum.

Bugzilla ID: 238
Fixes: 850f3733f8 ("examples/packet_ordering: new sample app")
Fixes: 016493307a ("examples/packet_ordering: add stats per worker thread")
Cc: sergio.gonzalez.monroy at intel.com
Cc: phil.yang at arm.com

Reported-by: David Marchand <david.marchand at redhat.com>
Signed-off-by: Ibtisam Tariq <ibtisam.tariq at emumba.com>
---
 examples/packet_ordering/main.c | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/examples/packet_ordering/main.c b/examples/packet_ordering/main.c
index a79d77a32..ac41d1a88 100644
--- a/examples/packet_ordering/main.c
+++ b/examples/packet_ordering/main.c
@@ -29,6 +29,13 @@
 /* Macros for printing using RTE_LOG */
 #define RTE_LOGTYPE_REORDERAPP          RTE_LOGTYPE_USER1
 
+enum{
+#define OPTION_DISABLE_REORDER "disable-reorder"
+	OPTION_DISABLE_REORDER_NUM = 256,
+#define OPTION_INSIGHT_WORKER "insight-worker"
+	OPTION_INSIGHT_WORKER_NUM,
+};
+
 unsigned int portmask;
 unsigned int disable_reorder;
 unsigned int insight_worker;
@@ -157,8 +164,8 @@ parse_args(int argc, char **argv)
 	char **argvopt;
 	char *prgname = argv[0];
 	static struct option lgopts[] = {
-		{"disable-reorder", 0, 0, 0},
-		{"insight-worker", 0, 0, 0},
+		{OPTION_DISABLE_REORDER, 0, NULL, OPTION_DISABLE_REORDER_NUM},
+		{OPTION_INSIGHT_WORKER, 0, NULL, OPTION_INSIGHT_WORKER_NUM},
 		{NULL, 0, 0, 0}
 	};
 
@@ -177,17 +184,18 @@ parse_args(int argc, char **argv)
 			}
 			break;
 		/* long options */
-		case 0:
-			if (!strcmp(lgopts[option_index].name, "disable-reorder")) {
-				printf("reorder disabled\n");
-				disable_reorder = 1;
-			}
-			if (!strcmp(lgopts[option_index].name,
-						"insight-worker")) {
-				printf("print all worker statistics\n");
-				insight_worker = 1;
-			}
+		case OPTION_DISABLE_REORDER_NUM:
+		{
+			printf("reorder disabled\n");
+			disable_reorder = 1;
 			break;
+		}
+		case OPTION_INSIGHT_WORKER_NUM:
+		{
+			printf("print all worker statistics\n");
+			insight_worker = 1;
+			break;
+		}
 		default:
 			print_usage(prgname);
 			return -1;
-- 
2.17.1



More information about the dev mailing list