From 578dac0cf362b7f6012dd09a68b8306fffe6611c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 18 Nov 2008 21:07:18 +0000 Subject: [PATCH] * tty_select() did not check for ICANON and therefore notified the select listeners immediately if there was already something in the queue. Factored out a tty_readable() out of tty_notify_if_available() that tty_select() now uses. * This fixes bug #3148. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28687 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/drivers/tty/tty.cpp | 27 ++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/add-ons/kernel/drivers/tty/tty.cpp b/src/add-ons/kernel/drivers/tty/tty.cpp index f5cfb3260f..0837f12f8f 100644 --- a/src/add-ons/kernel/drivers/tty/tty.cpp +++ b/src/add-ons/kernel/drivers/tty/tty.cpp @@ -1105,6 +1105,19 @@ tty_close_cookie(struct tty_cookie *cookie) } +static int32 +tty_readable(struct tty* tty) +{ + if (!tty->is_master && (tty->settings->termios.c_lflag & ICANON) != 0) { + return line_buffer_readable_line(tty->input_buffer, + tty->settings->termios.c_cc[VEOL], + tty->settings->termios.c_cc[VEOF]); + } + + return line_buffer_readable(tty->input_buffer); +} + + static void tty_notify_select_event(struct tty *tty, uint8 event) { @@ -1134,14 +1147,7 @@ tty_notify_if_available(struct tty *tty, struct tty *otherTTY, // Check, if something is readable (depending on whether canonical input // processing is enabled). - int32 readable; - if (!tty->is_master && (tty->settings->termios.c_lflag & ICANON) != 0) { - readable = line_buffer_readable_line(tty->input_buffer, - tty->settings->termios.c_cc[VEOL], - tty->settings->termios.c_cc[VEOF]); - } else - readable = line_buffer_readable(tty->input_buffer); - + int32 readable = tty_readable(tty); if (readable > 0) { // if nobody is waiting send select events, otherwise notify the waiter if (!tty->reader_queue.IsEmpty()) @@ -1895,10 +1901,8 @@ tty_select(tty_cookie *cookie, uint8 event, uint32 ref, selectsync *sync) // check, if the event is already present switch (event) { case B_SELECT_READ: - if (tty->reader_queue.IsEmpty() - && line_buffer_readable(tty->input_buffer) > 0) { + if (tty->reader_queue.IsEmpty() && tty_readable(tty) > 0) notify_select_event(sync, event); - } break; case B_SELECT_WRITE: @@ -1922,7 +1926,6 @@ tty_select(tty_cookie *cookie, uint8 event, uint32 ref, selectsync *sync) notify_select_event(sync, event); } } - break; }