[patch] Input-waiting problem on solaris

72 views
Skip to first unread message

Ozaki Kiichi

unread,
Jun 27, 2016, 10:05:33 AM6/27/16
to vim_dev
Hi.

Solaris (and maybe other SunOS distributions) have odd select() syscall behavior on tty,
and it affects input-waiting of vim.

[example]

------
while 1
let c = getchar(0)
if c != 0
break
endif
sleep 20m
if another_condition()
break
endif
endwhile
------

This script waits user input or establishment of another condition, otherwise does sleeping.
Actially it checks input by select() syscall in 2 places; in getchar(0) and end of sleep.

* in getchar(0), select() is called with tty non-canonical mode (TMODE_RAW)
* in sleep, select() is called with tty canonical mode (TMODE_SLEEP)

That is;

------
select() [non-canon] ... (a)
(20ms) ... (b)
select() [canon] ... (c)
(back to top-of-loop)
select() [non-canon] ... (a')
...
------

On linux and mac (maybe *bsd):

input during (a): detected by select(a) and breaks a loop instantly
input during (b)~(c): not detected by select(c), and detected by select(a') and breaks a loop

That is, input during canon-mode is detected at non-canon-mode.

On solaris:

input during (a): detected by select(a) and breaks a loop instantly
input during (b)~(c): not detected by either select(c) or select(a') (unless input <CR>)

That is, input during canon-mode is *NOT* detected at non-canon-mode,
so breaking-loop needs input during (a) or input <CR> to finish line-buffering (or, in this case, establish another_condition).

# input during (b)~(c) is retained, not diacarded.
# example:
# (b)~(c) <- input "123"
# (a') <- input "4"
# select(a') detects input and read() reads "1234" from tty.

[patch]

Drop ICANON flag (and set VMIN to 1 VTIME to 0) at TMODE_SLEEP

https://gist.github.com/ichizok/acae1b5431a639108dd8cf2768823dc2

# This patch is part of https://groups.google.com/forum/#!msg/vim_dev/8ciQGDB-0Og/NiaJYwQHKF8J


Thank you.
- Ozaki Kiichi

Bram Moolenaar

unread,
Jun 27, 2016, 4:56:41 PM6/27/16
to Ozaki Kiichi, vim_dev
Thanks for diving into this. This problem must have existed for a long
time, I wonder why nobody reported it before.

Since the patch is for Solaris (or perhaps SysV kind of Unix?), should
we add this inside an #ifdef? Or would it be OK to do the same on all
systems?

--
hundred-and-one symptoms of being an internet addict:
154. You fondle your mouse.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Ozaki Kiichi

unread,
Jun 28, 2016, 11:47:23 PM6/28/16
to vim_dev, gclien...@gmail.com
> Thanks for diving into this. This problem must have existed for a long
> time, I wonder why nobody reported it before.

I think because the number of vim users (using a lot plugins) on solaris is far less than on linux, mac, win, so maybe this behavior has received less attention.



> Since the patch is for Solaris (or perhaps SysV kind of Unix?), should
> we add this inside an #ifdef? Or would it be OK to do the same on all
> systems?

It is, as far as I found out, on only solaris problem.
But I think there is no need to keep ICANON on TMODE_SLEEP and we can apply changes to all systems.

Reply all
Reply to author
Forward
0 new messages