Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp577357ybp; Fri, 4 Oct 2019 01:21:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqwSF5fXvIq7JnOYSTzF5qA6/0nbmHDIMb8T2ttp5PBXGDXvzFBfDQe01pAZ6sHfqTOiFkJE X-Received: by 2002:a50:934c:: with SMTP id n12mr14149801eda.12.1570177264807; Fri, 04 Oct 2019 01:21:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570177264; cv=none; d=google.com; s=arc-20160816; b=a1oVWnE1gPQJGeU4doNazwaHM3sIBc48WV06VEnTdqazZknGuK1DhH8IPFSfBpDPU+ oMvWd2FS6xEe4YohrD2mT2PiRed1o7ZzsYET5TN/+lAcMzspKaoefqingSJ7PLpNqkv1 TpNvNavs0/Wq1z/gomqW3s+VGa7mV+StAdz32Tx9mPv2A8lj1AW9DkOjKgQNFmuVcc/R GCy+VaXy0xAAicptQAwpkGa4o2SN4f5YuxUmLR/5GBQtVa5ocX3ff72DJQamHbapjiKF gerAG4+x3X9cUyLyGbCgWB0QrrZTSvv194Q8g7QgZlmfGKzqmjeksvy4GwCu6lqeOtlY t5pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=55DCSgxFc7hVW6DQSPmxTSYgVif+Jlg6vTznFg7x+yo=; b=ZSOfh5sxqZtnPu9KLu4QdbLDNwRmvCwxwKpV625D2UyIgbnktls6/Rx3uGl1Stt3Ar hryrxiFE1te/i6WWZi8GyWMN5DM1wcM5AXmfv5sA9+dL5nN+dK5zXx3MD3ap7uA7uxZG umnUlP3vA8mFLagrZYT9OCuFaQrIK+ZG6HjJbD/z7fFoii1nKr58HGhK6UOAJx8DA8cL NhMxH4ZUdk582hi4VoUyoiNMXYCmJclTUG2SJC3I2f+ikIl/B+FzChKua5sxx0r6GKJ6 P1lyQvda08Dyh1Ut8haLUZ0ggh1D097JLoIzWKMexbSB5MJXlqt/oZbey3HNKQbESLsq fVIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codecoup-pl.20150623.gappssmtp.com header.s=20150623 header.b=1qibn2cJ; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a3si2849432edr.20.2019.10.04.01.20.40; Fri, 04 Oct 2019 01:21:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@codecoup-pl.20150623.gappssmtp.com header.s=20150623 header.b=1qibn2cJ; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731461AbfJDFno (ORCPT + 99 others); Fri, 4 Oct 2019 01:43:44 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:37487 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730957AbfJDFno (ORCPT ); Fri, 4 Oct 2019 01:43:44 -0400 Received: by mail-lf1-f65.google.com with SMTP id w67so3568558lff.4 for ; Thu, 03 Oct 2019 22:43:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codecoup-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=55DCSgxFc7hVW6DQSPmxTSYgVif+Jlg6vTznFg7x+yo=; b=1qibn2cJleXgOV4FSFo5Her+T3of+EySfBy8pbDKRIHi1v++jhM1xu08xH2r3dnACy lyj+sZ2JjUvlrMH+fQWsUcp9xXGcmWrjt0qFRQFhaShK3MS8QAwmGUD/57VC/VL2UM+I j8VkhCuq9x3TRR4gyOOCC1T3NrHrzhqTyJuqbY7L5Tok8aNI/DyHc7eop81/WNagqh0C rib2VsME/zkEA+8D9tPmsTT/YuobJD73blMK1DFtBV3tykEn3yPr4kBrH+gVlQSsmpzr nQ0gYA8hNkZqTebSUQbdF0FPCR1gTD9u36yYbc61kN3opX8y+Uo0m+ajVn+AgNzIJajp TKEA== 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:mime-version :content-transfer-encoding; bh=55DCSgxFc7hVW6DQSPmxTSYgVif+Jlg6vTznFg7x+yo=; b=cMeh9GCGIaXAPlWhXvyHiZkPKc82oPichvpTftIO+eZDyhGhAC7sCBsdUus2dMOWcl wXaevCWwIZtKlmehqjNIhBU3wQWZ8moj4uY77ldeXPdPAzElPlhNbD8ArilBuMSF+m0r 1RbQLil25j/QnApjniKrL132ksDl//X89d8/ijN4B7JMXHiKe7Axzb/9MaHEqj0AjLI/ e/8sV5WdwLPmqo14VeXDRb6UM0zT0zPTSHoGp1KksfV2ZK6856n2PGGDA/lxiJAuUBCn zwQnJDfB9EVho5aT8HYcHhpW1dcfS8rQArMGm+0vRmX+LsVaD/1yraILeBvoKFbmG/s/ F9+Q== X-Gm-Message-State: APjAAAWvK9SF/lx0UFV09UF3Rof4A5LyRLzvlG7rQy8CPDgn39Bb95RY ja25Rxb4pSeH9IChdhEtUzdrzqF+Wjg= X-Received: by 2002:a19:711e:: with SMTP id m30mr7932003lfc.63.1570167821726; Thu, 03 Oct 2019 22:43:41 -0700 (PDT) Received: from ix.int.codecoup.pl ([95.143.243.62]) by smtp.gmail.com with ESMTPSA id q88sm1024828lje.57.2019.10.03.22.43.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2019 22:43:41 -0700 (PDT) From: Szymon Janc To: linux-bluetooth@vger.kernel.org Cc: Andrzej Kaczmarek Subject: [PATCH V3 1/3] monitor: Extract TTY data processing to separate function Date: Fri, 4 Oct 2019 07:43:32 +0200 Message-Id: <20191004054334.5479-1-szymon.janc@codecoup.pl> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Andrzej Kaczmarek --- monitor/control.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/monitor/control.c b/monitor/control.c index 39a413be1..4022e7644 100644 --- a/monitor/control.c +++ b/monitor/control.c @@ -1300,23 +1300,8 @@ static bool tty_parse_header(uint8_t *hdr, uint8_t len, struct timeval **tv, return true; } -static void tty_callback(int fd, uint32_t events, void *user_data) +static void process_data(struct control_data *data) { - struct control_data *data = user_data; - ssize_t len; - - if (events & (EPOLLERR | EPOLLHUP)) { - mainloop_remove_fd(data->fd); - return; - } - - len = read(data->fd, data->buf + data->offset, - sizeof(data->buf) - data->offset); - if (len < 0) - return; - - data->offset += len; - while (data->offset >= sizeof(struct tty_hdr)) { struct tty_hdr *hdr = (struct tty_hdr *) data->buf; uint16_t pktlen, opcode, data_len; @@ -1358,6 +1343,26 @@ static void tty_callback(int fd, uint32_t events, void *user_data) } } +static void tty_callback(int fd, uint32_t events, void *user_data) +{ + struct control_data *data = user_data; + ssize_t len; + + if (events & (EPOLLERR | EPOLLHUP)) { + mainloop_remove_fd(data->fd); + return; + } + + len = read(data->fd, data->buf + data->offset, + sizeof(data->buf) - data->offset); + if (len < 0) + return; + + data->offset += len; + + process_data(data); +} + int control_tty(const char *path, unsigned int speed) { struct control_data *data; -- 2.21.0