DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Terminal device control

Non-canonical mode input processing

In non-canonical input processing, input bytes are not assembled into lines, and erase and kill processing does not occur. The values of the MIN and TIME members of the c_cc array determine how to process any data received.

MIN is the minimum number of bytes of data that a read should return when it completes successfully. If MIN exceeds MAX_INPUT, the response to the request is implementation-defined. In UNIX System V, the maximum value that can be stored for MIN in c_cc[VMIN] is 256, less than MAX_INPUT which equals 512; thus, the MIN value can never exceed MAX_INPUT. TIME is a read-timer with a 0.10 second granularity used to time-out bursty and short-term data transmissions. The four possible interactions between MIN and TIME follow:

  1. (MIN>0, TIME>0).

    Because TIME>0, it serves as an inter-byte timer activated on receipt of the first byte of data, and reset on receipt of each byte of data. MIN and TIME interact as follows:

    When TIME expires, a read transfers at least one byte of data because the inter-byte timer is enabled if and only if a byte of data was received. A program using this case must wait for at least one byte of data to be read before proceeding. In case (MIN>0, TIME>0), a read blocks until receiving a byte of data activates MIN and TIME, or a signal interrupts the read. Thus, the read transfers at least one byte of data.

  2. (MIN>0, TIME=0).

    Because TIME=0, the timer plays no role and only MIN is significant. A read completes successfully only on receiving MIN bytes of data (i.e., the pending read blocks until MIN bytes of data are received) or a signal interrupts the read. Use these values only when the program cannot continue until a predetermined number of bytes of data are read. A program using this case to do record-based terminal I/O may block indefinitely in a read.

  3. (MIN=0, TIME>0).

    Because MIN=0, TIME no longer serves as an inter-byte timer, but now serves as a read-timer activated when a read is processed (in canon). A read completes successfully as soon as any bytes of data are received or the read-timer expires. A read does not transfer any bytes of data if the read-timer expires. If the read-timer does not expire, a read completes successfully if and only if some bytes of data are received. In case (MIN=0, TIME>0), the read does not block indefinitely waiting for a byte of data. If no bytes of data are received within TIME*0.10 seconds after the read starts, it returns 0 having read no data. If the buffer holds data when a read starts, the read-timer starts as if it received data immediately. MIN and TIME are useful when a program can assume that data is not available after a TIME interval and other processing can be done before data is available.

  4. (MIN=0, TIME=0).

    Without waiting for more bytes of data to be received, a read returns the minimum of either the number of bytes of data requested or the number of bytes of data currently available. In this case, a read immediately transfers any bytes of data present, or if no bytes of data are available, it returns 0 having read no data. In case (MIN=0, TIME=0), read operates identically to the O_NDELAY flag in canonical mode.

MIN/TIME interactions serve different purposes and thus do not parallel one another. In case [2]: (MIN>0, TIME=0), TIME lacks effect, but with the conditions reversed in case [3]: (MIN=0, TIME>0), both MIN and TIME play a role in that receiving a single byte satisfies the MIN criteria. Furthermore, in case [3]: (MIN=0, TIME>0), TIME represents a read-timer, while in case [1]: (MIN>0, TIME>0), TIME represents an inter-byte timer,

Cases [1] and [2], where MIN>0, handle burst mode activity (e.g., file-transfers), where programs need to process at least MIN bytes of data at a time. In case [1], the inter-byte timer acts as a safety measure; in case [2], the timer is turned off.

Cases [3] and [4] handle single byte, timed transfers like those used by screen-based programs that need to know if a byte of data is present in the input-queue before refreshing the screen. In case [3], the read is timed, while in case [4], it is not.

One should also note that MIN is always just a minimum, and does not define a record length. Thus, if a program tries a read of 20 bytes when 25 bytes of data are present and MIN is 10, the read returns 20 bytes of data. In the special case of MIN=0, this still applies: if more than one byte of data is available, all data is returned immediately.


Next topic: Writing data and output processing
Previous topic: Canonical mode input processing

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004