Diff between 52faac4648500dd45c06b6aa41f1be426c43a125 and 068bc4b0b42459457a2556963274b95a22acdedd

Changed Files

File Additions Deletions Status
monitor/control.c +21 -16 modified

Full Patch

diff --git a/monitor/control.c b/monitor/control.c
index 39a413b..4022e76 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;