public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH 0/2] Cygwin: pty, console: Make FLUSHO and Ctrl-O work.
@ 2021-02-19  8:44 Takashi Yano
  2021-02-19  8:44 ` [PATCH 1/2] Cygwin: pty: " Takashi Yano
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Takashi Yano @ 2021-02-19  8:44 UTC (permalink / raw)
  To: cygwin-patches

- With these patches, FLUSHO and Ctrl-O (VDISCARD) get working.

Takashi Yano (2):
  Cygwin: pty: Make FLUSHO and Ctrl-O work.
  Cygwin: console: Add support for FLUSHO and Ctrl-O.

 winsup/cygwin/fhandler.h          |  1 +
 winsup/cygwin/fhandler_console.cc | 11 +++++++++++
 winsup/cygwin/fhandler_tty.cc     | 17 +++++++++++------
 winsup/cygwin/select.cc           |  5 +++++
 winsup/cygwin/tty.cc              |  1 +
 winsup/cygwin/tty.h               |  1 +
 6 files changed, 30 insertions(+), 6 deletions(-)

-- 
2.30.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] Cygwin: pty: Make FLUSHO and Ctrl-O work.
  2021-02-19  8:44 [PATCH 0/2] Cygwin: pty, console: Make FLUSHO and Ctrl-O work Takashi Yano
@ 2021-02-19  8:44 ` Takashi Yano
  2021-02-19  8:44 ` [PATCH 2/2] Cygwin: console: Add support for FLUSHO and Ctrl-O Takashi Yano
  2021-02-19 17:09 ` [PATCH 0/2] Cygwin: pty, console: Make FLUSHO and Ctrl-O work Corinna Vinschen
  2 siblings, 0 replies; 4+ messages in thread
From: Takashi Yano @ 2021-02-19  8:44 UTC (permalink / raw)
  To: cygwin-patches

- Previously, FLUSHO feature was implemented incompletely. With
  this patch, FLUSHO and Ctrl-O (VDISCARD) get working.
---
 winsup/cygwin/fhandler.h      |  1 +
 winsup/cygwin/fhandler_tty.cc | 17 +++++++++++------
 winsup/cygwin/select.cc       |  5 +++++
 winsup/cygwin/tty.cc          |  1 +
 winsup/cygwin/tty.h           |  1 +
 5 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index faa910692..5d095d384 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -2467,6 +2467,7 @@ public:
   bool to_be_read_from_pcon (void);
   void get_master_thread_param (master_thread_param_t *p);
   void get_master_fwd_thread_param (master_fwd_thread_param_t *p);
+  void set_mask_flusho (bool m) { get_ttyp ()->mask_flusho = m; }
 };
 
 class fhandler_dev_null: public fhandler_base
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index e4c35ea41..d30041af1 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -612,8 +612,8 @@ fhandler_pty_master::process_slave_output (char *buf, size_t len, int pktmode_on
 	      rc = -1;
 	      goto out;
 	    }
-	  /* DISCARD (FLUSHO) and tcflush can finish here. */
-	  if ((get_ttyp ()->ti.c_lflag & FLUSHO || !buf))
+	  /* tclush can finish here. */
+	  if (!buf)
 	    goto out;
 
 	  if (is_nonblocking ())
@@ -671,8 +671,9 @@ fhandler_pty_master::process_slave_output (char *buf, size_t len, int pktmode_on
 
       termios_printf ("bytes read %u", n);
 
-      if (get_ttyp ()->ti.c_lflag & FLUSHO || !buf)
-	continue;
+      if (!buf || ((get_ttyp ()->ti.c_lflag & FLUSHO)
+		   && !get_ttyp ()->mask_flusho))
+	continue; /* Discard read data */
 
       memcpy (optr, outbuf, n);
       optr += n;
@@ -691,6 +692,8 @@ fhandler_pty_master::process_slave_output (char *buf, size_t len, int pktmode_on
     }
 
 out:
+  if (buf)
+    set_mask_flusho (false);
   termios_printf ("returning %d", rc);
   return rc;
 }
