From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id DDA96A052B; Thu, 30 Jul 2020 23:07:50 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 462DA1C02E; Thu, 30 Jul 2020 23:07:32 +0200 (CEST) Received: from mail-lf1-f66.google.com (mail-lf1-f66.google.com [209.85.167.66]) by dpdk.org (Postfix) with ESMTP id 1463A4C93 for ; Thu, 30 Jul 2020 23:07:26 +0200 (CEST) Received: by mail-lf1-f66.google.com with SMTP id s9so15744188lfs.4 for ; Thu, 30 Jul 2020 14:07:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9KBD5tDXCqm5NI+e5AeRBqTs67CJlCSTNrTUeRSPhGk=; b=ASNVWaHxEJN+A/4Jc5LAIlAXilIwrPJgq5wShK5MvjkB8i0qbZ0bzVbd0Hl6vl1pGw dhIBqs7ZNQ3+WOhdUfHsSk8JCZFRtXpaI2+VntjI4zbWupQYc+5UcePxUJOMuTN+OOYC s42LzeVvJvZpZy8T98CUQwDeWM3ZM2a1t1mL9N8AKQjcNuxXMjnMBTg/iG0OssCzVjmn RINPcRxi/FzAUNyG0rj86EJYEd0RECKgd8RRjbSg1oO/pqTkjQ3GnbufVskI5aNRmIG4 r3DIPsxd666lOoSZqOkzxZyL8zME5FABkNMLPIi3ZWn9hhgB6sNXTMuD9JyTe1vJekEs azNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9KBD5tDXCqm5NI+e5AeRBqTs67CJlCSTNrTUeRSPhGk=; b=ByQQVBSwljh15fo8UUM8IaBNYlSRWaYb3Xk/fH6omVPqAXDEge4hQOtxWUePXN1jAF QSZSJqeM/drMjwevN+AYv13XkmmNhq26z7VN77y/DzX0oadapDHYhVxO7tUvbLhikBO1 NUOFphCP15c1mm0cxePrtt7H+EHWVyHxLq6bNfw1qSBHkkU1kW1HpZ9xyVjTnT3vRy7S zyWRLxwbkm7wy06XPlb4HllruP+0oGW4g+BQqRfYeyR4Ofo3gz9CL6o3Jri1B0Y09Gk4 4TgVYxOofpvqK5oC+SawLaIqwhy6ogr2mmI0sxfJKc+FbF0Z5uujd047WniGMnYYuCPI +Rlg== X-Gm-Message-State: AOAM532a0Yx0FFMBSys4Gns5Ns821gLvcCc5q+HjxxuDce2I698aehGS M/4yKDxGhEoflUcfZ0uVlyRYuTAHue69Gg== X-Google-Smtp-Source: ABdhPJzwz0N7/NUzURv5frTuiNfqlaRRoJK+STTUS9gGTCbBophSNOFAzrrt43RYI8XxX9Bzbnl8tQ== X-Received: by 2002:a05:6512:358c:: with SMTP id m12mr264324lfr.18.1596143245418; Thu, 30 Jul 2020 14:07:25 -0700 (PDT) Received: from localhost.localdomain (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id y9sm1257763lji.49.2020.07.30.14.07.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jul 2020 14:07:24 -0700 (PDT) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Dmitry Malloy , Narcisa Ana Maria Vasile , Fady Bader , Tal Shnaiderman , "Kadam, Pallavi" , Dmitry Kozlyuk , Olivier Matz Date: Fri, 31 Jul 2020 00:06:47 +0300 Message-Id: <20200730210652.14568-4-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200730210652.14568-1-dmitry.kozliuk@gmail.com> References: <20200620210511.13134-1-dmitry.kozliuk@gmail.com> <20200730210652.14568-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 3/7] cmdline: add internal wrappers for character input X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" poll(3) is a purely Unix facility, so it cannot be directly used by common code. read(2) is limited in device support outside of Unix. Create wrapper functions and implement them for Unix. Signed-off-by: Dmitry Kozlyuk --- lib/librte_cmdline/cmdline.c | 12 +++--------- lib/librte_cmdline/cmdline_os_unix.c | 20 ++++++++++++++++++++ lib/librte_cmdline/cmdline_private.h | 6 ++++++ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c index 6f3fdd598..a04719998 100644 --- a/lib/librte_cmdline/cmdline.c +++ b/lib/librte_cmdline/cmdline.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include @@ -185,7 +184,6 @@ cmdline_quit(struct cmdline *cl) int cmdline_poll(struct cmdline *cl) { - struct pollfd pfd; int status; ssize_t read_status; char c; @@ -195,16 +193,12 @@ cmdline_poll(struct cmdline *cl) 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); + status = cmdline_poll_char(cl); if (status < 0) return status; else if (status > 0) { c = -1; - read_status = read(cl->s_in, &c, 1); + read_status = cmdline_read_char(cl, &c); if (read_status < 0) return read_status; @@ -226,7 +220,7 @@ cmdline_interact(struct cmdline *cl) c = -1; while (1) { - if (read(cl->s_in, &c, 1) <= 0) + if (cmdline_read_char(cl, &c) <= 0) break; if (cmdline_in(cl, &c, 1) < 0) break; diff --git a/lib/librte_cmdline/cmdline_os_unix.c b/lib/librte_cmdline/cmdline_os_unix.c index ca47bd19f..865a89ddd 100644 --- a/lib/librte_cmdline/cmdline_os_unix.c +++ b/lib/librte_cmdline/cmdline_os_unix.c @@ -2,7 +2,9 @@ * Copyright (c) 2020 Dmitry Kozlyuk */ +#include #include +#include #include "cmdline_private.h" @@ -25,3 +27,21 @@ terminal_restore(const struct terminal *oldterm) { tcsetattr(fileno(stdin), TCSANOW, &oldterm->termios); } + +int +cmdline_poll_char(struct cmdline *cl) +{ + struct pollfd pfd; + + pfd.fd = cl->s_in; + pfd.events = POLLIN; + pfd.revents = 0; + + return poll(&pfd, 1, 0); +} + +ssize_t +cmdline_read_char(struct cmdline *cl, char *c) +{ + return read(cl->s_in, c, 1); +} diff --git a/lib/librte_cmdline/cmdline_private.h b/lib/librte_cmdline/cmdline_private.h index adc552845..ecfeb89f6 100644 --- a/lib/librte_cmdline/cmdline_private.h +++ b/lib/librte_cmdline/cmdline_private.h @@ -29,4 +29,10 @@ struct cmdline { struct terminal oldterm; }; +/* Check if a single character can be read from input. */ +int cmdline_poll_char(struct cmdline *cl); + +/* Read one character from input. */ +ssize_t cmdline_read_char(struct cmdline *cl, char *c); + #endif -- 2.25.4