From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 9E57C3237 for ; Tue, 12 May 2015 13:21:13 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP; 12 May 2015 04:21:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,414,1427785200"; d="scan'208";a="727819803" Received: from unknown (HELO stargo) ([10.217.248.233]) by orsmga002.jf.intel.com with SMTP; 12 May 2015 04:21:07 -0700 Received: by stargo (sSMTP sendmail emulation); Tue, 12 May 2015 13:17:20 +0200 From: "Pawel Wodkowski" To: dev@dpdk.org Date: Tue, 12 May 2015 13:10:19 +0200 Message-Id: <1431429019-21130-3-git-send-email-pawelx.wodkowski@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1431429019-21130-1-git-send-email-pawelx.wodkowski@intel.com> References: <1431429019-21130-1-git-send-email-pawelx.wodkowski@intel.com> X-Mailman-Approved-At: Tue, 12 May 2015 14:06:14 +0200 Subject: [dpdk-dev] [PATCH 2/2] cmdline: add polling mode for command line X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 May 2015 11:21:14 -0000 This patch adds the ability to process console input in the same thread as packet processing by using poll() function. Signed-off-by: Pawel Wodkowski --- lib/librte_cmdline/cmdline.c | 35 ++++++++++++++++++++++++++++++ lib/librte_cmdline/cmdline.h | 1 + lib/librte_cmdline/rte_cmdline_version.map | 1 + 3 files changed, 37 insertions(+) diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c index e61c4f2..6a55f1f 100644 --- a/lib/librte_cmdline/cmdline.c +++ b/lib/librte_cmdline/cmdline.c @@ -65,6 +65,7 @@ #include #include #include +#include #include #include #include @@ -246,6 +247,40 @@ cmdline_quit(struct cmdline *cl) rdline_quit(&cl->rdl); } +int +cmdline_poll(struct cmdline *cl) +{ + struct pollfd pfd; + int status; + ssize_t read_status; + char c; + + if (!cl) + return -EINVAL; + else if (cl->rdl.status == RDLINE_EXITED) + return RDLINE_EXITED; + + pfd.fd = cl->s_in; + pfd.events = POLLIN; + pfd.revents = 0; + + status = poll(&pfd, 1, 0); + if (status < 0) + return status; + else if (status > 0) { + c = -1; + read_status = read(cl->s_in, &c, 1); + if (read_status < 0) + return read_status; + + status = cmdline_in(cl, &c, 1); + if (status < 0 && cl->rdl.status != RDLINE_EXITED) + return status; + } + + return cl->rdl.status; +} + void cmdline_interact(struct cmdline *cl) { diff --git a/lib/librte_cmdline/cmdline.h b/lib/librte_cmdline/cmdline.h index 9085ff6..39e8e6b 100644 --- a/lib/librte_cmdline/cmdline.h +++ b/lib/librte_cmdline/cmdline.h @@ -84,6 +84,7 @@ void cmdline_printf(const struct cmdline *cl, const char *fmt, ...) __attribute__((format(printf,2,3))); int cmdline_in(struct cmdline *cl, const char *buf, int size); int cmdline_write_char(struct rdline *rdl, char c); +int cmdline_poll(struct cmdline *cl); void cmdline_interact(struct cmdline *cl); void cmdline_quit(struct cmdline *cl); diff --git a/lib/librte_cmdline/rte_cmdline_version.map b/lib/librte_cmdline/rte_cmdline_version.map index 6193462..df55def 100644 --- a/lib/librte_cmdline/rte_cmdline_version.map +++ b/lib/librte_cmdline/rte_cmdline_version.map @@ -40,6 +40,7 @@ DPDK_2.0 { cmdline_parse_num; cmdline_parse_portlist; cmdline_parse_string; + cmdline_poll; cmdline_printf; cmdline_quit; cmdline_set_prompt; -- 1.9.1