public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin-patches@cygwin.com
Subject: [PATCH] Cygwin: pty: Add several further comments to the pty code.
Date: Sat,  5 Mar 2022 08:42:22 +0900	[thread overview]
Message-ID: <20220304234222.2319-1-takashi.yano@nifty.ne.jp> (raw)

---
 winsup/cygwin/fhandler_tty.cc | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 0c762d75e..c2e612580 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -76,6 +76,13 @@ void release_attach_mutex (void)
 
 inline static bool process_alive (DWORD pid);
 
+/* This functions looks for a process which attached to the same console
+   with current process and is matched to given conditions:
+     match: If true, return given pid if the process pid attaches to the
+	    same console, otherwise, return 0. If false, return pid except
+	    for given pid.
+     cygwin: return only process's pid which has cygwin pid.
+     stub_only: return only stub process's pid of non-cygwin process. */
 DWORD
 fhandler_pty_common::get_console_process_id (DWORD pid, bool match,
 					     bool cygwin, bool stub_only)
@@ -158,6 +165,7 @@ set_switch_to_nat_pipe (HANDLE *in, HANDLE *out, HANDLE *err)
     *err = replace_err->get_output_handle_nat ();
 }
 
+/* Determine if the given path is cygwin binary. */
 static bool
 path_iscygexec_a_w (LPCSTR na, LPSTR ca, LPCWSTR nw, LPWSTR cw)
 {
@@ -3860,6 +3868,7 @@ fhandler_pty_slave::transfer_input (tty::xfer_dir dir, HANDLE from, tty *ttyp,
 
   if (dir == tty::to_cyg && ttyp->pcon_activated)
     { /* from handle is console handle */
+      /* Reaches here for nat->cyg case with pcon activated. */
       INPUT_RECORD r[INREC_SIZE];
       DWORD n;
       while (PeekConsoleInputA (from, r, INREC_SIZE, &n) && n)
@@ -3931,7 +3940,8 @@ fhandler_pty_slave::transfer_input (tty::xfer_dir dir, HANDLE from, tty *ttyp,
 	}
     }
   else
-    {
+    { /* Reaches here when both cyg->nat and nat->cyg cases with
+	 pcon not activated or cyg->nat case with pcon activated. */
       DWORD bytes_in_pipe;
       while (::bytes_available (bytes_in_pipe, from) && bytes_in_pipe)
 	{
@@ -3964,9 +3974,11 @@ fhandler_pty_slave::transfer_input (tty::xfer_dir dir, HANDLE from, tty *ttyp,
 	}
     }
 
-  if (dir == tty::to_nat)
+  /* Fix input_available_event which indicates availability in cyg pipe. */
+  if (dir == tty::to_nat) /* all data is transfered to nat pipe,
+			     so no data available in cyg pipe. */
     ResetEvent (input_available_event);
-  else if (transfered)
+  else if (transfered) /* There is data transfered to cyg pipe. */
     SetEvent (input_available_event);
   ttyp->pty_input_state = dir;
   ttyp->discard_input = false;
-- 
2.35.1


                 reply	other threads:[~2022-03-04 23:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220304234222.2319-1-takashi.yano@nifty.ne.jp \
    --to=takashi.yano@nifty.ne.jp \
    --cc=cygwin-patches@cygwin.com \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).