From: Szymon Janc <szymon.janc@codecoup.pl>
To: linux-bluetooth@vger.kernel.org
Cc: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
Subject: [PATCH V3 1/3] monitor: Extract TTY data processing to separate function
Date: Fri, 4 Oct 2019 07:43:32 +0200 [thread overview]
Message-ID: <20191004054334.5479-1-szymon.janc@codecoup.pl> (raw)
From: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
---
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
next reply other threads:[~2019-10-04 5:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-04 5:43 Szymon Janc [this message]
2019-10-04 5:43 ` [PATCH V3 2/3] monitor: Add interface for J-Link library Szymon Janc
2019-10-04 5:43 ` [PATCH V3 3/3] monitor: Add support for reading over J-Link RTT Szymon Janc
2019-10-14 10:15 ` [PATCH V3 1/3] monitor: Extract TTY data processing to separate function Szymon Janc
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=20191004054334.5479-1-szymon.janc@codecoup.pl \
--to=szymon.janc@codecoup.pl \
--cc=andrzej.kaczmarek@codecoup.pl \
--cc=linux-bluetooth@vger.kernel.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).