DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Pawel Wodkowski" <pwodkowx@stargo>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH 2/2] cmdline: add polling mode for command line
Date: Tue, 12 May 2015 13:10:19 +0200	[thread overview]
Message-ID: <1431429019-21130-3-git-send-email-pawelx.wodkowski@intel.com> (raw)
In-Reply-To: <1431429019-21130-1-git-send-email-pawelx.wodkowski@intel.com>

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 <pawelx.wodkowski@intel.com>
---
 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 <stdarg.h>
 #include <inttypes.h>
 #include <fcntl.h>
+#include <poll.h>
 #include <errno.h>
 #include <termios.h>
 #include <netinet/in.h>
@@ -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

  parent reply	other threads:[~2015-05-12 11:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-12 11:10 [dpdk-dev] [PATCH 0/2] " Pawel Wodkowski
2015-05-12 11:10 ` [dpdk-dev] [PATCH 1/2] cmdline: fix missing include files Pawel Wodkowski
2015-05-12 11:10 ` Pawel Wodkowski [this message]
2015-05-12 14:36   ` [dpdk-dev] [PATCH 2/2] cmdline: add polling mode for command line Olivier MATZ
2015-05-12 16:14     ` Pawel Wodkowski
2015-05-12 11:36 ` [dpdk-dev] [PATCH 0/2] " Dumitrescu, Cristian
2015-05-12 15:32 ` Wodkowski, PawelX
2015-05-13 11:59 ` [dpdk-dev] [PATCH v2 " Pawel Wodkowski
2015-05-13 12:00   ` [dpdk-dev] [PATCH v2 1/2] cmdline: fix missing include files Pawel Wodkowski
2015-05-13 12:00   ` [dpdk-dev] [PATCH v2 2/2] cmdline: add polling mode for command line Pawel Wodkowski
2015-05-13 12:44   ` [dpdk-dev] [PATCH v2 0/2] " Dumitrescu, Cristian
2015-05-13 13:20   ` Olivier MATZ
2015-05-18 13:18     ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1431429019-21130-3-git-send-email-pawelx.wodkowski@intel.com \
    --to=pwodkowx@stargo \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).