public inbox for cygwin-developers@cygwin.com
 help / color / mirror / Atom feed
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin-developers@cygwin.com
Subject: Re: Unexpected behavior using arrow keys on the terminal
Date: Wed, 12 Nov 2014 15:46:00 -0000	[thread overview]
Message-ID: <20141112154654.GA2782@calimero.vinschen.de> (raw)
In-Reply-To: <476974939.62973.1415788538204.JavaMail.yahoo@jws106102.mail.bf1.yahoo.com>

[-- Attachment #1: Type: text/plain, Size: 2695 bytes --]

Hi George,

On Nov 12 10:35, George Prekas wrote:
> Using Cygwin 1.7.32, mintty 1.1.3 and OpenSSH_6.7p1 I am getting
> unexpected behavior regarding the use of arrow keys on the terminal.
> You can reproduce the behavior by doing the following:
> 
> ssh linux
> cd /usr/src/linux/tools/perf
> make
> cd ~
> /usr/src/linux/tools/perf/perf record echo 42
> /usr/src/linux/tools/perf/perf report
> 
> Pressing UP or DOWN should highlight one of the rows displayed. You
> can verify expected behavior by using either PuTTY or native Linux.
> 
> Observation #1: You can fix perf's behavior by applying perf.patch
> (attached).
> 
> Observation #2: Using Wireshark, I've observed that when I ssh to a
> host and press UP or DOWN on my terminal 3 packets are transmitted
> from the client. PuTTY on the other hand transmits only 1 packet
> (larger in size).
> 
> Observation #3: I wrote the program test.c (attached). If I run it and
> press UP or DOWN:
> * on Windows from cmd.exe it says "Read 3 bytes. First is 27."
> * on Linux it says "Read 3 bytes. First is 27."
> * on Linux via PuTTY it says "Read 3 bytes. First is 27."
> * on Windows from mintty.exe it says "Read 1 bytes. First is 27. Read
>   1 bytes. First is 91. Read 1 bytes. First is 65."
> 
> My understanding is that the unexpected behavior occurs because Cygwin
> sends the UP/DOWN sequence one byte at a time. Specifically:
> 
> * winsup\cygwin\fhandler_tty.cc @ fhandler_pty_master::write
>     This is the function called by the write system call invoked by
>     mintty. Here len = 3. line_edit is invoked 3 times.
> * winsup\cygwin\fhandler_termios.cc @ fhandler_termios::line_edit
>     This is called by the previous and it calls accept_input.
> * winsup\cygwin\fhandler_tty.cc @ fhandler_pty_master::accept_input
>     This does the actual WriteFile to the pipe.
> 
> I would have provided a patch to fix the problem, but I am not sure I
> completely understand the semantics of the above mentioned methods.

I have to admit that I'm not quite sure either.  In theory I'd say that
the perf tool is making some invalid assumption here.  You can't rely on
a set of bytes sent from any input source to be always sent or received
as a single package, unless you're working with a transport guaranteing
this.

Your analyzes of the underlying mechanism in Cygwin is correct, though.
Despite what I said above, I take a look into this and perhaps I can fix
the code to send more than 1 byte at a time.  


Thanks,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

  reply	other threads:[~2014-11-12 15:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-12 10:35 George Prekas
2014-11-12 15:46 ` Corinna Vinschen [this message]
2014-11-13 20:10   ` Corinna Vinschen
2014-11-18 17:44     ` George Prekas
2014-11-18 20:07       ` Corinna Vinschen

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=20141112154654.GA2782@calimero.vinschen.de \
    --to=corinna-cygwin@cygwin.com \
    --cc=cygwin-developers@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).