[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Return value of write() is not properly evaluated
From: |
Thomas Dickey |
Subject: |
Re: Return value of write() is not properly evaluated |
Date: |
Tue, 30 Dec 2014 20:44:18 -0500 |
User-agent: |
Mutt/1.5.20 (2009-06-14) |
On Tue, Dec 30, 2014 at 03:26:57PM +0100, Stian Skjelstad wrote:
> Hello
>
> I am the maintainer of Open Cubic Player, and the last couple of days I
> have done a couple of tests, using ncurses on lubuntu.
>
> I stumbled across some graphical issues, and it appeared visible in several
> different terminal emulators when running on higher resolutions. After some
> experimentation I discovered that the problem was not visible if streaming
> stdout via tools like tee: eg
> ocp-curses | tee <- no UI noise
> ocp-curses <- UI noise every now and then
>
> Later I did some more testing with strace, and I discovered one point that
> I think is the key issue
>
> write(1, "\33[H\33[30m\37m\3..........", 8025) = 4096
> --- SIGALRM {si_signo=SIGALRM, si_code=SI_KERNEL} ---
> ioctl(4, SNDRV_PCM_IOCTL_HWSYNC, 0x1) = 0
> ioctl(4, SNDRV_PCM_IOCTL_HWSYNC, 0x3) = 0
> ioctl(4, SNDRV_PCM_IOCTL_HWSYNC, 0x20) = 0
> ioctl(4, SNDRV_PCM_IOCTL_HWSYNC, 0x20) = 0
> getitimer(ITIMER_REAL, {it_interval={0, 14320}, it_value={0, 9190}}) = 0
> rt_sigreturn() = 4096
> rt_sigaction(SIGTSTP, {0x7f2f4f97a0b0, [], SA_RESTORER|SA_RESTART,
> 0x7f2f50e17da0}, NULL, 8) = 0
> select(1, [0], NULL, NULL, {0, 0}) = 0 (Timeout)
>
>
> The usage of setitimer() can cause write() to return before a complete
> write has occurred. If piped via software like tee, the receiver will
> swallow bigger chunks of the buffer, making it more likely that a full
> buffer is sent before write() returns.
That sounds like
The curses library does ``line-breakout optimization'' by looking for
typeahead periodically while updating the screen. If input is found,
and it is coming from a tty, the current update is postponed until re‐
fresh or doupdate is called again. This allows faster response to com‐
mands typed in advance. Normally, the input FILE pointer passed to
newterm, or stdin in the case that initscr was used, will be used to do
this typeahead checking. The typeahead routine specifies that the file
descriptor fd is to be used to check for typeahead instead. If fd is
-1, then no typeahead checking is done.
... though an additional complication since 5.9 is that ncurses would behave
different if your program mixes direct writes to stdout (outside ncurses).
A quick read of the source code doesn't show me any of that, but it's something
to keep in mind.
--
Thomas E. Dickey <address@hidden>
http://invisible-island.net
ftp://invisible-island.net
signature.asc
Description: Digital signature