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 B7EFFA04C0; Mon, 28 Sep 2020 23:52:28 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 832281D6F4; Mon, 28 Sep 2020 23:51:41 +0200 (CEST) Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by dpdk.org (Postfix) with ESMTP id B34451D6C1 for ; Mon, 28 Sep 2020 23:51:36 +0200 (CEST) Received: by mail-lj1-f196.google.com with SMTP id k25so2273663ljg.9 for ; Mon, 28 Sep 2020 14:51:36 -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=VmpLHY3OgQ2bT1wqBFsKhBn9NSHfo1iyMAswym/4w9s=; b=N1rq/Gy7hOU9SldYUxuXCv8bmhfQyJbvBTPbeVs3DFwHqIfIGfK11WSMmunFTOVZDq JOXrGu2SpLdr5oVOhSuXlm1Goz0PnM47rCBGak03y0xhktwbtHaHW4lFkkWbI4T8Hmbs npHlTWa69PIDh47g2FSu1Gn+kA+rbB27/4XkQzkx635L1bxhbbNqLncYWTMl9SYJuExM 92iD6l5FXfU/T1w2PclGaczWwaUU1SagoatIbCqzLsy1Kjp1cXB+ARQ5ag8TfbpbmUda Z4sGvEW4BeUeeVYfxsYl1wY/Mvj89o1zjN0eHghHNIx+DBU6CiDX5/dgyYXf7jl7S/4c hW1g== 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=VmpLHY3OgQ2bT1wqBFsKhBn9NSHfo1iyMAswym/4w9s=; b=t5zyp0xREVcqRSiV0DBv8eHep+4m77LWgRIhKxdAOe7K4ZuDEc2g4o+TFnthjNiaui i9LFouEF8AXvJwtleKns3WxbPE16hWbdGu2oYENL2ODG7dv5hhM1G2bisHj6Z0pJUENa SrMe41cr5ijnVOsMoSBxMOHFuFLwgsJ01ScdWg3SizFuzCqU9v/kCgdP4gIBzdDZlK2B exO3yawzp1heKFqpSPgKEkcCr9lyeutQzAyM8QWauAHt5Xnk0lU+mDFUR6oGFsnNWfjH gS1DJUhdaND9IogVigDeTb2w5kR2OEXZ5CUVsN5qCoWEyJFhL0xAbpkgYel0fTVyae0y FDqA== X-Gm-Message-State: AOAM533cAchIQZRgq9pKRaM9GWyfYcraTjZOweEVjKoaJ/Nswpjs/Go+ SKxCBHc5ymWLW24Jy3Ta+Vu1M91Le4A4E/qa X-Google-Smtp-Source: ABdhPJxberBCda1cEq40baSzNlw4b5EYS1afCc0c4HolaQDRaCOlGzGu4j8KARCRcUKYTa+ySMQ8kQ== X-Received: by 2002:a2e:99c1:: with SMTP id l1mr173764ljj.95.1601329894905; Mon, 28 Sep 2020 14:51:34 -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 l11sm2954893lfk.113.2020.09.28.14.51.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 14:51:34 -0700 (PDT) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: "Kinsella, Ray" , Khoa To , Stephen Hemminger , Ferruh Yigit , Dmitry Kozlyuk , Olivier Matz Date: Tue, 29 Sep 2020 00:50:48 +0300 Message-Id: <20200928215052.23627-4-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200928215052.23627-1-dmitry.kozliuk@gmail.com> References: <20200730210652.14568-1-dmitry.kozliuk@gmail.com> <20200928215052.23627-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v3 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 | 14 ++++---------- lib/librte_cmdline/cmdline_os_unix.c | 20 ++++++++++++++++++++ lib/librte_cmdline/cmdline_private.h | 6 ++++++ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c index 41f50cc56..0b2e1e30b 100644 --- a/lib/librte_cmdline/cmdline.c +++ b/lib/librte_cmdline/cmdline.c @@ -11,13 +11,12 @@ #include #include #include -#include #include #include #include -#include "cmdline.h" +#include "cmdline_private.h" static void cmdline_valid_buffer(struct rdline *rdl, const char *buf, @@ -184,7 +183,6 @@ cmdline_quit(struct cmdline *cl) int cmdline_poll(struct cmdline *cl) { - struct pollfd pfd; int status; ssize_t read_status; char c; @@ -194,16 +192,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; @@ -225,7 +219,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 d50eb1c65..a4916c197 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 cmdline *cl) { tcsetattr(fileno(stdin), TCSANOW, &cl->oldterm); } + +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 50326e8a4..ac10de4f8 100644 --- a/lib/librte_cmdline/cmdline_private.h +++ b/lib/librte_cmdline/cmdline_private.h @@ -13,4 +13,10 @@ void terminal_adjust(struct cmdline *cl); /* Restore terminal settings form oldterm. */ void terminal_restore(const struct cmdline *cl); +/* 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.28.0