[comp.unix.programmer] Losing pending input in entering RAW or CBREAK

dfenyes@thesis1.med.uth.tmc.edu (David Fenyes) (05/03/91)

Hello,

I have an application that enters CBREAK mode (to do editing).
When I switch from cooked to CBREAK, any pending input appears
to be discarded.  How can this be avoided or worked around?

The exception is if a <CR> is hit before entering CBREAK--then the
whole line is properly read in CREAK mode.

I'm using Coherent.  Is this an anomaly, or standard tty behavior?
Is there any way to retrieve those chars not sent by <CR> in cooked
mode?

Thanks in advance,

David Fenyes                                 dfenyes@thesis1.med.uth.tmc.edu
University of Texas Medical School           Houston, Texas

mike@bria.UUCP (mike.stefanik) (05/04/91)

In an article, dfenyes@thesis1.med.uth.tmc.edu (David Fenyes) writes:
|Hello,
|
|I have an application that enters CBREAK mode (to do editing).
|When I switch from cooked to CBREAK, any pending input appears
|to be discarded.  How can this be avoided or worked around?
|
|I'm using Coherent.  Is this an anomaly, or standard tty behavior?

Well, having never progammed under Coherent (and, with God's grace, I
won't at any time in the near future :-) I will make the assumption
that Coherent uses termio ... with that out of the way ...

Are you using curses, or have you written your own?  The reason that
I ask is that if you are using curses, then you are probably SOL.
An excerpt from The Holiest of Tomes:

	TCSETA		set the parameters associated with the terminal
			from the structure passed as `arg'.  The change
			is immediate

	TCSETAW		wait for the output to drain before setting the
			new parameters

	TCSETAF		wait for the output to drain and flush the input
			queue before setting the new parameters

It would seem that the ioctl() that is setting the terminal characteristics
is using TCSETAF which is forcing the flush on the input queue.  If
your cbreak is homegrown, then try using TCSETA instead.

-- 
Michael Stefanik, MGI Inc, Los Angeles | Opinions stated are never realistic
Title of the week: Systems Engineer    | UUCP: ...!uunet!bria!mike
-------------------------------------------------------------------------------
If MS-DOS didn't exist, who would UNIX programmers have to make fun of?

scs@adam.mit.edu (Steve Summit) (05/07/91)

In article <243@bria.UUCP> uunet!bria!mike writes:
>In an article, dfenyes@thesis1.med.uth.tmc.edu (David Fenyes) writes:
>|When I switch from cooked to CBREAK, any pending input appears
>|to be discarded.  How can this be avoided or worked around?
>|
>|I'm using Coherent.  Is this an anomaly, or standard tty behavior?
>
>An excerpt from The Holiest of Tomes:
>
>	TCSETA		set the parameters associated with the terminal
>			from the structure passed as `arg'.  The change
>			is immediate
>
>	TCSETAF		wait for the output to drain and flush the input
>			queue before setting the new parameters
>
>It would seem that the ioctl() that is setting the terminal characteristics
>is using TCSETAF which is forcing the flush on the input queue.  If
>your cbreak is homegrown, then try using TCSETA instead.

I'm not familiar with Coherent, either, and Michael is probably
correct in assuming that it is termio and/or termios based, but
in case it derives from V7 and/or BSD, the equivalent ioctl's are

	TIOCSETP	set tty parameters (and flush pending input)
	TIOCSETN	set tty parameters (no flush of pending input)

                                            Steve Summit
                                            scs@adam.mit.edu