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>
Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Acked-by: Olivier Matz <olivier.matz@6wind.com>
lib/librte_eal/common/include \
lib/librte_eal/common/include/generic \
lib/librte_acl \
lib/librte_eal/common/include \
lib/librte_eal/common/include/generic \
lib/librte_acl \
lib/librte_distributor \
lib/librte_ether \
lib/librte_hash \
lib/librte_distributor \
lib/librte_ether \
lib/librte_hash \
#include <stdarg.h>
#include <inttypes.h>
#include <fcntl.h>
#include <stdarg.h>
#include <inttypes.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <netinet/in.h>
#include <errno.h>
#include <termios.h>
#include <netinet/in.h>
+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)
{
void
cmdline_interact(struct cmdline *cl)
{
#include <termios.h>
#include <cmdline_rdline.h>
#include <termios.h>
#include <cmdline_rdline.h>
+/**
+ * @file
+ *
+ * Command line API
+ */
+
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
extern "C" {
#endif
__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);
__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);
+
+/**
+ * This function is nonblocking equivalent of ``cmdline_interact()``. It polls
+ * *cl* for one character and interpret it. If return value is *RDLINE_EXITED*
+ * it mean that ``cmdline_quit()`` was invoked.
+ *
+ * @param cl
+ * The command line object.
+ *
+ * @return
+ * On success return object status - one of *enum rdline_status*.
+ * On error return negative value.
+ */
+int cmdline_poll(struct cmdline *cl);
+
void cmdline_interact(struct cmdline *cl);
void cmdline_quit(struct cmdline *cl);
void cmdline_interact(struct cmdline *cl);
void cmdline_quit(struct cmdline *cl);
+
+DPDK_2.1 {
+ global:
+
+ cmdline_poll;
+
+ local: *;
+} DPDK_2.0;