serial: uart_native_pty_bottom: length parameter
Add a length parameter to the poll in read function so that data can be
read in larger chunks.
Signed-off-by: Jordan Yates <jordan@embeint.com>
diff --git a/drivers/serial/uart_native_pty.c b/drivers/serial/uart_native_pty.c
index c4da045..89f5bb3 100644
--- a/drivers/serial/uart_native_pty.c
+++ b/drivers/serial/uart_native_pty.c
@@ -170,13 +170,11 @@
return -1;
}
- rc = np_uart_stdin_poll_in_bottom(in_f, p_char);
+ rc = np_uart_stdin_poll_in_bottom(in_f, p_char, 1);
if (rc == -2) {
disconnected = true;
- return -1;
}
-
- return rc;
+ return rc == 1 ? 0 : -1;
}
/**
diff --git a/drivers/serial/uart_native_pty_bottom.c b/drivers/serial/uart_native_pty_bottom.c
index 0c5546c..3ff7ca5 100644
--- a/drivers/serial/uart_native_pty_bottom.c
+++ b/drivers/serial/uart_native_pty_bottom.c
@@ -32,12 +32,13 @@
*
* @param in_f Input file descriptor
* @param p_char Pointer to character.
+ * @param len Maximum number of characters to read.
*
- * @retval 0 If a character arrived and was stored in p_char
+ * @retval >0 Number of characters actually read
* @retval -1 If no character was available to read
* @retval -2 if the stdin is disconnected
*/
-int np_uart_stdin_poll_in_bottom(int in_f, unsigned char *p_char)
+int np_uart_stdin_poll_in_bottom(int in_f, unsigned char *p_char, int len)
{
if (feof(stdin)) {
/*
@@ -64,12 +65,12 @@
ERROR("%s: Error on select ()\n", __func__);
}
- n = read(in_f, p_char, 1);
+ n = read(in_f, p_char, len);
if ((n == -1) || (n == 0)) {
return -1;
}
- return 0;
+ return n;
}
/**
diff --git a/drivers/serial/uart_native_pty_bottom.h b/drivers/serial/uart_native_pty_bottom.h
index 5cbf278..69af6d3 100644
--- a/drivers/serial/uart_native_pty_bottom.h
+++ b/drivers/serial/uart_native_pty_bottom.h
@@ -20,7 +20,7 @@
/* Note: None of these functions are public interfaces. But internal to the native ptty driver */
-int np_uart_stdin_poll_in_bottom(int in_f, unsigned char *p_char);
+int np_uart_stdin_poll_in_bottom(int in_f, unsigned char *p_char, int len);
int np_uart_slave_connected(int fd);
int np_uart_open_pty(const char *uart_name, const char *auto_attach_cmd,
bool do_auto_attach, bool wait_pts);