@@ -2036,7 +2039,7 @@ fhandler_pty_master::write (const void *ptr, size_t len)
 {
   ssize_t ret;
   char *p = (char *) ptr;
-  termios ti = tc ()->ti;
+  termios &ti = tc ()->ti;
 
   bg_check_types bg = bg_check (SIGTTOU);
   if (bg <= bg_eof)
@@ -2193,7 +2196,7 @@ fhandler_pty_master::tcflush (int queue)
 
   if (queue == TCIFLUSH || queue == TCIOFLUSH)
     ret = process_slave_output (NULL, OUT_BUFFER_SIZE, 0);
-  else if (queue == TCIFLUSH || queue == TCIOFLUSH)
+  if (queue == TCOFLUSH || queue == TCIOFLUSH)
     {
       /* do nothing for now. */
     }
@@ -2929,6 +2932,8 @@ fhandler_pty_common::process_opost_output (HANDLE h, const void *ptr,
 {
   ssize_t towrite = len;
   BOOL res = TRUE;
+  if (ttyp->ti.c_lflag & FLUSHO)
+    return res; /* Discard write data */
   while (towrite)
     {
       if (!is_echo)
diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc
index 085de6deb..c8f288c27 100644
--- a/winsup/cygwin/select.cc
+++ b/winsup/cygwin/select.cc
@@ -710,6 +710,11 @@ peek_pipe (select_record *s, bool from_select)
     }
 
 out:
+  if (fh->get_major () == DEV_PTYM_MAJOR)
+    {
+      fhandler_pty_master *fhm = (fhandler_pty_master *) fh;
+      fhm->set_mask_flusho (s->read_ready);
+    }
   h = fh->get_output_handle_cyg ();
   if (s->write_selected && dev != FH_PIPER)
     {
diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc
index 7627cd6c7..eaab573e0 100644
--- a/winsup/cygwin/tty.cc
+++ b/winsup/cygwin/tty.cc
@@ -252,6 +252,7 @@ tty::init ()
   req_xfer_input = false;
   pcon_input_state = to_cyg;
   last_sig = 0;
+  mask_flusho = false;
 }
 
 HANDLE
diff --git a/winsup/cygwin/tty.h b/winsup/cygwin/tty.h
index 4ef1e04c9..b74120416 100644
--- a/winsup/cygwin/tty.h
+++ b/winsup/cygwin/tty.h
@@ -130,6 +130,7 @@ private:
   bool master_is_running_as_service;
   bool req_xfer_input;
   xfer_dir pcon_input_state;
+  bool mask_flusho;
 
 public:
   HANDLE from_master () const { return _from_master; }
-- 
2.30.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] Cygwin: console: Add support for FLUSHO and Ctrl-O.
  2021-02-19  8:44 [PATCH 0/2] Cygwin: pty, console: Make FLUSHO and Ctrl-O work Takashi Yano
  2021-02-19  8:44 ` [PATCH 1/2] Cygwin: pty: " Takashi Yano
@ 2021-02-19  8:44 ` Takashi Yano
  2021-02-19 17:09 ` [PATCH 0/2] Cygwin: pty, console: Make FLUSHO and Ctrl-O work Corinna Vinschen
  2 siblings, 0 replies; 4+ messages in thread
From: Takashi Yano @ 2021-02-19  8:44 UTC (permalink / raw)
  To: cygwin-patches

- With this patch, FLUSHO and Ctrl-O (VDISCARD) get working.
---
 winsup/cygwin/fhandler_console.cc | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
index ca8eb6400..6ded9eabf 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -259,6 +259,7 @@ fhandler_console::cons_master_thread (handle_set_t *p, tty *ttyp)
 		    {
 		      ttyp->kill_pgrp (sig);
 		      ttyp->output_stopped = false;
+		      ti.c_lflag &= ~FLUSHO;
 		      /* Discard type ahead input */
 		      goto skip_writeback;
 		    }
@@ -286,6 +287,13 @@ fhandler_console::cons_master_thread (handle_set_t *p, tty *ttyp)
 			   && c && i >= output_stopped_at)
 		    goto restart_output;
 		}
+	      if ((ti.c_lflag & ICANON) && (ti.c_lflag & IEXTEN)
+		  && CCEQ (ti.c_cc[VDISCARD], c))
+		{
+		  if (input_rec[i].Event.KeyEvent.bKeyDown)
+		    ti.c_lflag ^= FLUSHO;
+		  processed = true;
+		}
 	      break;
 	    case WINDOW_BUFFER_SIZE_EVENT:
 	      SHORT y = con.dwWinSize.Y;
@@ -3052,6 +3060,9 @@ fhandler_console::write (const void *vsrc, size_t len)
   if (bg <= bg_eof)
     return (ssize_t) bg;
 
+  if (get_ttyp ()->ti.c_lflag & FLUSHO)
+    return len; /* Discard write data */
+
   if (get_ttyp ()->output_stopped && is_nonblocking ())
     {
       set_errno (EAGAIN);
-- 
2.30.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] Cygwin: pty, console: Make FLUSHO and Ctrl-O work.
  2021-02-19  8:44 [PATCH 0/2] Cygwin: pty, console: Make FLUSHO and Ctrl-O work Takashi Yano
  2021-02-19  8:44 ` [PATCH 1/2] Cygwin: pty: " Takashi Yano
  2021-02-19  8:44 ` [PATCH 2/2] Cygwin: console: Add support for FLUSHO and Ctrl-O Takashi Yano
@ 2021-02-19 17:09 ` Corinna Vinschen
  2 siblings, 0 replies; 4+ messages in thread
From: Corinna Vinschen @ 2021-02-19 17:09 UTC (permalink / raw)
  To: cygwin-patches

On Feb 19 17:44, Takashi Yano via Cygwin-patches wrote:
> - With these patches, FLUSHO and Ctrl-O (VDISCARD) get working.
> 
> Takashi Yano (2):
>   Cygwin: pty: Make FLUSHO and Ctrl-O work.
>   Cygwin: console: Add support for FLUSHO and Ctrl-O.
> 
>  winsup/cygwin/fhandler.h          |  1 +
>  winsup/cygwin/fhandler_console.cc | 11 +++++++++++
>  winsup/cygwin/fhandler_tty.cc     | 17 +++++++++++------
>  winsup/cygwin/select.cc           |  5 +++++
>  winsup/cygwin/tty.cc              |  1 +
>  winsup/cygwin/tty.h               |  1 +
>  6 files changed, 30 insertions(+), 6 deletions(-)
> 
> -- 
> 2.30.0

Pushed.


Thanks,
Corinna

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-02-19 17:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-19  8:44 [PATCH 0/2] Cygwin: pty, console: Make FLUSHO and Ctrl-O work Takashi Yano
2021-02-19  8:44 ` [PATCH 1/2] Cygwin: pty: " Takashi Yano
2021-02-19  8:44 ` [PATCH 2/2] Cygwin: console: Add support for FLUSHO and Ctrl-O Takashi Yano
2021-02-19 17:09 ` [PATCH 0/2] Cygwin: pty, console: Make FLUSHO and Ctrl-O work Corinna Vinschen

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 read-only IMAP folder(s) and NNTP newsgroup(s).